2020-04-22 11:51:36 -07:00
|
|
|
const gql = require("graphql-tag");
|
2020-04-22 13:03:32 -07:00
|
|
|
const { ApolloServer } = require("apollo-server");
|
2020-04-22 11:51:36 -07:00
|
|
|
const { createTestClient } = require("apollo-server-testing");
|
|
|
|
|
|
|
|
|
|
const connectToDb = require("./db");
|
|
|
|
|
const actualConnectToDb = jest.requireActual("./db");
|
2020-04-22 13:03:32 -07:00
|
|
|
const { config } = require("./index");
|
2020-04-22 11:51:36 -07:00
|
|
|
|
2020-04-22 13:03:32 -07:00
|
|
|
const { query } = createTestClient(new ApolloServer(config));
|
2020-04-22 11:51:36 -07:00
|
|
|
|
|
|
|
|
// Spy on db.execute, so we can snapshot the queries we run. This can help us
|
|
|
|
|
// keep an eye on perf - watch for tests with way too many queries!
|
|
|
|
|
jest.mock("./db");
|
|
|
|
|
let queryFn;
|
2020-04-22 15:53:59 -07:00
|
|
|
let db;
|
2020-04-23 01:08:00 -07:00
|
|
|
beforeAll(() => {
|
2020-04-22 11:51:36 -07:00
|
|
|
connectToDb.mockImplementation(async (...args) => {
|
2020-04-22 15:53:59 -07:00
|
|
|
db = await actualConnectToDb(...args);
|
2020-04-22 11:51:36 -07:00
|
|
|
queryFn = jest.spyOn(db, "execute");
|
|
|
|
|
return db;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
afterEach(() => {
|
2020-04-23 01:08:00 -07:00
|
|
|
queryFn.mockClear();
|
|
|
|
|
});
|
|
|
|
|
afterAll(() => {
|
2020-04-22 15:53:59 -07:00
|
|
|
db.end();
|
2020-04-22 11:51:36 -07:00
|
|
|
});
|
|
|
|
|
|
2020-04-23 01:08:00 -07:00
|
|
|
describe("Item", () => {
|
|
|
|
|
it("loads metadata", async () => {
|
|
|
|
|
const res = await query({
|
|
|
|
|
query: gql`
|
|
|
|
|
query {
|
|
|
|
|
items(ids: ["38913", "38911", "38912"]) {
|
|
|
|
|
id
|
|
|
|
|
name
|
|
|
|
|
thumbnailUrl
|
|
|
|
|
}
|
2020-04-22 11:51:36 -07:00
|
|
|
}
|
2020-04-23 01:08:00 -07:00
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(res).toHaveNoErrors();
|
|
|
|
|
expect(res.data).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"items": Array [
|
2020-04-23 14:23:46 -07:00
|
|
|
Object {
|
|
|
|
|
"id": "38913",
|
|
|
|
|
"name": "Zafara Agent Gloves",
|
|
|
|
|
"thumbnailUrl": "http://images.neopets.com/items/clo_zafara_agent_gloves.gif",
|
|
|
|
|
},
|
2020-04-23 01:08:00 -07:00
|
|
|
Object {
|
|
|
|
|
"id": "38911",
|
|
|
|
|
"name": "Zafara Agent Hood",
|
|
|
|
|
"thumbnailUrl": "http://images.neopets.com/items/clo_zafara_agent_hood.gif",
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "38912",
|
|
|
|
|
"name": "Zafara Agent Robe",
|
|
|
|
|
"thumbnailUrl": "http://images.neopets.com/items/clo_zafara_agent_robe.gif",
|
|
|
|
|
},
|
|
|
|
|
],
|
2020-04-22 11:51:36 -07:00
|
|
|
}
|
2020-04-23 01:08:00 -07:00
|
|
|
`);
|
|
|
|
|
expect(queryFn.mock.calls).toMatchInlineSnapshot(`
|
|
|
|
|
Array [
|
|
|
|
|
Array [
|
|
|
|
|
"SELECT * FROM items WHERE id IN (?,?,?)",
|
|
|
|
|
Array [
|
|
|
|
|
"38913",
|
|
|
|
|
"38911",
|
|
|
|
|
"38912",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
Array [
|
|
|
|
|
"SELECT * FROM item_translations WHERE item_id IN (?,?,?) AND locale = \\"en\\"",
|
|
|
|
|
Array [
|
2020-04-23 14:23:46 -07:00
|
|
|
"38913",
|
2020-04-23 01:08:00 -07:00
|
|
|
"38911",
|
|
|
|
|
"38912",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
`);
|
2020-04-22 11:51:36 -07:00
|
|
|
});
|
|
|
|
|
|
2020-04-23 01:08:00 -07:00
|
|
|
it("loads appearance data", async () => {
|
|
|
|
|
const res = await query({
|
|
|
|
|
query: gql`
|
|
|
|
|
query {
|
2020-04-23 13:10:42 -07:00
|
|
|
items(ids: ["38912", "38911", "37375"]) {
|
2020-04-23 01:08:00 -07:00
|
|
|
id
|
|
|
|
|
name
|
|
|
|
|
|
|
|
|
|
appearanceOn(speciesId: "54", colorId: "75") {
|
|
|
|
|
layers {
|
|
|
|
|
id
|
|
|
|
|
imageUrl(size: SIZE_600)
|
|
|
|
|
zone {
|
|
|
|
|
id
|
|
|
|
|
depth
|
|
|
|
|
label
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 14:44:06 -07:00
|
|
|
|
|
|
|
|
restrictedZones {
|
|
|
|
|
id
|
|
|
|
|
}
|
2020-04-23 01:08:00 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(res).toHaveNoErrors();
|
|
|
|
|
expect(res.data).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"items": Array [
|
2020-04-23 13:10:42 -07:00
|
|
|
Object {
|
|
|
|
|
"appearanceOn": Object {
|
|
|
|
|
"layers": Array [
|
|
|
|
|
Object {
|
2020-04-23 14:23:46 -07:00
|
|
|
"id": "37128",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/object/000/000/014/14856/600x600.png?v2-1587653266000",
|
2020-04-23 13:10:42 -07:00
|
|
|
"zone": Object {
|
2020-04-23 14:23:46 -07:00
|
|
|
"depth": 30,
|
|
|
|
|
"id": "26",
|
|
|
|
|
"label": "Jacket",
|
2020-04-23 13:10:42 -07:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
2020-04-23 14:44:06 -07:00
|
|
|
"restrictedZones": Array [
|
|
|
|
|
Object {
|
|
|
|
|
"id": "20",
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "22",
|
|
|
|
|
},
|
|
|
|
|
],
|
2020-04-23 13:10:42 -07:00
|
|
|
},
|
2020-04-23 14:23:46 -07:00
|
|
|
"id": "38912",
|
|
|
|
|
"name": "Zafara Agent Robe",
|
2020-04-23 13:10:42 -07:00
|
|
|
},
|
2020-04-23 01:08:00 -07:00
|
|
|
Object {
|
|
|
|
|
"appearanceOn": Object {
|
|
|
|
|
"layers": Array [
|
|
|
|
|
Object {
|
|
|
|
|
"id": "37129",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/object/000/000/014/14857/600x600.png?v2-0",
|
2020-04-23 01:08:00 -07:00
|
|
|
"zone": Object {
|
|
|
|
|
"depth": 44,
|
|
|
|
|
"id": "40",
|
|
|
|
|
"label": "Hat",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
2020-04-23 14:44:06 -07:00
|
|
|
"restrictedZones": Array [
|
|
|
|
|
Object {
|
|
|
|
|
"id": "37",
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "38",
|
|
|
|
|
},
|
|
|
|
|
],
|
2020-04-23 01:08:00 -07:00
|
|
|
},
|
|
|
|
|
"id": "38911",
|
|
|
|
|
"name": "Zafara Agent Hood",
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"appearanceOn": Object {
|
|
|
|
|
"layers": Array [
|
|
|
|
|
Object {
|
2020-04-23 14:23:46 -07:00
|
|
|
"id": "30203",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/object/000/000/006/6829/600x600.png?v2-0",
|
2020-04-23 01:08:00 -07:00
|
|
|
"zone": Object {
|
2020-04-23 14:23:46 -07:00
|
|
|
"depth": 3,
|
|
|
|
|
"id": "3",
|
|
|
|
|
"label": "Background",
|
2020-04-23 01:08:00 -07:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
2020-04-23 14:44:06 -07:00
|
|
|
"restrictedZones": Array [],
|
2020-04-23 01:08:00 -07:00
|
|
|
},
|
2020-04-23 14:23:46 -07:00
|
|
|
"id": "37375",
|
|
|
|
|
"name": "Moon and Stars Background",
|
2020-04-23 01:08:00 -07:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
`);
|
|
|
|
|
expect(queryFn.mock.calls).toMatchInlineSnapshot(`
|
2020-04-22 11:51:36 -07:00
|
|
|
Array [
|
|
|
|
|
Array [
|
2020-04-23 13:10:42 -07:00
|
|
|
"SELECT * FROM items WHERE id IN (?,?,?)",
|
2020-04-23 01:08:00 -07:00
|
|
|
Array [
|
|
|
|
|
"38912",
|
|
|
|
|
"38911",
|
2020-04-23 13:10:42 -07:00
|
|
|
"37375",
|
2020-04-23 01:08:00 -07:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
Array [
|
2020-04-23 13:10:42 -07:00
|
|
|
"SELECT * FROM item_translations WHERE item_id IN (?,?,?) AND locale = \\"en\\"",
|
2020-04-23 01:08:00 -07:00
|
|
|
Array [
|
|
|
|
|
"38912",
|
2020-04-23 14:23:46 -07:00
|
|
|
"38911",
|
|
|
|
|
"37375",
|
2020-04-23 01:08:00 -07:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
Array [
|
2020-04-23 13:10:42 -07:00
|
|
|
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?)",
|
2020-04-23 01:08:00 -07:00
|
|
|
Array [
|
|
|
|
|
"54",
|
|
|
|
|
"75",
|
|
|
|
|
"54",
|
|
|
|
|
"75",
|
2020-04-23 13:10:42 -07:00
|
|
|
"54",
|
|
|
|
|
"75",
|
2020-04-23 01:08:00 -07:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
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
|
2020-04-23 13:10:42 -07:00
|
|
|
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))",
|
2020-04-23 01:08:00 -07:00
|
|
|
Array [
|
2020-04-23 14:23:46 -07:00
|
|
|
"38912",
|
2020-04-23 13:10:42 -07:00
|
|
|
"180",
|
2020-04-23 01:08:00 -07:00
|
|
|
"38911",
|
|
|
|
|
"180",
|
2020-04-23 14:23:46 -07:00
|
|
|
"37375",
|
2020-04-23 01:08:00 -07:00
|
|
|
"180",
|
|
|
|
|
],
|
2020-04-22 11:51:36 -07:00
|
|
|
],
|
|
|
|
|
Array [
|
2020-04-23 13:10:42 -07:00
|
|
|
"SELECT * FROM zones WHERE id IN (?,?,?)",
|
2020-04-23 01:08:00 -07:00
|
|
|
Array [
|
|
|
|
|
"26",
|
2020-04-23 14:23:46 -07:00
|
|
|
"40",
|
|
|
|
|
"3",
|
2020-04-23 01:08:00 -07:00
|
|
|
],
|
2020-04-22 11:51:36 -07:00
|
|
|
],
|
2020-04-23 01:08:00 -07:00
|
|
|
Array [
|
2020-04-23 13:10:42 -07:00
|
|
|
"SELECT * FROM zone_translations WHERE zone_id IN (?,?,?) AND locale = \\"en\\"",
|
2020-04-23 01:08:00 -07:00
|
|
|
Array [
|
|
|
|
|
"26",
|
2020-04-23 14:23:46 -07:00
|
|
|
"40",
|
|
|
|
|
"3",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
`);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("PetAppearance", () => {
|
|
|
|
|
it("loads for species and color", async () => {
|
|
|
|
|
const res = await query({
|
|
|
|
|
query: gql`
|
|
|
|
|
query {
|
|
|
|
|
petAppearance(speciesId: "54", colorId: "75") {
|
|
|
|
|
layers {
|
|
|
|
|
id
|
|
|
|
|
imageUrl(size: SIZE_600)
|
|
|
|
|
zone {
|
|
|
|
|
depth
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(res).toHaveNoErrors();
|
|
|
|
|
expect(res.data).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"petAppearance": Object {
|
|
|
|
|
"layers": Array [
|
|
|
|
|
Object {
|
|
|
|
|
"id": "5995",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/007/7941/600x600.png?v2-0",
|
2020-04-23 14:23:46 -07:00
|
|
|
"zone": Object {
|
|
|
|
|
"depth": 18,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "5996",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/007/7942/600x600.png?v2-0",
|
2020-04-23 14:23:46 -07:00
|
|
|
"zone": Object {
|
|
|
|
|
"depth": 7,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "6000",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/007/7946/600x600.png?v2-0",
|
2020-04-23 14:23:46 -07:00
|
|
|
"zone": Object {
|
|
|
|
|
"depth": 40,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "16467",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/024/24008/600x600.png?v2-0",
|
2020-04-23 14:23:46 -07:00
|
|
|
"zone": Object {
|
|
|
|
|
"depth": 34,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "19549",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/028/28548/600x600.png?v2-1345719457000",
|
2020-04-23 14:23:46 -07:00
|
|
|
"zone": Object {
|
|
|
|
|
"depth": 37,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "19550",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/028/28549/600x600.png?v2-0",
|
2020-04-23 14:23:46 -07:00
|
|
|
"zone": Object {
|
|
|
|
|
"depth": 38,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "163528",
|
2020-04-24 21:38:18 -07:00
|
|
|
"imageUrl": "https://impress-asset-images.s3.amazonaws.com/biology/000/000/028/28549/600x600.png?v2-1326455337000",
|
2020-04-23 14:23:46 -07:00
|
|
|
"zone": Object {
|
|
|
|
|
"depth": 38,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
`);
|
|
|
|
|
expect(queryFn.mock.calls).toMatchInlineSnapshot(`
|
|
|
|
|
Array [
|
|
|
|
|
Array [
|
|
|
|
|
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
|
|
|
|
|
Array [
|
|
|
|
|
"54",
|
|
|
|
|
"75",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
Array [
|
|
|
|
|
"SELECT * FROM pet_states WHERE pet_type_id IN (?)",
|
|
|
|
|
Array [
|
|
|
|
|
"2",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
Array [
|
|
|
|
|
"SELECT sa.*, rel.parent_id FROM swf_assets sa
|
|
|
|
|
INNER JOIN parents_swf_assets rel ON
|
|
|
|
|
rel.parent_type = \\"PetState\\" AND
|
|
|
|
|
rel.swf_asset_id = sa.id
|
|
|
|
|
WHERE rel.parent_id IN (?)",
|
|
|
|
|
Array [
|
|
|
|
|
"2",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
Array [
|
|
|
|
|
"SELECT * FROM zones WHERE id IN (?,?,?,?,?,?)",
|
|
|
|
|
Array [
|
|
|
|
|
"15",
|
|
|
|
|
"5",
|
|
|
|
|
"37",
|
|
|
|
|
"30",
|
|
|
|
|
"33",
|
|
|
|
|
"34",
|
2020-04-23 01:08:00 -07:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
`);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-24 21:17:03 -07:00
|
|
|
describe("Search", () => {
|
|
|
|
|
it("loads Zafara Agent items", async () => {
|
|
|
|
|
const res = await query({
|
|
|
|
|
query: gql`
|
|
|
|
|
query {
|
|
|
|
|
itemSearch(query: "Zafara Agent") {
|
|
|
|
|
id
|
|
|
|
|
name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(res).toHaveNoErrors();
|
|
|
|
|
expect(res.data).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"itemSearch": Array [
|
|
|
|
|
Object {
|
|
|
|
|
"id": "38913",
|
|
|
|
|
"name": "Zafara Agent Gloves",
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "38911",
|
|
|
|
|
"name": "Zafara Agent Hood",
|
|
|
|
|
},
|
|
|
|
|
Object {
|
|
|
|
|
"id": "38912",
|
|
|
|
|
"name": "Zafara Agent Robe",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
`);
|
|
|
|
|
expect(queryFn.mock.calls).toMatchInlineSnapshot(`
|
|
|
|
|
Array [
|
|
|
|
|
Array [
|
|
|
|
|
"SELECT items.* FROM items
|
|
|
|
|
INNER JOIN item_translations t ON t.item_id = items.id
|
|
|
|
|
WHERE t.name LIKE ? AND locale=\\"en\\"
|
|
|
|
|
ORDER BY t.name
|
|
|
|
|
LIMIT 30",
|
|
|
|
|
Array [
|
|
|
|
|
"%Zafara Agent%",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
Array [
|
|
|
|
|
"SELECT * FROM item_translations WHERE item_id IN (?,?,?) AND locale = \\"en\\"",
|
|
|
|
|
Array [
|
|
|
|
|
"38913",
|
|
|
|
|
"38911",
|
|
|
|
|
"38912",
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
`);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-23 01:08:00 -07:00
|
|
|
expect.extend({
|
|
|
|
|
toHaveNoErrors(res) {
|
|
|
|
|
if (res.errors) {
|
|
|
|
|
return {
|
|
|
|
|
message: () =>
|
|
|
|
|
`expected no GraphQL errors, but got:\n ${res.errors}`,
|
|
|
|
|
pass: false,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
message: () => `expected GraphQL errors, but there were none`,
|
|
|
|
|
pass: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-04-22 11:51:36 -07:00
|
|
|
});
|