2020-04-25 23:03:58 -07:00
const gql = require ( "graphql-tag" ) ;
2020-09-12 20:02:56 -07:00
const { query , getDbCalls , logInAsTestUser } = require ( "./setup.js" ) ;
2020-04-25 23:03:58 -07:00
describe ( "Item" , ( ) => {
it ( "loads metadata" , async ( ) => {
const res = await query ( {
query : gql `
query {
2020-08-14 21:12:13 -07:00
items ( ids : [ "38913" , "38911" , "38912" , "55788" , "77530" , "78104" ] ) {
2020-04-25 23:03:58 -07:00
id
name
description
thumbnailUrl
2020-05-31 15:56:40 -07:00
rarityIndex
isNc
2020-07-31 22:31:28 -07:00
manualSpecialColor {
id
name
}
2020-08-14 21:12:13 -07:00
explicitlyBodySpecific
2020-04-25 23:03:58 -07:00
}
}
` ,
} ) ;
expect ( res ) . toHaveNoErrors ( ) ;
expect ( res . data ) . toMatchSnapshot ( ) ;
expect ( getDbCalls ( ) ) . toMatchInlineSnapshot ( `
Array [
Array [
2020-08-14 21:12:13 -07:00
"SELECT * FROM item_translations WHERE item_id IN (?,?,?,?,?,?) AND locale = \\" en \ \ "" ,
2020-04-25 23:03:58 -07:00
Array [
"38913" ,
"38911" ,
"38912" ,
2020-08-14 21:12:13 -07:00
"55788" ,
2020-07-31 22:31:28 -07:00
"77530" ,
2020-05-31 15:56:40 -07:00
"78104" ,
2020-04-25 23:03:58 -07:00
] ,
] ,
Array [
2020-08-14 21:12:13 -07:00
"SELECT * FROM items WHERE id IN (?,?,?,?,?,?)" ,
2020-04-25 23:03:58 -07:00
Array [
"38913" ,
"38911" ,
"38912" ,
2020-08-14 21:12:13 -07:00
"55788" ,
2020-07-31 22:31:28 -07:00
"77530" ,
2020-05-31 15:56:40 -07:00
"78104" ,
2020-04-25 23:03:58 -07:00
] ,
] ,
2020-07-31 22:31:28 -07:00
Array [
" SELECT * FROM color _translations
WHERE color _id IN ( ? ) AND locale = \ \ "en\\" " ,
Array [
"44" ,
] ,
] ,
2020-04-25 23:03:58 -07:00
]
` );
} ) ;
it ( "loads appearance data" , async ( ) => {
const res = await query ( {
query : gql `
query {
items ( ids : [ "38912" , "38911" , "37375" ] ) {
id
name
appearanceOn ( speciesId : "54" , colorId : "75" ) {
layers {
id
2020-08-14 22:09:52 -07:00
remoteId
2020-04-25 23:03:58 -07:00
imageUrl ( size : SIZE _600 )
2020-05-27 00:46:55 -07:00
svgUrl
2020-04-25 23:03:58 -07:00
zone {
id
depth
label
}
}
restrictedZones {
id
}
}
}
}
` ,
} ) ;
expect ( res ) . toHaveNoErrors ( ) ;
expect ( res . data ) . toMatchSnapshot ( ) ;
expect ( getDbCalls ( ) ) . toMatchInlineSnapshot ( `
Array [
Array [
2020-07-02 20:06:04 -07:00
"SELECT * FROM item_translations WHERE item_id IN (?,?,?) AND locale = \\" en \ \ "" ,
2020-04-25 23:03:58 -07:00
Array [
"38912" ,
"38911" ,
"37375" ,
] ,
] ,
Array [
2020-08-17 01:33:34 -07:00
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)" ,
2020-04-25 23:03:58 -07:00
Array [
"54" ,
"75" ,
] ,
] ,
Array [
" SELECT sa . * , rel . parent _id FROM swf _assets sa
INNER JOIN parents _swf _assets rel ON
rel . parent _type = \ \ "Item\\" AND
rel . swf _asset _id = sa . id
WHERE ( rel . parent _id = ? AND ( sa . body _id = ? OR sa . body _id = 0 ) ) OR ( rel . parent _id = ? AND ( sa . body _id = ? OR sa . body _id = 0 ) ) OR ( rel . parent _id = ? AND ( sa . body _id = ? OR sa . body _id = 0 ) ) " ,
Array [
"38912" ,
"180" ,
"38911" ,
"180" ,
"37375" ,
"180" ,
] ,
] ,
2020-08-28 00:10:00 -07:00
Array [
"SELECT * FROM items WHERE id IN (?,?,?)" ,
Array [
"38912" ,
"38911" ,
"37375" ,
] ,
] ,
2020-08-17 18:49:37 -07:00
Array [
"SELECT * FROM zones WHERE id IN (?,?,?)" ,
Array [
"26" ,
"40" ,
"3" ,
] ,
] ,
Array [
"SELECT * FROM zone_translations WHERE zone_id IN (?,?,?) AND locale = \\" en \ \ "" ,
Array [
"26" ,
"40" ,
"3" ,
] ,
] ,
2020-04-25 23:03:58 -07:00
]
` );
} ) ;
2020-05-27 00:46:55 -07:00
2020-09-01 17:00:27 -07:00
it ( "returns empty appearance for incompatible items" , async ( ) => {
const res = await query ( {
query : gql `
query {
items ( ids : [ "38912" ] ) {
id
name
appearanceOn ( speciesId : "1" , colorId : "8" ) {
layers {
id
}
# Pay particular attention to this : normally this item restricts
# zones , but not when the appearance is empty !
restrictedZones {
id
}
}
}
}
` ,
} ) ;
expect ( res ) . toHaveNoErrors ( ) ;
expect ( res . data ) . toMatchInlineSnapshot ( `
Object {
"items" : Array [
Object {
"appearanceOn" : Object {
"layers" : Array [ ] ,
"restrictedZones" : Array [ ] ,
} ,
"id" : "38912" ,
"name" : "Zafara Agent Robe" ,
} ,
] ,
}
` );
expect ( getDbCalls ( ) ) . toMatchInlineSnapshot ( `
Array [
Array [
"SELECT * FROM item_translations WHERE item_id IN (?) AND locale = \\" en \ \ "" ,
Array [
"38912" ,
] ,
] ,
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)" ,
Array [
"1" ,
"8" ,
] ,
] ,
Array [
" SELECT sa . * , rel . parent _id FROM swf _assets sa
INNER JOIN parents _swf _assets rel ON
rel . parent _type = \ \ "Item\\" AND
rel . swf _asset _id = sa . id
WHERE ( rel . parent _id = ? AND ( sa . body _id = ? OR sa . body _id = 0 ) ) " ,
Array [
"38912" ,
"93" ,
] ,
] ,
]
` );
} ) ;
2020-05-27 00:46:55 -07:00
it ( "skips appearance data for audio assets" , async ( ) => {
const res = await query ( {
query : gql `
query {
items ( ids : [ "42829" ] ) {
id
name
appearanceOn ( speciesId : "54" , colorId : "75" ) {
layers {
id
imageUrl ( size : SIZE _600 )
svgUrl
zone {
id
depth
label
}
}
restrictedZones {
id
}
}
}
}
` ,
} ) ;
expect ( res ) . toHaveNoErrors ( ) ;
expect ( res . data ) . toMatchSnapshot ( ) ;
expect ( getDbCalls ( ) ) . toMatchInlineSnapshot ( `
Array [
Array [
2020-07-02 20:06:04 -07:00
"SELECT * FROM item_translations WHERE item_id IN (?) AND locale = \\" en \ \ "" ,
2020-05-27 00:46:55 -07:00
Array [
"42829" ,
] ,
] ,
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)" ,
Array [
"54" ,
"75" ,
] ,
] ,
Array [
" SELECT sa . * , rel . parent _id FROM swf _assets sa
INNER JOIN parents _swf _assets rel ON
rel . parent _type = \ \ "Item\\" AND
rel . swf _asset _id = sa . id
WHERE ( rel . parent _id = ? AND ( sa . body _id = ? OR sa . body _id = 0 ) ) " ,
Array [
"42829" ,
"180" ,
] ,
] ,
2020-08-28 00:10:00 -07:00
Array [
"SELECT * FROM items WHERE id IN (?)" ,
Array [
"42829" ,
] ,
] ,
2020-05-27 00:46:55 -07:00
]
` );
} ) ;
2020-09-06 02:50:04 -07:00
2020-09-12 20:02:56 -07:00
it ( "loads whether we own/want items" , async ( ) => {
await logInAsTestUser ( ) ;
const res = await query ( {
query : gql `
query {
items ( ids : [ "38913" , "39945" , "39948" ] ) {
id
currentUserOwnsThis
currentUserWantsThis
}
}
` ,
} ) ;
expect ( res ) . toHaveNoErrors ( ) ;
expect ( res . data ) . toMatchInlineSnapshot ( `
Object {
"items" : Array [
Object {
"currentUserOwnsThis" : false ,
"currentUserWantsThis" : false ,
"id" : "38913" ,
} ,
Object {
"currentUserOwnsThis" : false ,
"currentUserWantsThis" : true ,
"id" : "39945" ,
} ,
Object {
"currentUserOwnsThis" : true ,
"currentUserWantsThis" : false ,
"id" : "39948" ,
} ,
] ,
}
` );
expect ( getDbCalls ( ) ) . toMatchInlineSnapshot ( `
Array [
Array [
" SELECT closet _hangers . * , item _translations . name as item _name FROM closet _hangers
INNER JOIN items ON items . id = closet _hangers . item _id
INNER JOIN item _translations ON
item _translations . item _id = items . id AND locale = \ \ "en\\"
WHERE user _id IN ( ? )
ORDER BY item _name " ,
Array [
"44743" ,
] ,
] ,
]
` );
} ) ;
it ( "does not own/want items if not logged in" , async ( ) => {
const res = await query ( {
query : gql `
query {
items ( ids : [ "38913" , "39945" , "39948" ] ) {
id
currentUserOwnsThis
currentUserWantsThis
}
}
` ,
} ) ;
expect ( res ) . toHaveNoErrors ( ) ;
expect ( res . data ) . toMatchInlineSnapshot ( `
Object {
"items" : Array [
Object {
"currentUserOwnsThis" : false ,
"currentUserWantsThis" : false ,
"id" : "38913" ,
} ,
Object {
"currentUserOwnsThis" : false ,
"currentUserWantsThis" : false ,
"id" : "39945" ,
} ,
Object {
"currentUserOwnsThis" : false ,
"currentUserWantsThis" : false ,
"id" : "39948" ,
} ,
] ,
}
` );
expect ( getDbCalls ( ) ) . toMatchInlineSnapshot ( ` Array [] ` ) ;
} ) ;
2020-09-06 02:50:04 -07:00
it ( "loads items that need models" , async ( ) => {
jest . setTimeout ( 20000 ) ;
2020-09-06 15:49:08 -07:00
const buildLoaders = require ( "../loaders" ) ;
const db = await require ( "../db" ) ( ) ;
const { itemsThatNeedModelsLoader } = buildLoaders ( db ) ;
await itemsThatNeedModelsLoader . load ( "all" ) ;
2020-09-06 02:50:04 -07:00
const res = await query ( {
query : gql `
query {
itemsThatNeedModels {
id
name
speciesThatNeedModels {
id
name
}
}
}
` ,
} ) ;
expect ( res ) . toHaveNoErrors ( ) ;
expect ( res . data ) . toMatchSnapshot ( ) ;
expect ( getDbCalls ( ) ) . toMatchInlineSnapshot ( `
Array [
Array [
2020-09-15 02:38:23 -07:00
"SELECT * FROM item_translations WHERE item_id IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) AND locale = \\" en \ \ "" ,
2020-09-06 02:50:04 -07:00
Array [
"36907" ,
"42448" ,
"42544" ,
"42546" ,
"50669" ,
"50670" ,
"50671" ,
"50672" ,
"51646" ,
"51651" ,
"51653" ,
"51654" ,
"51655" ,
"53324" ,
"53325" ,
"58285" ,
"59848" ,
"62939" ,
"64195" ,
"64387" ,
"67317" ,
"68228" ,
"69311" ,
"70843" ,
"71110" ,
"71937" ,
"71938" ,
"73707" ,
"73708" ,
"73724" ,
"74259" ,
"74260" ,
"74261" ,
"76108" ,
"76109" ,
"77441" ,
"77442" ,
"81144" ,
"81145" ,
"81229" ,
"81230" ,
"81232" ,
"81233" ,
"81234" ,
"81237" ,
"81238" ,
"81240" ,
"81241" ,
"81242" ,
"81243" ,
"81245" ,
"81246" ,
"81547" ,
2020-09-15 02:38:23 -07:00
"81619" ,
2020-09-06 02:50:04 -07:00
"81630" ,
2020-09-15 02:38:23 -07:00
"81657" ,
"81658" ,
"81659" ,
"81660" ,
"81664" ,
"81667" ,
"81670" ,
"81671" ,
"81672" ,
"81674" ,
"81675" ,
"81693" ,
2020-09-06 02:50:04 -07:00
] ,
] ,
Array [
" SELECT * FROM species _translations
WHERE species _id IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) AND locale = \ \ "en\\" " ,
Array [
"1" ,
2020-09-15 02:38:23 -07:00
"4" ,
"5" ,
"6" ,
2020-09-06 02:50:04 -07:00
"7" ,
"8" ,
2020-09-15 02:38:23 -07:00
"11" ,
"12" ,
2020-09-06 02:50:04 -07:00
"15" ,
"16" ,
"17" ,
"19" ,
2020-09-15 02:38:23 -07:00
"20" ,
"21" ,
2020-09-06 02:50:04 -07:00
"22" ,
2020-09-15 02:38:23 -07:00
"23" ,
"24" ,
2020-09-06 02:50:04 -07:00
"26" ,
2020-09-15 02:38:23 -07:00
"27" ,
2020-09-06 02:50:04 -07:00
"30" ,
"32" ,
"34" ,
"36" ,
"39" ,
"40" ,
2020-09-15 02:38:23 -07:00
"42" ,
2020-09-06 02:50:04 -07:00
"44" ,
2020-09-15 02:38:23 -07:00
"47" ,
"48" ,
"49" ,
"50" ,
2020-09-06 02:50:04 -07:00
"54" ,
2020-09-15 02:38:23 -07:00
"2" ,
"13" ,
"14" ,
"25" ,
2020-09-06 02:50:04 -07:00
"29" ,
2020-09-15 02:38:23 -07:00
"37" ,
2020-09-06 02:50:04 -07:00
"38" ,
"43" ,
"45" ,
"46" ,
2020-09-15 02:38:23 -07:00
"51" ,
2020-09-06 02:50:04 -07:00
"52" ,
"53" ,
2020-09-15 02:38:23 -07:00
"3" ,
"9" ,
"31" ,
"41" ,
2020-09-06 02:50:04 -07:00
"10" ,
2020-09-15 02:38:23 -07:00
"18" ,
"28" ,
"35" ,
"33" ,
2020-09-06 02:50:04 -07:00
"55" ,
] ,
] ,
]
` );
} ) ;
2020-04-25 23:03:58 -07:00
} ) ;