Commit 7fda6448 by Vladislav
2 parents 7770be8b 1650ac0f
...@@ -14,21 +14,21 @@ use Illuminate\Console\Command; ...@@ -14,21 +14,21 @@ use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Bus;
class CampaignsLoadUpdatedChildrenAdGroups extends Command class CampaignsCheckUpdatedChildrenAdGroups extends Command
{ {
/** /**
* The name and signature of the console command. * The name and signature of the console command.
* *
* @var string * @var string
*/ */
protected $signature = 'campaigns:loadUpdatedChildrenAdGroups'; protected $signature = 'campaigns:checkUpdatedChildrenAdGroups';
/** /**
* The console command description. * The console command description.
* *
* @var string * @var string
*/ */
protected $description = 'Загрузка измененных РК'; protected $description = 'Проверка наличия изменения в дочерних элементах';
/** /**
* Create a new command instance. * Create a new command instance.
......
...@@ -7,8 +7,8 @@ use App\Console\Commands\AdGroupsLoadUpdated; ...@@ -7,8 +7,8 @@ use App\Console\Commands\AdGroupsLoadUpdated;
use App\Console\Commands\AdGroupsUpdate; use App\Console\Commands\AdGroupsUpdate;
use App\Console\Commands\CampaignsAdd; use App\Console\Commands\CampaignsAdd;
use App\Console\Commands\CampaignsCheckChange; use App\Console\Commands\CampaignsCheckChange;
use App\Console\Commands\CampaignsCheckUpdatedChildrenAdGroups;
use App\Console\Commands\CampaignsLoadGroups; use App\Console\Commands\CampaignsLoadGroups;
use App\Console\Commands\CampaignsLoadUpdatedChildrenAdGroups;
use App\Console\Commands\CampaignsResume; use App\Console\Commands\CampaignsResume;
use App\Console\Commands\CampaignsSuspend; use App\Console\Commands\CampaignsSuspend;
use App\Console\Commands\CampaignsUpdate; use App\Console\Commands\CampaignsUpdate;
...@@ -40,12 +40,14 @@ class Kernel extends ConsoleKernel ...@@ -40,12 +40,14 @@ class Kernel extends ConsoleKernel
$schedule->command(RefreshLimits::class)->hourly(); $schedule->command(RefreshLimits::class)->hourly();
$schedule->command(DictionariesLoad::class)->saturdays()->at('05:00'); $schedule->command(DictionariesLoad::class)->saturdays()->at('05:00');
$schedule->command(CampaignsCheckChange::class)->hourlyAt(5); $schedule->command(CampaignsCheckChange::class)->hourlyAt(5);
$schedule->command(CampaignsLoadUpdated::class)->hourlyAt(15); $schedule->command(CampaignsCheckUpdatedChildrenAdGroups::class)->hourlyAt(10);
$schedule->command(CampaignsLoadUpdated::class)->hourlyAt(10);
$schedule->command(CampaignsAdd::class)->hourlyAt(20); $schedule->command(CampaignsAdd::class)->hourlyAt(20);
$schedule->command(CampaignsUpdate::class)->hourlyAt(20); $schedule->command(CampaignsUpdate::class)->hourlyAt(20);
$schedule->command(CampaignsResume::class)->hourlyAt(20); $schedule->command(CampaignsResume::class)->hourlyAt(20);
$schedule->command(CampaignsSuspend::class)->hourlyAt(20); $schedule->command(CampaignsSuspend::class)->hourlyAt(20);
$schedule->command(CampaignsLoadUpdatedChildrenAdGroups::class)->hourlyAt(35);
$schedule->command(CampaignsLoadGroups::class)->hourlyAt(40); $schedule->command(CampaignsLoadGroups::class)->hourlyAt(40);
$schedule->command(AdGroupsLoadUpdated::class)->hourlyAt(45); $schedule->command(AdGroupsLoadUpdated::class)->hourlyAt(45);
$schedule->command(AdGroupsAdd::class)->hourlyAt(50); $schedule->command(AdGroupsAdd::class)->hourlyAt(50);
......
<?php
namespace Tests\Unit;
use App\Jobs\ProcessCallLimitedAPI;
use App\Models\Account;
use App\Models\Campaigns;
use App\Models\Dictionary;
use App\Models\Pivots\DictionaryCampaign;
use App\Models\Tokens;
use App\Models\User;
use App\Service\Contract\API;
use App\Service\Requests\APIRequest;
use Carbon\Carbon;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class UpdateCampaignsTest extends TestCase
{
use RefreshDatabase;
private $request;
private $user;
private $token_main;
protected function setUp(): void
{
parent::setUp();
$account = Account::create(['name' => 'Acme Corporation']);
$this->user = factory(User::class)->create([
'account_id' => $account->id,
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com',
'owner' => true,
]);
$this->token_main = factory(Tokens::class)->create([
'type' => Tokens::MAIN,
'created_by' => $this->user->id,
]);
$this->token = factory(Tokens::class)->create([
'limit' => 20,
'created_by' => $this->user->getKey()
]);
$this->request = APIRequest::getInstance(API::YANDEX)
->setToken($this->token_main)
->getRequest('Campaigns', 'update');
$this->campaign = factory(Campaigns::class)->create([
'manage' => true,
'token' => $this->token_main->getKey(),
]);
$this->dictionaries = factory(Dictionary::class, 12)->create([
'token_id' => $this->token->getKey(),
'type' => Dictionary::CITY,
]);
$this->campaign->dictionaries()->syncWithoutDetaching(
$this->dictionaries->keyBy(Campaigns::getModel()->getKeyName())->transform(function (Dictionary $dictionary) {
return DictionaryCampaign::copyPropertyFromMain($this->campaign);
})->all()
);
}
function test_get_campaigns_for_update(){
$dictionaryCampaign = DictionaryCampaign::first();
$dictionaryCampaign['external_id'] = 1;
$data['external_updated_at'] = Carbon::now();
if ($dictionaryCampaign->updated) {
$data['updated_need'] = Carbon::now();
}
$dictionaryCampaign->update($data);
$tokens = Tokens::whereHas('dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated')
->with('dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated.campaign')
->where('type', '!=', Tokens::MAIN)
->get();
Queue::fake();
foreach ($tokens as $token) {
$this->assertEquals($dictionaryCampaign->toArray()['external_id'], $token->dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated->toArray()[0]['external_id']);
$this->request->call([
'dictionaryCampaigns' => $token->dictionaryCampaignsEnabledForExternalUpdatedNeedUpdated,
]);
Queue::assertPushed(ProcessCallLimitedAPI::class);
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!