From 91851bc340ca0cac02805ab6ee4bd3e0a220d563 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 19 Nov 2024 13:31:34 -0800 Subject: [PATCH] Add tests for Maraquan item modeling predictions I also added a test I forgot for the standard case: when you've modeled each individual species. --- spec/fixtures/colors.yml | 4 ++ spec/fixtures/species.yml | 3 ++ spec/models/item_spec.rb | 98 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 100 insertions(+), 5 deletions(-) diff --git a/spec/fixtures/colors.yml b/spec/fixtures/colors.yml index 42589873..f23c1200 100644 --- a/spec/fixtures/colors.yml +++ b/spec/fixtures/colors.yml @@ -6,6 +6,10 @@ green: id: 34 name: green basic: true +maraquan: + id: 44 + name: maraquan + standard: false purple: id: 57 name: purple diff --git a/spec/fixtures/species.yml b/spec/fixtures/species.yml index 04f385cc..3509f3e9 100644 --- a/spec/fixtures/species.yml +++ b/spec/fixtures/species.yml @@ -7,6 +7,9 @@ blumaroo: chia: id: 7 name: chia +mynci: + id: 35 + name: mynci jetsam: id: 20 name: jetsam diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index d27044b2..55cb087e 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -7,12 +7,22 @@ RSpec.describe Item do # Rather than using fixtures of real-world data, we create very specific # pet types, to be able to create small encapsulated test cases where there # are only a few bodies. + # + # We create some basic color pet types, and some Maraquan pet types—and, + # just like irl, the Maraquan Mynci has the same body as the basic Mynci. before do PetType.destroy_all # Make sure no leftovers from e.g. PetType's spec! + build_pt(colors(:blue), species(:acara), body_id: 1).save! build_pt(colors(:red), species(:acara), body_id: 1).save! - build_pt(colors(:green), species(:blumaroo), body_id: 2).save! - build_pt(colors(:red), species(:chia), body_id: 3).save! + build_pt(colors(:blue), species(:blumaroo), body_id: 2).save! + build_pt(colors(:green), species(:chia), body_id: 3).save! + build_pt(colors(:red), species(:mynci), body_id: 4).save! + + build_pt(colors(:maraquan), species(:acara), body_id: 11).save! + build_pt(colors(:maraquan), species(:blumaroo), body_id: 12).save! + build_pt(colors(:maraquan), species(:chia), body_id: 13).save! + build_pt(colors(:maraquan), species(:mynci), body_id: 4).save! end def build_pt(color, species, body_id:) @@ -34,7 +44,7 @@ RSpec.describe Item do expect(item.compatible_body_ids).to be_empty end it("predicts all standard bodies are compatible") do - expect(item.predicted_missing_body_ids).to contain_exactly(1, 2, 3) + expect(item.predicted_missing_body_ids).to contain_exactly(1, 2, 3, 4) end end @@ -70,7 +80,29 @@ RSpec.describe Item do expect(item.compatible_body_ids).to contain_exactly(1, 2) end it("predicts remaining standard bodies are compatible") do - expect(item.predicted_missing_body_ids).to contain_exactly(3) + expect(item.predicted_missing_body_ids).to contain_exactly(3, 4) + end + end + + describe "an item with all standard species modeled" do + subject(:item) { items(:straw_hat) } + + before do + item.swf_assets << build_item_asset(zones(:wings), body_id: 1) + item.swf_assets << build_item_asset(zones(:wings), body_id: 2) + item.swf_assets << build_item_asset(zones(:wings), body_id: 3) + item.swf_assets << build_item_asset(zones(:wings), body_id: 4) + # HACK: I don't understand why the first asset is triggering the hooks + # for cached fields, but the second isn't? Idk, force an update. + item.update_cached_fields + end + + it("is fully modeled") { should be_predicted_fully_modeled } + it("is compatible with all standard body IDs") do + expect(item.compatible_body_ids).to contain_exactly(1, 2, 3, 4) + end + it("predicts no more compatible bodies") do + expect(item.predicted_missing_body_ids).to be_empty end end @@ -90,6 +122,62 @@ RSpec.describe Item do end end - pending("Don't forget special colors!") { fail } + describe "an item with one Maraquan pet modeled" do + subject(:item) { items(:straw_hat) } + + before do + item.swf_assets << build_item_asset(zones(:wings), body_id: 11) + end + + it("is considered fully modeled") { should be_predicted_fully_modeled } + it("has one compatible body ID") do + expect(item.compatible_body_ids).to contain_exactly(11) + end + it("predicts no more compatible bodies") do + expect(item.predicted_missing_body_ids).to be_empty + end + end + + describe "an item with two Maraquan pets modeled" do + subject(:item) { items(:straw_hat) } + + before do + item.swf_assets << build_item_asset(zones(:wings), body_id: 11) + item.swf_assets << build_item_asset(zones(:wings), body_id: 12) + # HACK: I don't understand why the first asset is triggering the hooks + # for cached fields, but the second isn't? Idk, force an update. + item.update_cached_fields + end + + it("is not fully modeled") { should_not be_predicted_fully_modeled } + it("has two compatible body IDs") do + expect(item.compatible_body_ids).to contain_exactly(11, 12) + end + it("predicts remaining Maraquan body IDs are compatible") do + expect(item.predicted_missing_body_ids).to contain_exactly(13, 4) + end + end + + describe "an item with all Maraquan species modeled" do + subject(:item) { items(:straw_hat) } + + before do + item.swf_assets << build_item_asset(zones(:wings), body_id: 11) + item.swf_assets << build_item_asset(zones(:wings), body_id: 12) + item.swf_assets << build_item_asset(zones(:wings), body_id: 13) + item.swf_assets << build_item_asset(zones(:wings), body_id: 4) + # HACK: I don't understand why the first asset is triggering the hooks + # for cached fields, but the second isn't? Idk, force an update. + item.update_cached_fields + end + + it("is fully modeled") { should be_predicted_fully_modeled } + it("is compatible with all Maraquan body IDs") do + expect(item.compatible_body_ids).to contain_exactly(11, 12, 13, 4) + end + it("predicts no more compatible bodies") do + expect(item.predicted_missing_body_ids).to be_empty + end + end end end