From eb2fb125b900173d968ab69b45a004be7d5692df Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Mon, 21 Oct 2024 14:05:10 -0700 Subject: [PATCH] Basic modeling test! Just getting a basic foothold here. I'm thinking about moving this to RSpec, cuz I feel like the assertions are gonna get pretty specific and groupable. --- test/fixtures/colors.yml | 3 ++ test/fixtures/species.yml | 3 ++ test/mocks/custom_pets/thyassa.json | 60 +++++++++++++++++++++++++++++ test/modeling.rb | 16 ++++++++ test/test_helper.rb | 17 ++++++++ 5 files changed, 99 insertions(+) create mode 100644 test/fixtures/colors.yml create mode 100644 test/fixtures/species.yml create mode 100644 test/mocks/custom_pets/thyassa.json create mode 100644 test/modeling.rb diff --git a/test/fixtures/colors.yml b/test/fixtures/colors.yml new file mode 100644 index 00000000..b31ffcc9 --- /dev/null +++ b/test/fixtures/colors.yml @@ -0,0 +1,3 @@ +purple: + id: 57 + name: purple diff --git a/test/fixtures/species.yml b/test/fixtures/species.yml new file mode 100644 index 00000000..04ce807b --- /dev/null +++ b/test/fixtures/species.yml @@ -0,0 +1,3 @@ +chia: + id: 7 + name: chia diff --git a/test/mocks/custom_pets/thyassa.json b/test/mocks/custom_pets/thyassa.json new file mode 100644 index 00000000..5da69647 --- /dev/null +++ b/test/mocks/custom_pets/thyassa.json @@ -0,0 +1,60 @@ +{ + "custom_pet": { + "name": "thyassa", + "owner": "donna", + "slot": 1.0, + "scale": 0.5, + "muted": false, + "body_id": 212.0, + "species_id": 7.0, + "color_id": 57.0, + "alt_style": false, + "alt_color": 57.0, + "style_closet_id": null, + "biology_by_zone": { + "37": { + "part_id": 10083.0, + "zone_id": 37.0, + "asset_url": "https://images.neopets.com/cp/bio/swf/000/000/010/10083_8a1111a13f.swf", + "manifest": "https://images.neopets.com/cp/bio/data/000/000/010/10083_8a1111a13f/manifest.json", + "zones_restrict": "0000000000000000000000000000000000000000000000000000" + }, + "15": { + "part_id": 11613.0, + "zone_id": 15.0, + "asset_url": "https://images.neopets.com/cp/bio/swf/000/000/011/11613_f7d8d377ab.swf", + "manifest": "https://images.neopets.com/cp/bio/data/000/000/011/11613_f7d8d377ab/manifest.json", + "zones_restrict": "0000000000000000000000000000000000000000000000000000" + }, + "34": { + "part_id": 14187.0, + "zone_id": 34.0, + "asset_url": "https://images.neopets.com/cp/bio/swf/000/000/014/14187_0e65c2082f.swf", + "manifest": "https://images.neopets.com/cp/bio/data/000/000/014/14187_0e65c2082f/manifest.json", + "zones_restrict": "0000000000000000000000000000000000000000000000000000" + }, + "33": { + "part_id": 14189.0, + "zone_id": 33.0, + "asset_url": "https://images.neopets.com/cp/bio/swf/000/000/014/14189_102e4991e9.swf", + "manifest": "https://images.neopets.com/cp/bio/data/000/000/014/14189_102e4991e9/manifest.json", + "zones_restrict": "0000000000000000000000000000000000000000000000000000" + } + }, + "equipped_by_zone": [ + + ], + "original_biology": [ + + ] + }, + "closet_items": [ + + ], + "object_info_registry": [ + + ], + "object_asset_registry": [ + + ] +} diff --git a/test/modeling.rb b/test/modeling.rb new file mode 100644 index 00000000..eee540dc --- /dev/null +++ b/test/modeling.rb @@ -0,0 +1,16 @@ +require 'test_helper' + +class ModelingTest < ActiveSupport::TestCase + test "Modeling thyassa gives us Purple Chia data" do + thyassa = Pet.load("thyassa") + + # The Purple Chia starts as a new record, hooked up to the existing + # Purple color and Chia species. + purple_chia = thyassa.pet_type + assert purple_chia.new_record? + assert_equal Color.find_by_name("purple"), purple_chia.color + assert_equal Species.find_by_name("chia"), purple_chia.species + assert_equal 212, purple_chia.body_id + assert_equal "mock-image-hash:thyassa", purple_chia.image_hash + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 8bf1192f..354abff3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,3 +11,20 @@ class ActiveSupport::TestCase # Add more helper methods to be used by all tests here... end + +# We replace Neopets::CustomPets methods with a mocked implementation. +module Neopets::CustomPets + def self.fetch_viewer_data(pet_name, ...) + File.open(Rails.root / "test/mocks/custom_pets/#{pet_name}.json") do |file| + HashWithIndifferentAccess.new JSON.load(file) + end + end + + def self.fetch_metadata(...) + raise NotImplementedError + end + + def self.fetch_image_hash(pet_name, ...) + "mock-image-hash:#{pet_name}" + end +end