app/Jobs/ImportProfession.php: make $character variable optional and require $user.
This commit is contained in:
parent
f82f7c3571
commit
8eda7a315c
6 changed files with 174 additions and 34 deletions
|
|
@ -11,7 +11,6 @@ use App\Models\Recipe;
|
|||
use App\Models\Spell;
|
||||
use App\Jobs\ImportProfession;
|
||||
|
||||
use App\ProfessionImport\InvalidCharacterException;
|
||||
use App\ProfessionImport\InvalidProfessionException;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
|
@ -96,7 +95,7 @@ class BasicTest extends TestCase
|
|||
Profession::factory()->create([ 'name' => 'Alchemy' ]);
|
||||
$character = Character::factory()->create([ 'name' => 'Superduper']);
|
||||
|
||||
ImportProfession::dispatch($character, $data);
|
||||
ImportProfession::dispatch($data, $character->user, $character);
|
||||
|
||||
$this->assertEquals('Alchemy', $character->professions[0]->name);
|
||||
$recipes = $character->professions[0]->recipes;
|
||||
|
|
@ -140,28 +139,6 @@ class BasicTest extends TestCase
|
|||
$this->assertEquals(2, $recipes[1]->reagents[2]->quantity);
|
||||
}
|
||||
|
||||
public function test_wrong_character_name()
|
||||
{
|
||||
Profession::factory()->create([ 'name' => 'Alchemy' ]);
|
||||
$character = Character::factory()->create([ 'name' => 'Actualname']);
|
||||
|
||||
$data = (object) [
|
||||
"server" => "Ashbringer",
|
||||
"player" => "Wrongname",
|
||||
"guild" => "Flat Azeroth Research Team",
|
||||
"profession" => (object) [
|
||||
"name" => "Alchemy",
|
||||
"level" => 375,
|
||||
"maxLevel" => 375,
|
||||
"recipes" => []
|
||||
]
|
||||
];
|
||||
|
||||
$this->expectException(InvalidCharacterException::class);
|
||||
|
||||
ImportProfession::dispatch($character, $data);
|
||||
}
|
||||
|
||||
public function test_invalid_profession()
|
||||
{
|
||||
Profession::factory()->create([ 'name' => 'Alchemy' ]);
|
||||
|
|
@ -183,6 +160,6 @@ class BasicTest extends TestCase
|
|||
|
||||
$this->expectException(InvalidProfessionException::class);
|
||||
|
||||
ImportProfession::dispatch($character, $data);
|
||||
ImportProfession::dispatch($data, $character->user, $character);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
152
tests/Feature/ProfessionImport/CharacterTest.php
Normal file
152
tests/Feature/ProfessionImport/CharacterTest.php
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\ProfessionImport;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Character;
|
||||
use App\Models\Profession;
|
||||
use App\Jobs\ImportProfession;
|
||||
|
||||
use App\ProfessionImport\InvalidCharacterException;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CharacterTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_character_found()
|
||||
{
|
||||
Profession::factory()->create([ 'name' => 'Alchemy' ]);
|
||||
$character = Character::factory()->create([ 'name' => 'Charfound']);
|
||||
|
||||
$data = (object) [
|
||||
"server" => "Darkshore",
|
||||
"player" => "Charfound",
|
||||
"guild" => "ABOBA",
|
||||
"profession" => (object) [
|
||||
"name" => "Alchemy",
|
||||
"level" => 375,
|
||||
"maxLevel" => 375,
|
||||
"recipes" => [
|
||||
(object) [
|
||||
"name" => "Elixir of Major Defense",
|
||||
"color" => "ffffff",
|
||||
"id" => 22834,
|
||||
"num" => 1,
|
||||
"categorie" => "Elixir",
|
||||
"items" => [
|
||||
(object) [
|
||||
"name" => "Ancient Lichen",
|
||||
"color" => "ffffff",
|
||||
"num" => 3,
|
||||
"id" => 22790
|
||||
],
|
||||
(object) [
|
||||
"name" => "Terocone",
|
||||
"color" => "ffffff",
|
||||
"num" => 1,
|
||||
"id" => 22789
|
||||
],
|
||||
(object) [
|
||||
"name" => "Imbued Vial",
|
||||
"color" => "ffffff",
|
||||
"num" => 1,
|
||||
"id" => 18256
|
||||
],
|
||||
],
|
||||
"spellId" => 28557
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
ImportProfession::dispatch($data, $character->user);
|
||||
|
||||
$this->assertEquals('Alchemy', $character->professions[0]->name);
|
||||
$recipes = $character->professions[0]->recipes;
|
||||
|
||||
$this->assertEquals(22834, $recipes[0]->craft->external_id);
|
||||
$this->assertEquals('Elixir of Major Defense', $recipes[0]->craft->name);
|
||||
|
||||
$this->assertEquals(28557, $recipes[0]->spell->id);
|
||||
$this->assertEquals('Elixir of Major Defense', $recipes[0]->spell->name);
|
||||
|
||||
$this->assertEquals(22790, $recipes[0]->reagents[0]->external_id);
|
||||
$this->assertEquals('Ancient Lichen', $recipes[0]->reagents[0]->name);
|
||||
$this->assertEquals(3, $recipes[0]->reagents[0]->quantity);
|
||||
|
||||
$this->assertEquals(18256, $recipes[0]->reagents[1]->external_id);
|
||||
$this->assertEquals('Imbued Vial', $recipes[0]->reagents[1]->name);
|
||||
$this->assertEquals(1, $recipes[0]->reagents[1]->quantity);
|
||||
|
||||
$this->assertEquals(22789, $recipes[0]->reagents[2]->external_id);
|
||||
$this->assertEquals('Terocone', $recipes[0]->reagents[2]->name);
|
||||
$this->assertEquals(1, $recipes[0]->reagents[2]->quantity);
|
||||
}
|
||||
|
||||
public function test_character_not_found()
|
||||
{
|
||||
$character = Character::factory()->create([ 'name' => 'Findme']);
|
||||
|
||||
$data = (object) [
|
||||
"server" => "Ashbringer",
|
||||
"player" => "Anotherdude",
|
||||
"guild" => "Flat Azeroth Research Team",
|
||||
"profession" => (object) [
|
||||
"name" => "Alchemy",
|
||||
"level" => 375,
|
||||
"maxLevel" => 375,
|
||||
"recipes" => []
|
||||
]
|
||||
];
|
||||
|
||||
$this->expectException(InvalidCharacterException::class);
|
||||
|
||||
ImportProfession::dispatch($data, $character->user);
|
||||
}
|
||||
|
||||
public function test_other_users_characters_is_not_found()
|
||||
{
|
||||
$character = Character::factory()->create([ 'name' => 'Otherchar']);
|
||||
|
||||
$data = (object) [
|
||||
"server" => "Rattlegore",
|
||||
"player" => "Otherchar",
|
||||
"guild" => "The A-Team",
|
||||
"profession" => (object) [
|
||||
"name" => "Alchemy",
|
||||
"level" => 375,
|
||||
"maxLevel" => 375,
|
||||
"recipes" => []
|
||||
]
|
||||
];
|
||||
|
||||
$this->expectException(InvalidCharacterException::class);
|
||||
|
||||
ImportProfession::dispatch($data, User::factory()->create());
|
||||
}
|
||||
|
||||
public function test_character_is_not_the_same_as_imported_name()
|
||||
{
|
||||
$character = Character::factory()->create([ 'name' => 'Actualname']);
|
||||
|
||||
$data = (object) [
|
||||
"server" => "Benediction",
|
||||
"player" => "Wrongname",
|
||||
"guild" => "Spaceballs",
|
||||
"profession" => (object) [
|
||||
"name" => "Alchemy",
|
||||
"level" => 375,
|
||||
"maxLevel" => 375,
|
||||
"recipes" => []
|
||||
]
|
||||
];
|
||||
|
||||
$this->expectException(InvalidCharacterException::class);
|
||||
|
||||
ImportProfession::dispatch($data, $character->user, $character);
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ class RecipesTest extends TestCase
|
|||
Profession::factory()->create([ 'name' => 'Enchanting' ]);
|
||||
$character = Character::factory()->create([ 'name' => 'Scumbag']);
|
||||
|
||||
ImportProfession::dispatch($character, $data);
|
||||
ImportProfession::dispatch($data, $character->user, $character);
|
||||
|
||||
$this->assertEquals('Enchanting', $character->professions[0]->name);
|
||||
$recipes = $character->professions[0]->recipes;
|
||||
|
|
@ -123,7 +123,7 @@ class RecipesTest extends TestCase
|
|||
]
|
||||
];
|
||||
|
||||
ImportProfession::dispatch($character, $data);
|
||||
ImportProfession::dispatch($data, $character->user, $character);
|
||||
|
||||
$this->assertEquals(1, Recipe::count());
|
||||
$this->assertDatabaseHas('recipes', [
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class SpecializationTest extends TestCase
|
|||
]
|
||||
];
|
||||
|
||||
ImportProfession::dispatch($character, $data);
|
||||
ImportProfession::dispatch($data, $character->user, $character);
|
||||
|
||||
$this->assertNotNull($character->professions[0]->specialization, "specalization was not imported");
|
||||
$this->assertEquals(28672, $character->professions[0]->specialization->id);
|
||||
|
|
@ -55,7 +55,7 @@ class SpecializationTest extends TestCase
|
|||
]
|
||||
];
|
||||
|
||||
ImportProfession::dispatch($character, $data);
|
||||
ImportProfession::dispatch($data, $character->user, $character);
|
||||
|
||||
$this->assertNull($character->professions[0]->specialization);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue