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.
This commit is contained in:
parent
d8ff99475e
commit
eb2fb125b9
5 changed files with 99 additions and 0 deletions
3
test/fixtures/colors.yml
vendored
Normal file
3
test/fixtures/colors.yml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
purple:
|
||||
id: 57
|
||||
name: purple
|
3
test/fixtures/species.yml
vendored
Normal file
3
test/fixtures/species.yml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
chia:
|
||||
id: 7
|
||||
name: chia
|
60
test/mocks/custom_pets/thyassa.json
Normal file
60
test/mocks/custom_pets/thyassa.json
Normal file
|
@ -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": [
|
||||
|
||||
]
|
||||
}
|
16
test/modeling.rb
Normal file
16
test/modeling.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue