Commit efdf1d86 by Евгений

Улучшение #19461

Страница настройки целевых аккаунтов.
1 parent 1712c1bf
...@@ -6,5 +6,6 @@ use Faker\Generator as Faker; ...@@ -6,5 +6,6 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Campaigns::class, function (Faker $faker) { $factory->define(App\Models\Campaigns::class, function (Faker $faker) {
return [ return [
'name' => $faker->name, 'name' => $faker->name,
'external_id' => $faker->randomNumber()
]; ];
}); });
...@@ -6,5 +6,6 @@ use Faker\Generator as Faker; ...@@ -6,5 +6,6 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Dictionary::class, function (Faker $faker) { $factory->define(App\Models\Dictionary::class, function (Faker $faker) {
return [ return [
'name' => $faker->name, 'name' => $faker->name,
'region_id' => $faker->unique()->randomNumber()
]; ];
}); });
<?php
namespace Tests\Feature;
use App\Models\Account;
use App\Models\Campaigns;
use App\Models\Dictionary;
use App\Models\Tokens;
use App\Models\User;
use App\Models\Organization;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CityTest extends TestCase
{
use RefreshDatabase;
private $token;
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 = factory(Tokens::class)->create([
'created_by' => $this->user->getKey()
]);
$this->token_main = factory(Tokens::class)->create([
'type' => Tokens::MAIN,
]);
factory(Campaigns::class, 2)->create([
'manage' => true,
'token' => $this->token_main->getKey(),
]);
factory(Campaigns::class, 2)->create([
'manage' => false,
'token' => $this->token_main->getKey(),
]);
factory(Dictionary::class, 10)->create([
'type' => Dictionary::CITY,
]);
}
public function test_add_city(){
$ids = Dictionary::all()->pluck('id');
$this->actingAs($this->user)
->post(route('token.city.store', [
'token' => $this->token->id,
'city' => $ids[0]
]))
->assertStatus(302);
$this->token->load('cities.campaigns');
$this->assertEquals($this->token->cities->count(), 1);
foreach ($this->token->cities as $city){
$this->assertEquals($city->campaigns->count(), 2);
}
$this->actingAs($this->user)
->post(route('token.city.store', [
'token' => $this->token->id,
'city' => $ids[1]
]))
->assertStatus(302);
$this->token->load('cities.campaigns');
$this->assertEquals($this->token->cities->count(), 2);
foreach ($this->token->cities as $city){
$this->assertEquals($city->campaigns->count(), 2);
}
$this->actingAs($this->user)
->post(route('token.city.store', [
'token' => $this->token->id,
'city' => $ids[2]
]))
->assertStatus(302);
$this->token->load('cities.campaigns');
$this->assertEquals($this->token->cities->count(), 3);
foreach ($this->token->cities as $city){
$this->assertEquals($city->campaigns->count(), 2);
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!