From 88995dab3568634d78deaa1e7aa79bba354315c7 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 11 Jul 2021 16:27:45 +0200 Subject: [PATCH] test: refactor profession import tests into multiple classes. --- tests/Feature/ProfessionImport/BasicTest.php | 139 ++++++++ .../Feature/ProfessionImport/RecipesTest.php | 134 ++++++++ .../ProfessionImport/SpecializationTest.php | 62 ++++ tests/Feature/ProfessionImportTest.php | 299 ------------------ 4 files changed, 335 insertions(+), 299 deletions(-) create mode 100644 tests/Feature/ProfessionImport/BasicTest.php create mode 100644 tests/Feature/ProfessionImport/RecipesTest.php create mode 100644 tests/Feature/ProfessionImport/SpecializationTest.php delete mode 100644 tests/Feature/ProfessionImportTest.php diff --git a/tests/Feature/ProfessionImport/BasicTest.php b/tests/Feature/ProfessionImport/BasicTest.php new file mode 100644 index 0000000..8110ad0 --- /dev/null +++ b/tests/Feature/ProfessionImport/BasicTest.php @@ -0,0 +1,139 @@ +seed(\Database\Seeders\ProductionSeeders\ItemSeeder::class); + + // Profession Exporter v1.1.0 format + $data = (object) [ + "server" => "Ashbringer", + "player" => "Superduper", + "guild" => "Nej baba inte tofflan", + "profession" => (object) [ + "locale" => "enUS", + "name" => "Alchemy", + "specializationId" => 28672, + "specializationName" => "Transmutation Master", + "level" => 374, + "maxLevel" => 375, + "recipes" => [ + (object) [ + "name" => "Elixir of Major Defense", + "color" => "ffffff", + "id" => 22834, + "num" => 1, + "categorie" => "Elixir", + "items" => [ + (object) [ + "color" => "ffffff", + "num" => 3, + "id" => 22790 + ], + (object) [ + "color" => "ffffff", + "num" => 1, + "id" => 22789 + ], + (object) [ + "color" => "ffffff", + "num" => 1, + "id" => 18256 + ], + ], + "spellId" => 28557 + ], + (object) [ + "name" => "Elixir of Major Agility", + "color" => "ffffff", + "id" => 22831, + "num" => 1, + "categorie" => "Elixir", + "items" => [ + (object) [ + "color" => "ffffff", + "num" => 1, + "id" => 22789 + ], + (object) [ + "color" => "ffffff", + "num" => 2, + "id" => 22785 + ], + (object) [ + "color" => "ffffff", + "num" => 1, + "id" => 18256 + ] + ], + "spellId" => 28553 + ] + ] + ] + ]; + + Profession::factory()->create([ 'name' => 'Alchemy' ]); + $character = Character::factory()->create([ 'name' => 'Superduper']); + + ImportProfession::dispatch($character, $data); + + $this->assertEquals('Alchemy', $character->professions[0]->name); + $recipes = $character->professions[0]->recipes; + + // Recipe 1 + $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(18256, $recipes[0]->reagents[0]->external_id); + $this->assertEquals('Imbued Vial', $recipes[0]->reagents[0]->name); + $this->assertEquals(1, $recipes[0]->reagents[0]->quantity); + + $this->assertEquals(22789, $recipes[0]->reagents[1]->external_id); + $this->assertEquals('Terocone', $recipes[0]->reagents[1]->name); + $this->assertEquals(1, $recipes[0]->reagents[1]->quantity); + + $this->assertEquals(22790, $recipes[0]->reagents[2]->external_id); + $this->assertEquals('Ancient Lichen', $recipes[0]->reagents[2]->name); + $this->assertEquals(3, $recipes[0]->reagents[2]->quantity); + + // Recipe 2 + $this->assertEquals(22831, $recipes[1]->craft->external_id); + $this->assertEquals('Elixir of Major Agility', $recipes[1]->craft->name); + + $this->assertEquals(28553, $recipes[1]->spell->id); + $this->assertEquals('Elixir of Major Agility', $recipes[1]->spell->name); + + $this->assertEquals(18256, $recipes[1]->reagents[0]->external_id); + $this->assertEquals('Imbued Vial', $recipes[1]->reagents[0]->name); + $this->assertEquals(1, $recipes[1]->reagents[0]->quantity); + + $this->assertEquals(22789, $recipes[1]->reagents[1]->external_id); + $this->assertEquals('Terocone', $recipes[1]->reagents[1]->name); + $this->assertEquals(1, $recipes[1]->reagents[1]->quantity); + + $this->assertEquals(22785, $recipes[1]->reagents[2]->external_id); + $this->assertEquals('Felweed', $recipes[1]->reagents[2]->name); + $this->assertEquals(2, $recipes[1]->reagents[2]->quantity); + } +} diff --git a/tests/Feature/ProfessionImport/RecipesTest.php b/tests/Feature/ProfessionImport/RecipesTest.php new file mode 100644 index 0000000..f958cc0 --- /dev/null +++ b/tests/Feature/ProfessionImport/RecipesTest.php @@ -0,0 +1,134 @@ +seed(\Database\Seeders\ProductionSeeders\ItemSeeder::class); + + $data = (object) [ + "server" => "Ashbringer", + "player" => "Scumbag", + "guild" => "Method", + "profession" => (object) [ + "locale" => "enUS", + "name" => "Enchanting", + "specializationId" => null, + "specializationName" => null, + "level" => 303, + "maxLevel" => 375, + "recipes" => [ + (object) [ + "description" => "Permanently enchant boots to give +7 Agility.", + "name" => "Enchant Boots - Greater Agility", + "num" => 0, + "categorie" => "none", + "items" => [ + (object) [ + "color" => "1eff00", + "id" => 16203, + "num" => 8 + ] + ], + "spellId" => 20023 + ], + (object) [ + "description" => "Transforms a Nexus Crystal into a Small Prismatic Shard.", + "name" => "Nexus Transformation", + "num" => 1, + "categorie" => "none", + "items" => [ + (object) [ + "color" => "a335ee", + "id" => 20725, + "num" => 1 + ] + ], + "spellId" => 42613 + ] + ] + ] + ]; + + Profession::factory()->create([ 'name' => 'Enchanting' ]); + $character = Character::factory()->create([ 'name' => 'Scumbag']); + + ImportProfession::dispatch($character, $data); + + $this->assertEquals('Enchanting', $character->professions[0]->name); + $recipes = $character->professions[0]->recipes; + + // Recipe 1 + $this->assertNull($recipes[0]->craft); + + $this->assertEquals(20023, $recipes[0]->spell->id); + $this->assertEquals('Enchant Boots - Greater Agility', $recipes[0]->spell->name); + + $this->assertEquals(16203, $recipes[0]->reagents[0]->external_id); + $this->assertEquals('Greater Eternal Essence', $recipes[0]->reagents[0]->name); + $this->assertEquals(8, $recipes[0]->reagents[0]->quantity); + + // Recipe 2 + $this->assertNull($recipes[1]->craft); + + $this->assertEquals(42613, $recipes[1]->spell->id); + $this->assertEquals('Nexus Transformation', $recipes[1]->spell->name); + + $this->assertEquals(20725, $recipes[1]->reagents[0]->external_id); + $this->assertEquals('Nexus Crystal', $recipes[1]->reagents[0]->name); + $this->assertEquals(1, $recipes[1]->reagents[0]->quantity); + } + + public function test_import_does_not_create_duplicate_recipes_if_spell_relationship_is_missing() + { + $character = Character::factory()->create([ 'name' => 'Duplicated']); + $profession = Profession::factory()->create([ 'name' => 'My Unique Profession' ]); + $item = Item::factory()->create(['name' => 'Unique Recipe']); + + $recipe = Recipe::factory() + ->for($profession) + ->for($item, 'craft') + ->create(['spell_id' => null]); + + $data = (object) [ + "player" => $character->name, + "profession" => (object) [ + "name" => $profession->name, + "level" => 375, + "maxLevel" => 375, + "recipes" => [ + (object) [ + "name" => $item->name, + "num" => 0, + "categorie" => "none", + "items" => [], + "spellId" => 1337 + ] + ] + ] + ]; + + ImportProfession::dispatch($character, $data); + + $this->assertEquals(1, Recipe::count()); + $this->assertDatabaseHas('recipes', [ + 'spell_id' => 1337, + 'item_id' => $item->id, + ]); + } +} diff --git a/tests/Feature/ProfessionImport/SpecializationTest.php b/tests/Feature/ProfessionImport/SpecializationTest.php new file mode 100644 index 0000000..b0b2df8 --- /dev/null +++ b/tests/Feature/ProfessionImport/SpecializationTest.php @@ -0,0 +1,62 @@ +create([ 'name' => 'Specialdude']); + $profession = Profession::factory()->create([ 'name' => 'Alchemy' ]); + $specialization = Spell::factory()->create(['id' => 28672, 'name' => 'Transmutation Master']); + + $data = (object) [ + "player" => $character->name, + "profession" => (object) [ + "name" => $profession->name, + "specializationId" => 28672, + "specializationName" => "Transmutation Master", + "level" => 375, + "recipes" => [], + ] + ]; + + ImportProfession::dispatch($character, $data); + + $this->assertNotNull($character->professions[0]->specialization, "specalization was not imported"); + $this->assertEquals(28672, $character->professions[0]->specialization->id); + $this->assertEquals("Transmutation Master", $character->professions[0]->specialization->name); + + $this->assertEquals(1, Spell::count()); + } + + public function test_specialization_can_be_omitted() + { + $character = Character::factory()->create([ 'name' => 'frankthetank']); + $profession = Profession::factory()->create([ 'name' => 'Carpenter' ]); + + $data = (object) [ + "player" => $character->name, + "profession" => (object) [ + "name" => $profession->name, + "level" => 375, + "recipes" => [], + ] + ]; + + ImportProfession::dispatch($character, $data); + + $this->assertNull($character->professions[0]->specialization); + } +} diff --git a/tests/Feature/ProfessionImportTest.php b/tests/Feature/ProfessionImportTest.php deleted file mode 100644 index 02adad5..0000000 --- a/tests/Feature/ProfessionImportTest.php +++ /dev/null @@ -1,299 +0,0 @@ -seed(\Database\Seeders\ProductionSeeders\ItemSeeder::class); - - // Profession Exporter v1.1.0 format - $data = (object) [ - "server" => "Ashbringer", - "player" => "Superduper", - "guild" => "Nej baba inte tofflan", - "profession" => (object) [ - "locale" => "enUS", - "name" => "Alchemy", - "specializationId" => 28672, - "specializationName" => "Transmutation Master", - "level" => 374, - "maxLevel" => 375, - "recipes" => [ - (object) [ - "name" => "Elixir of Major Defense", - "color" => "ffffff", - "id" => 22834, - "num" => 1, - "categorie" => "Elixir", - "items" => [ - (object) [ - "color" => "ffffff", - "num" => 3, - "id" => 22790 - ], - (object) [ - "color" => "ffffff", - "num" => 1, - "id" => 22789 - ], - (object) [ - "color" => "ffffff", - "num" => 1, - "id" => 18256 - ], - ], - "spellId" => 28557 - ], - (object) [ - "name" => "Elixir of Major Agility", - "color" => "ffffff", - "id" => 22831, - "num" => 1, - "categorie" => "Elixir", - "items" => [ - (object) [ - "color" => "ffffff", - "num" => 1, - "id" => 22789 - ], - (object) [ - "color" => "ffffff", - "num" => 2, - "id" => 22785 - ], - (object) [ - "color" => "ffffff", - "num" => 1, - "id" => 18256 - ] - ], - "spellId" => 28553 - ] - ] - ] - ]; - - Profession::factory()->create([ 'name' => 'Alchemy' ]); - $character = Character::factory()->create([ 'name' => 'Superduper']); - - ImportProfession::dispatch($character, $data); - - $this->assertEquals('Alchemy', $character->professions[0]->name); - $recipes = $character->professions[0]->recipes; - - // Recipe 1 - $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(18256, $recipes[0]->reagents[0]->external_id); - $this->assertEquals('Imbued Vial', $recipes[0]->reagents[0]->name); - $this->assertEquals(1, $recipes[0]->reagents[0]->quantity); - - $this->assertEquals(22789, $recipes[0]->reagents[1]->external_id); - $this->assertEquals('Terocone', $recipes[0]->reagents[1]->name); - $this->assertEquals(1, $recipes[0]->reagents[1]->quantity); - - $this->assertEquals(22790, $recipes[0]->reagents[2]->external_id); - $this->assertEquals('Ancient Lichen', $recipes[0]->reagents[2]->name); - $this->assertEquals(3, $recipes[0]->reagents[2]->quantity); - - // Recipe 2 - $this->assertEquals(22831, $recipes[1]->craft->external_id); - $this->assertEquals('Elixir of Major Agility', $recipes[1]->craft->name); - - $this->assertEquals(28553, $recipes[1]->spell->id); - $this->assertEquals('Elixir of Major Agility', $recipes[1]->spell->name); - - $this->assertEquals(18256, $recipes[1]->reagents[0]->external_id); - $this->assertEquals('Imbued Vial', $recipes[1]->reagents[0]->name); - $this->assertEquals(1, $recipes[1]->reagents[0]->quantity); - - $this->assertEquals(22789, $recipes[1]->reagents[1]->external_id); - $this->assertEquals('Terocone', $recipes[1]->reagents[1]->name); - $this->assertEquals(1, $recipes[1]->reagents[1]->quantity); - - $this->assertEquals(22785, $recipes[1]->reagents[2]->external_id); - $this->assertEquals('Felweed', $recipes[1]->reagents[2]->name); - $this->assertEquals(2, $recipes[1]->reagents[2]->quantity); - } - - public function test_import_recipe_without_craft_item() - { - $this->seed(\Database\Seeders\ProductionSeeders\ItemSeeder::class); - - $data = (object) [ - "server" => "Ashbringer", - "player" => "Scumbag", - "guild" => "Method", - "profession" => (object) [ - "locale" => "enUS", - "name" => "Enchanting", - "specializationId" => null, - "specializationName" => null, - "level" => 303, - "maxLevel" => 375, - "recipes" => [ - (object) [ - "description" => "Permanently enchant boots to give +7 Agility.", - "name" => "Enchant Boots - Greater Agility", - "num" => 0, - "categorie" => "none", - "items" => [ - (object) [ - "color" => "1eff00", - "id" => 16203, - "num" => 8 - ] - ], - "spellId" => 20023 - ], - (object) [ - "description" => "Transforms a Nexus Crystal into a Small Prismatic Shard.", - "name" => "Nexus Transformation", - "num" => 1, - "categorie" => "none", - "items" => [ - (object) [ - "color" => "a335ee", - "id" => 20725, - "num" => 1 - ] - ], - "spellId" => 42613 - ] - ] - ] - ]; - - Profession::factory()->create([ 'name' => 'Enchanting' ]); - $character = Character::factory()->create([ 'name' => 'Scumbag']); - - ImportProfession::dispatch($character, $data); - - $this->assertEquals('Enchanting', $character->professions[0]->name); - $recipes = $character->professions[0]->recipes; - - // Recipe 1 - $this->assertNull($recipes[0]->craft); - - $this->assertEquals(20023, $recipes[0]->spell->id); - $this->assertEquals('Enchant Boots - Greater Agility', $recipes[0]->spell->name); - - $this->assertEquals(16203, $recipes[0]->reagents[0]->external_id); - $this->assertEquals('Greater Eternal Essence', $recipes[0]->reagents[0]->name); - $this->assertEquals(8, $recipes[0]->reagents[0]->quantity); - - // Recipe 2 - $this->assertNull($recipes[1]->craft); - - $this->assertEquals(42613, $recipes[1]->spell->id); - $this->assertEquals('Nexus Transformation', $recipes[1]->spell->name); - - $this->assertEquals(20725, $recipes[1]->reagents[0]->external_id); - $this->assertEquals('Nexus Crystal', $recipes[1]->reagents[0]->name); - $this->assertEquals(1, $recipes[1]->reagents[0]->quantity); - } - - public function test_import_does_not_create_duplicate_recipes_if_spell_relationship_is_missing() - { - $character = Character::factory()->create([ 'name' => 'Duplicated']); - $profession = Profession::factory()->create([ 'name' => 'My Unique Profession' ]); - $item = Item::factory()->create(['name' => 'Unique Recipe']); - - $recipe = Recipe::factory() - ->for($profession) - ->for($item, 'craft') - ->create(['spell_id' => null]); - - $data = (object) [ - "player" => $character->name, - "profession" => (object) [ - "name" => $profession->name, - "level" => 375, - "maxLevel" => 375, - "recipes" => [ - (object) [ - "name" => $item->name, - "num" => 0, - "categorie" => "none", - "items" => [], - "spellId" => 1337 - ] - ] - ] - ]; - - ImportProfession::dispatch($character, $data); - - $this->assertEquals(1, Recipe::count()); - $this->assertDatabaseHas('recipes', [ - 'spell_id' => 1337, - 'item_id' => $item->id, - ]); - } - - public function test_specialization_is_imported_correctly() - { - $character = Character::factory()->create([ 'name' => 'Specialdude']); - $profession = Profession::factory()->create([ 'name' => 'Alchemy' ]); - $specialization = Spell::factory()->create(['id' => 28672, 'name' => 'Transmutation Master']); - - $data = (object) [ - "player" => $character->name, - "profession" => (object) [ - "name" => $profession->name, - "specializationId" => 28672, - "specializationName" => "Transmutation Master", - "level" => 375, - "recipes" => [], - ] - ]; - - ImportProfession::dispatch($character, $data); - - $this->assertNotNull($character->professions[0]->specialization, "specalization was not imported"); - $this->assertEquals(28672, $character->professions[0]->specialization->id); - $this->assertEquals("Transmutation Master", $character->professions[0]->specialization->name); - - $this->assertEquals(1, Spell::count()); - } - - public function test_specialization_can_be_omitted() - { - $character = Character::factory()->create([ 'name' => 'frankthetank']); - $profession = Profession::factory()->create([ 'name' => 'Carpenter' ]); - - $data = (object) [ - "player" => $character->name, - "profession" => (object) [ - "name" => $profession->name, - "level" => 375, - "recipes" => [], - ] - ]; - - ImportProfession::dispatch($character, $data); - - $this->assertNull($character->professions[0]->specialization); - } -}