Delete GQL query tests

I haven't been keeping these up to date, so at this point they're more overhead than they're worth.

Helpful in the early days when we were iterating fast and making more mistakes, but now we're more solid (and I learned how to just resend queries from devtools :p)
This commit is contained in:
Emi Matchu 2021-02-04 21:24:53 -08:00
parent 580fd79b8c
commit 927d783a96
17 changed files with 0 additions and 16541 deletions

View file

@ -1,188 +0,0 @@
import gql from "graphql-tag";
import { query, getDbCalls } from "./setup.js";
describe("Color", () => {
it("loads a single color", async () => {
const res = await query({
query: gql`
query {
color(id: "8") {
id
name
isStandard
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"color": Object {
"id": "8",
"isStandard": true,
"name": "Blue",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM colors WHERE id IN (?) AND prank = 0",
Array [
"8",
],
],
Array [
"SELECT * FROM color_translations
WHERE color_id IN (?) AND locale = \\"en\\"",
Array [
"8",
],
],
]
`);
});
it("loads all colors", async () => {
const res = await query({
query: gql`
query {
allColors {
id
name
isStandard
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM colors WHERE prank = 0",
],
Array [
"SELECT * FROM color_translations
WHERE color_id IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) AND locale = \\"en\\"",
Array [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
"43",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"52",
"53",
"54",
"55",
"56",
"57",
"58",
"59",
"60",
"61",
"62",
"63",
"64",
"65",
"66",
"67",
"68",
"69",
"70",
"71",
"72",
"73",
"74",
"75",
"76",
"77",
"78",
"79",
"80",
"81",
"82",
"83",
"84",
"85",
"86",
"87",
"88",
"89",
"90",
"91",
"92",
"93",
"94",
"95",
"96",
"97",
"98",
"99",
"100",
"101",
"102",
"103",
"104",
"105",
"106",
"107",
"108",
"109",
"110",
"111",
"112",
],
],
]
`);
});
});

File diff suppressed because it is too large Load diff

View file

@ -1,419 +0,0 @@
import gql from "graphql-tag";
import { query, getDbCalls } from "./setup.js";
describe("ItemSearch", () => {
it("loads Neopian Times items", async () => {
const res = await query({
query: gql`
query {
itemSearch(query: "Neopian Times") {
query
items {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT items.*, t.name FROM items
INNER JOIN item_translations t ON t.item_id = items.id
WHERE t.name LIKE ? AND t.name LIKE ? AND t.locale=\\"en\\"
ORDER BY t.name
LIMIT 30",
Array [
"%Neopian%",
"%Times%",
],
],
]
`);
});
it("searches for each word separately", async () => {
const res = await query({
query: gql`
query {
itemSearch(query: "Tarla Workshop") {
query
items {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"itemSearch": Object {
"items": Array [
Object {
"id": "50377",
"name": "Tarlas Underground Workshop Background",
},
],
"query": "Tarla Workshop",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT items.*, t.name FROM items
INNER JOIN item_translations t ON t.item_id = items.id
WHERE t.name LIKE ? AND t.name LIKE ? AND t.locale=\\"en\\"
ORDER BY t.name
LIMIT 30",
Array [
"%Tarla%",
"%Workshop%",
],
],
]
`);
});
it("loads Neopian Times items that fit the Starry Zafara", async () => {
const res = await query({
query: gql`
query {
itemSearchToFit(
query: "Neopian Times"
speciesId: "54"
colorId: "75"
) {
query
items {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
Array [
"54",
"75",
],
],
Array [
"SELECT DISTINCT items.*, t.name FROM items
INNER JOIN item_translations t ON t.item_id = items.id
INNER JOIN parents_swf_assets rel
ON rel.parent_type = \\"Item\\" AND rel.parent_id = items.id
INNER JOIN swf_assets ON rel.swf_asset_id = swf_assets.id
WHERE t.name LIKE ? AND t.name LIKE ? AND t.locale=\\"en\\" AND
(swf_assets.body_id = ? OR swf_assets.body_id = 0) AND
1
ORDER BY t.name
LIMIT ? OFFSET ?",
Array [
"%Neopian%",
"%Times%",
"180",
30,
0,
],
],
]
`);
});
it("loads Neopian Times items that fit the Starry Zafara as a Background", async () => {
const res = await query({
query: gql`
query {
itemSearchToFit(
query: "Neopian Times"
speciesId: "54"
colorId: "75"
zoneIds: ["3"]
) {
query
items {
id
name
}
zones {
id
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"itemSearchToFit": Object {
"items": Array [
Object {
"id": "40431",
"name": "Neopian Times Background",
},
],
"query": "Neopian Times",
"zones": Array [
Object {
"id": "3",
},
],
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
Array [
"54",
"75",
],
],
Array [
"SELECT DISTINCT items.*, t.name FROM items
INNER JOIN item_translations t ON t.item_id = items.id
INNER JOIN parents_swf_assets rel
ON rel.parent_type = \\"Item\\" AND rel.parent_id = items.id
INNER JOIN swf_assets ON rel.swf_asset_id = swf_assets.id
WHERE t.name LIKE ? AND t.name LIKE ? AND t.locale=\\"en\\" AND
(swf_assets.body_id = ? OR swf_assets.body_id = 0) AND
swf_assets.zone_id IN (?)
ORDER BY t.name
LIMIT ? OFFSET ?",
Array [
"%Neopian%",
"%Times%",
"180",
"3",
30,
0,
],
],
]
`);
});
it("searches for each word separately (fit mode)", async () => {
const res = await query({
query: gql`
query {
itemSearchToFit(
query: "Tarla Workshop"
speciesId: "54"
colorId: "75"
) {
query
items {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"itemSearchToFit": Object {
"items": Array [
Object {
"id": "50377",
"name": "Tarlas Underground Workshop Background",
},
],
"query": "Tarla Workshop",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
Array [
"54",
"75",
],
],
Array [
"SELECT DISTINCT items.*, t.name FROM items
INNER JOIN item_translations t ON t.item_id = items.id
INNER JOIN parents_swf_assets rel
ON rel.parent_type = \\"Item\\" AND rel.parent_id = items.id
INNER JOIN swf_assets ON rel.swf_asset_id = swf_assets.id
WHERE t.name LIKE ? AND t.name LIKE ? AND t.locale=\\"en\\" AND
(swf_assets.body_id = ? OR swf_assets.body_id = 0) AND
1
ORDER BY t.name
LIMIT ? OFFSET ?",
Array [
"%Tarla%",
"%Workshop%",
"180",
30,
0,
],
],
]
`);
});
it("loads the first 10 hats that fit the Starry Zafara", async () => {
const res = await query({
query: gql`
query {
itemSearchToFit(
query: "hat"
speciesId: "54"
colorId: "75"
offset: 0
limit: 10
) {
query
items {
id
name
appearanceOn(speciesId: "54", colorId: "75") {
layers {
id
}
}
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
Array [
"54",
"75",
],
],
Array [
"SELECT DISTINCT items.*, t.name FROM items
INNER JOIN item_translations t ON t.item_id = items.id
INNER JOIN parents_swf_assets rel
ON rel.parent_type = \\"Item\\" AND rel.parent_id = items.id
INNER JOIN swf_assets ON rel.swf_asset_id = swf_assets.id
WHERE t.name LIKE ? AND t.locale=\\"en\\" AND
(swf_assets.body_id = ? OR swf_assets.body_id = 0) AND
1
ORDER BY t.name
LIMIT ? OFFSET ?",
Array [
"%hat%",
"180",
10,
0,
],
],
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)) 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)) 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)) 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)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0))",
Array [
"74967",
"180",
"49026",
"180",
"67242",
"180",
"64177",
"180",
"69995",
"180",
"62375",
"180",
"56654",
"180",
"62322",
"180",
"58733",
"180",
"80401",
"180",
],
],
]
`);
});
it("loads the next 10 hats that fit the Starry Zafara", async () => {
const res = await query({
query: gql`
query {
itemSearchToFit(
query: "hat"
speciesId: "54"
colorId: "75"
offset: 10
limit: 10
) {
query
items {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
Array [
"54",
"75",
],
],
Array [
"SELECT DISTINCT items.*, t.name FROM items
INNER JOIN item_translations t ON t.item_id = items.id
INNER JOIN parents_swf_assets rel
ON rel.parent_type = \\"Item\\" AND rel.parent_id = items.id
INNER JOIN swf_assets ON rel.swf_asset_id = swf_assets.id
WHERE t.name LIKE ? AND t.locale=\\"en\\" AND
(swf_assets.body_id = ? OR swf_assets.body_id = 0) AND
1
ORDER BY t.name
LIMIT ? OFFSET ?",
Array [
"%hat%",
"180",
10,
10,
],
],
]
`);
});
});

View file

@ -1,104 +0,0 @@
import gql from "graphql-tag";
import { query, getDbCalls } from "./setup.js";
describe("Outfit", () => {
it("loads an outfit by ID", async () => {
const res = await query({
query: gql`
query {
outfit(id: "31856") {
id
name
petAppearance {
id
color {
id
name
}
species {
id
name
}
pose
}
wornItems {
id
name
}
closetedItems {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM outfits WHERE id IN (?)",
Array [
"31856",
],
],
Array [
"SELECT * FROM item_outfit_relationships WHERE outfit_id IN (?)",
Array [
"31856",
],
],
Array [
"SELECT * FROM pet_states WHERE id IN (?)",
Array [
"3951",
],
],
Array [
"SELECT * FROM item_translations WHERE item_id IN (?,?,?,?,?,?,?,?,?,?,?) AND locale = \\"en\\"",
Array [
"38916",
"51054",
"38914",
"36125",
"36467",
"47075",
"47056",
"39662",
"56706",
"38915",
"56398",
],
],
Array [
"SELECT * FROM pet_types WHERE id IN (?)",
Array [
"33",
],
],
Array [
"SELECT * FROM color_translations
WHERE color_id IN (?) AND locale = \\"en\\"",
Array [
"34",
],
],
Array [
"SELECT * FROM species_translations
WHERE species_id IN (?) AND locale = \\"en\\"",
Array [
"54",
],
],
]
`);
});
});

View file

@ -1,404 +0,0 @@
import gql from "graphql-tag";
import {
query,
getDbCalls,
clearDbCalls,
useTestDb,
connectToDb,
} from "./setup.js";
describe("Pet", () => {
it("looks up a pet", async () => {
const res = await query({
query: gql`
query {
petOnNeopetsDotCom(petName: "roopal27") {
species {
id
name
}
color {
id
name
}
pose
items {
id
name
description
thumbnailUrl
rarityIndex
isNc
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
Array [
"54",
"75",
],
],
Array [
"SELECT * FROM items WHERE id IN (?,?,?,?,?,?,?,?)",
Array [
"37229",
"37375",
"38911",
"38912",
"38913",
"43014",
"43397",
"48313",
],
],
Array [
"SELECT * FROM item_translations WHERE item_id IN (?,?,?,?,?,?,?,?) AND locale = \\"en\\"",
Array [
"37229",
"37375",
"38911",
"38912",
"38913",
"43014",
"43397",
"48313",
],
],
Array [
"SELECT * FROM swf_assets WHERE (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?) OR (type = ? AND remote_id = ?)",
Array [
"object",
"6829",
"object",
"14855",
"object",
"14856",
"object",
"14857",
"object",
"36414",
"object",
"39646",
"object",
"51959",
"object",
"56478",
"biology",
"7942",
"biology",
"7941",
"biology",
"24008",
"biology",
"21060",
"biology",
"21057",
"biology",
"7946",
],
],
Array [
"SELECT * FROM pet_states WHERE (pet_type_id = ? AND swf_asset_ids = ?)",
Array [
"2",
"7941,7942,7946,21057,21060,24008",
],
],
Array [
"SELECT * FROM species_translations
WHERE species_id IN (?) AND locale = \\"en\\"",
Array [
54,
],
],
Array [
"SELECT * FROM color_translations
WHERE color_id IN (?) AND locale = \\"en\\"",
Array [
75,
],
],
]
`);
});
it("models new pet and item data", async () => {
useTestDb();
const res = await query({
query: gql`
query {
petOnNeopetsDotCom(petName: "roopal27") {
items {
id
name
description
thumbnailUrl
rarityIndex
isNc
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchSnapshot();
clearDbCalls();
const res2 = await query({
query: gql`
query {
petAppearance(colorId: "75", speciesId: "54", pose: SAD_MASC) {
id
pose
bodyId
restrictedZones {
id
}
layers {
id
swfUrl
}
}
items(
ids: [
"37229"
"37375"
"38911"
"38912"
"38913"
"43014"
"43397"
"48313"
]
) {
id
name
description
thumbnailUrl
rarityIndex
isNc
createdAt
appearanceOn(colorId: "75", speciesId: "54") {
layers {
id
swfUrl
}
}
}
}
`,
});
expect(res2).toHaveNoErrors();
expect(res2.data).toMatchSnapshot();
expect(getDbCalls()).toMatchSnapshot();
clearDbCalls();
// If we load the pet again, it should only make SELECT queries, not
// INSERT or UPDATE.
await query({
query: gql`
query {
petOnNeopetsDotCom(petName: "roopal27") {
items {
id
}
}
}
`,
});
const dbCalls = getDbCalls();
for (const [query, _] of dbCalls) {
expect(query).toMatch(/SELECT/);
expect(query).not.toMatch(/INSERT/);
expect(query).not.toMatch(/UPDATE/);
}
});
it("models updated item data", async () => {
useTestDb();
// First, write a fake version of the Jewelled Staff to the database.
// It's mostly the real data, except we changed rarity_index,
// thumbnail_url, translated name, and translated description.
const db = await connectToDb();
await Promise.all([
db.query(
`INSERT INTO items (id, zones_restrict, thumbnail_url, category,
type, rarity_index, price, weight_lbs)
VALUES (43397, "00000000000000000000000000000000000000000000000",
"http://example.com/favicon.ico", "Clothes", "Clothes", 101,
0, 1);`
),
db.query(
`INSERT INTO item_translations (item_id, locale, name, description,
rarity)
VALUES (43397, "en", "Bejewelled Staffo",
"This staff is really neat and good!", "Artifact")`
),
]);
clearDbCalls();
// Then, load a pet wearing this. It should trigger an UPDATE for the item
// and its translation, and return the new names in the query.
const res = await query({
query: gql`
query {
petOnNeopetsDotCom(petName: "roopal27") {
items {
id
name
description
thumbnailUrl
rarityIndex
}
}
}
`,
});
expect(res).toHaveNoErrors();
const itemData = res.data.petOnNeopetsDotCom.items.find(
(item) => item.id === "43397"
);
expect(itemData).toEqual({
id: "43397",
name: "Jewelled Staff",
description: "This jewelled staff shines with a magical light.",
thumbnailUrl: "http://images.neopets.com/items/mall_staff_jewelled.gif",
rarityIndex: 500,
});
expect(getDbCalls()).toMatchSnapshot();
clearDbCalls();
// Finally, load the item. It should have the updated values.
const res2 = await query({
query: gql`
query {
item(id: "43397") {
id
name
description
thumbnailUrl
rarityIndex
}
}
`,
});
expect(res2).toHaveNoErrors();
expect(res2.data.item).toEqual({
id: "43397",
name: "Jewelled Staff",
description: "This jewelled staff shines with a magical light.",
thumbnailUrl: "http://images.neopets.com/items/mall_staff_jewelled.gif",
rarityIndex: 500,
});
expect(getDbCalls()).toMatchSnapshot();
});
it("sets bodyId=0 after seeing it on two body types", async () => {
useTestDb();
// First, write the Moon and Stars Background SWF to the database, but with
// the Standard Acara body ID set.
const db = await connectToDb();
await db.query(
`INSERT INTO swf_assets (type, remote_id, url, zone_id, zones_restrict,
created_at, body_id)
VALUES ("object", 6829, "http://images.neopets.com/cp/items/swf/000/000/006/6829_1707e50385.swf",
3, "", CURRENT_TIMESTAMP(), 93);`
);
clearDbCalls();
// Then, model a Zafara wearing it.
await query({
query: gql`
query {
petOnNeopetsDotCom(petName: "roopal27") {
id
}
}
`,
});
expect(getDbCalls()).toMatchSnapshot("db");
// The body ID should be 0 now.
const [rows, _] = await db.query(
`SELECT body_id FROM swf_assets
WHERE type = "object" AND remote_id = 6829;`
);
expect(rows[0].body_id).toEqual(0);
});
it("models unconverted pets", async () => {
useTestDb();
// First, model an unconverted pet, and check its pose and layers.
const res = await query({
query: gql`
query {
petOnNeopetsDotCom(petName: "Marishka82") {
pose
petAppearance {
id
pose
layers {
id
}
}
}
}
`,
});
expect(res).toHaveNoErrors();
const modeledPet = res.data.petOnNeopetsDotCom;
expect(modeledPet.pose).toEqual("UNCONVERTED");
expect(modeledPet.petAppearance.pose).toEqual("UNCONVERTED");
expect(modeledPet.petAppearance.layers).toHaveLength(1);
// Then, request the corresponding appearance fresh from the db, and
// confirm we get the same back as when we modeled the pet.
const res2 = await query({
query: gql`
query {
petAppearance(speciesId: "31", colorId: "36", pose: UNCONVERTED) {
id
layers {
id
}
}
}
`,
});
expect(res2).toHaveNoErrors();
const petAppearance = res2.data.petAppearance;
expect(petAppearance.id).toEqual(modeledPet.petAppearance.id);
expect(petAppearance.layers.map((l) => l.id)).toEqual(
modeledPet.petAppearance.layers.map((l) => l.id)
);
});
});

View file

@ -1,297 +0,0 @@
import gql from "graphql-tag";
import { query, getDbCalls } from "./setup.js";
describe("PetAppearance", () => {
it("loads for species and color", async () => {
const res = await query({
query: gql`
query {
petAppearance(speciesId: "54", colorId: "75", pose: HAPPY_FEM) {
id
species {
id
name
}
color {
id
name
isStandard
}
layers {
id
imageUrl(size: SIZE_600)
svgUrl
zone {
depth
}
}
restrictedZones {
id
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).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 (?)
ORDER BY (mood_id IS NULL) ASC, mood_id ASC, female DESC,
unconverted DESC, glitched ASC, id DESC",
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 [
"17723",
],
],
Array [
"SELECT * FROM species_translations
WHERE species_id IN (?) AND locale = \\"en\\"",
Array [
"54",
],
],
Array [
"SELECT * FROM color_translations
WHERE color_id IN (?) AND locale = \\"en\\"",
Array [
"75",
],
],
Array [
"SELECT * FROM colors WHERE id IN (?) AND prank = 0",
Array [
"75",
],
],
Array [
"SELECT * FROM zones WHERE id IN (?,?,?,?,?,?)",
Array [
"15",
"5",
"37",
"30",
"33",
"34",
],
],
]
`);
});
it("loads multiple for species and color", async () => {
const res = await query({
query: gql`
query {
petAppearances(speciesId: "54", colorId: "75") {
id
species {
id
name
}
color {
id
name
}
bodyId
petStateId
pose
layers {
id
imageUrl(size: SIZE_600)
zone {
depth
}
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).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 (?)
ORDER BY (mood_id IS NULL) ASC, mood_id ASC, female DESC,
unconverted DESC, glitched ASC, id DESC",
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 [
"17723",
"17742",
"5991",
"436",
"10014",
"11089",
"4751",
"2",
],
],
Array [
"SELECT * FROM species_translations
WHERE species_id IN (?) AND locale = \\"en\\"",
Array [
"54",
],
],
Array [
"SELECT * FROM color_translations
WHERE color_id IN (?) AND locale = \\"en\\"",
Array [
"75",
],
],
Array [
"SELECT * FROM zones WHERE id IN (?,?,?,?,?,?)",
Array [
"15",
"5",
"37",
"30",
"33",
"34",
],
],
]
`);
});
it("loads unconverted appearance", async () => {
const res = await query({
query: gql`
query {
petAppearance(speciesId: "1", colorId: "63", pose: UNCONVERTED) {
id
species {
id
name
}
color {
id
name
isStandard
}
layers {
id
imageUrl(size: SIZE_600)
svgUrl
zone {
depth
}
}
restrictedZones {
id
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
Array [
"1",
"63",
],
],
Array [
"SELECT * FROM pet_states
WHERE pet_type_id IN (?)
ORDER BY (mood_id IS NULL) ASC, mood_id ASC, female DESC,
unconverted DESC, glitched ASC, id DESC",
Array [
"2274",
],
],
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 [
"2571",
],
],
Array [
"SELECT * FROM species_translations
WHERE species_id IN (?) AND locale = \\"en\\"",
Array [
"1",
],
],
Array [
"SELECT * FROM color_translations
WHERE color_id IN (?) AND locale = \\"en\\"",
Array [
"63",
],
],
Array [
"SELECT * FROM colors WHERE id IN (?) AND prank = 0",
Array [
"63",
],
],
Array [
"SELECT * FROM zones WHERE id IN (?)",
Array [
"46",
],
],
]
`);
});
});

View file

@ -1,253 +0,0 @@
import gql from "graphql-tag";
import { query, getDbCalls } from "./setup.js";
describe("Species", () => {
it("loads a single species", async () => {
const res = await query({
query: gql`
query {
species(id: "1") {
id
name
standardBodyId
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"species": Object {
"id": "1",
"name": "Acara",
"standardBodyId": "93",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM species WHERE id IN (?)",
Array [
"1",
],
],
Array [
"SELECT * FROM species_translations
WHERE species_id IN (?) AND locale = \\"en\\"",
Array [
"1",
],
],
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
Array [
"1",
"8",
],
],
]
`);
});
it("loads all species", async () => {
const res = await query({
query: gql`
query {
allSpecies {
id
name
standardBodyId
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot();
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM species",
],
Array [
"SELECT * FROM species_translations
WHERE species_id IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) AND locale = \\"en\\"",
Array [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
"43",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"52",
"53",
"54",
"55",
],
],
Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?)",
Array [
"1",
"8",
"2",
"8",
"3",
"8",
"4",
"8",
"5",
"8",
"6",
"8",
"7",
"8",
"8",
"8",
"9",
"8",
"10",
"8",
"11",
"8",
"12",
"8",
"13",
"8",
"14",
"8",
"15",
"8",
"16",
"8",
"17",
"8",
"18",
"8",
"19",
"8",
"20",
"8",
"21",
"8",
"22",
"8",
"23",
"8",
"24",
"8",
"25",
"8",
"26",
"8",
"27",
"8",
"28",
"8",
"29",
"8",
"30",
"8",
"31",
"8",
"32",
"8",
"33",
"8",
"34",
"8",
"35",
"8",
"36",
"8",
"37",
"8",
"38",
"8",
"39",
"8",
"40",
"8",
"41",
"8",
"42",
"8",
"43",
"8",
"44",
"8",
"45",
"8",
"46",
"8",
"47",
"8",
"48",
"8",
"49",
"8",
"50",
"8",
"51",
"8",
"52",
"8",
"53",
"8",
"54",
"8",
"55",
"8",
],
],
]
`);
});
});

View file

@ -1,458 +0,0 @@
import gql from "graphql-tag";
import { query, getDbCalls, logInAsTestUser } from "./setup.js";
describe("User", () => {
it("looks up a user", async () => {
// TODO: I'm not sure why this is taking extra time, maybe the db conn?
jest.setTimeout(20000);
const res = await query({
query: gql`
query {
user(id: "6") {
id
username
contactNeopetsUsername
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"user": Object {
"contactNeopetsUsername": "matchu1993",
"id": "6",
"username": "matchu",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM users WHERE id IN (?)",
Array [
"6",
],
],
Array [
"SELECT * FROM neopets_connections WHERE id IN (?)",
Array [
"1",
],
],
]
`);
});
it("returns null when user not found", async () => {
const res = await query({
query: gql`
query {
user(id: "<invalid-user-id>") {
id
username
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toEqual({ user: null });
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM users WHERE id IN (?)",
Array [
"<invalid-user-id>",
],
],
]
`);
});
it("gets current user, if logged in", async () => {
await logInAsTestUser();
const res = await query({
query: gql`
query {
currentUser {
id
username
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"currentUser": Object {
"id": "44743",
"username": "dti-test",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM users WHERE id IN (?)",
Array [
"44743",
],
],
]
`);
});
it("gets no user, if logged out", async () => {
const res = await query({
query: gql`
query {
currentUser {
id
username
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toEqual({ currentUser: null });
expect(getDbCalls()).toMatchInlineSnapshot(`Array []`);
});
it("gets private items they own for current user", async () => {
await logInAsTestUser();
const res = await query({
query: gql`
query {
user(id: "44743") {
id
username
itemsTheyOwn {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"user": Object {
"id": "44743",
"itemsTheyOwn": Array [
Object {
"id": "74967",
"name": "17th Birthday Party Hat",
},
Object {
"id": "49026",
"name": "Abominable Snowman Hat",
},
Object {
"id": "39948",
"name": "Altador Cup Background - Lost Desert",
},
Object {
"id": "39955",
"name": "Altador Cup Background - Virtupets",
},
Object {
"id": "40319",
"name": "Blue Jelly Tiara",
},
],
"username": "dti-test",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM users WHERE id IN (?)",
Array [
"44743",
],
],
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",
],
],
Array [
"SELECT * FROM closet_lists
WHERE user_id IN (?)
ORDER BY name",
Array [
"44743",
],
],
]
`);
});
it("hides private items they own from other users", async () => {
const res = await query({
query: gql`
query {
user(id: "44743") {
id
username
itemsTheyOwn {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"user": Object {
"id": "44743",
"itemsTheyOwn": Array [
Object {
"id": "39955",
"name": "Altador Cup Background - Virtupets",
},
],
"username": "dti-test",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM users WHERE id IN (?)",
Array [
"44743",
],
],
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",
],
],
Array [
"SELECT * FROM closet_lists
WHERE user_id IN (?)
ORDER BY name",
Array [
"44743",
],
],
]
`);
});
it("gets private items they want for current user", async () => {
await logInAsTestUser();
const res = await query({
query: gql`
query {
user(id: "44743") {
id
username
itemsTheyWant {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"user": Object {
"id": "44743",
"itemsTheyWant": Array [
Object {
"id": "39945",
"name": "Altador Cup Background - Haunted Woods",
},
Object {
"id": "39956",
"name": "Altador Cup Background - Kreludor",
},
Object {
"id": "39947",
"name": "Altador Cup Background - Shenkuu",
},
],
"username": "dti-test",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM users WHERE id IN (?)",
Array [
"44743",
],
],
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",
],
],
Array [
"SELECT * FROM closet_lists
WHERE user_id IN (?)
ORDER BY name",
Array [
"44743",
],
],
]
`);
});
it("hides private items they want from other users", async () => {
const res = await query({
query: gql`
query {
user(id: "44743") {
id
username
itemsTheyWant {
id
name
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchInlineSnapshot(`
Object {
"user": Object {
"id": "44743",
"itemsTheyWant": Array [
Object {
"id": "39947",
"name": "Altador Cup Background - Shenkuu",
},
],
"username": "dti-test",
},
}
`);
expect(getDbCalls()).toMatchInlineSnapshot(`
Array [
Array [
"SELECT * FROM users WHERE id IN (?)",
Array [
"44743",
],
],
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",
],
],
Array [
"SELECT * FROM closet_lists
WHERE user_id IN (?)
ORDER BY name",
Array [
"44743",
],
],
]
`);
});
it("gets public closet lists, but not private, for other users", async () => {
const res = await query({
query: gql`
query {
user(id: "44743") {
id
username
closetLists {
id
name
ownsOrWantsItems
isDefaultList
items {
id
name
}
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot("data");
expect(getDbCalls()).toMatchSnapshot("db");
});
it("gets public and private closet lists for current user", async () => {
await logInAsTestUser();
const res = await query({
query: gql`
query {
user(id: "44743") {
id
username
closetLists {
id
name
ownsOrWantsItems
isDefaultList
items {
id
name
}
}
}
}
`,
});
expect(res).toHaveNoErrors();
expect(res.data).toMatchSnapshot("data");
expect(getDbCalls()).toMatchSnapshot("db");
});
});

View file

@ -1,568 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Color loads all colors 1`] = `
Object {
"allColors": Array [
Object {
"id": "1",
"isStandard": true,
"name": "Alien",
},
Object {
"id": "2",
"isStandard": false,
"name": "Apple",
},
Object {
"id": "3",
"isStandard": false,
"name": "Asparagus",
},
Object {
"id": "4",
"isStandard": false,
"name": "Aubergine",
},
Object {
"id": "5",
"isStandard": false,
"name": "Avocado",
},
Object {
"id": "6",
"isStandard": false,
"name": "Baby",
},
Object {
"id": "7",
"isStandard": true,
"name": "Biscuit",
},
Object {
"id": "8",
"isStandard": true,
"name": "Blue",
},
Object {
"id": "9",
"isStandard": false,
"name": "Blueberry",
},
Object {
"id": "10",
"isStandard": true,
"name": "Brown",
},
Object {
"id": "11",
"isStandard": true,
"name": "Camouflage",
},
Object {
"id": "12",
"isStandard": false,
"name": "Carrot",
},
Object {
"id": "13",
"isStandard": true,
"name": "Checkered",
},
Object {
"id": "14",
"isStandard": true,
"name": "Chocolate",
},
Object {
"id": "15",
"isStandard": false,
"name": "Chokato",
},
Object {
"id": "16",
"isStandard": true,
"name": "Christmas",
},
Object {
"id": "17",
"isStandard": true,
"name": "Clay",
},
Object {
"id": "18",
"isStandard": true,
"name": "Cloud",
},
Object {
"id": "19",
"isStandard": true,
"name": "Coconut",
},
Object {
"id": "20",
"isStandard": true,
"name": "Custard",
},
Object {
"id": "21",
"isStandard": true,
"name": "Darigan",
},
Object {
"id": "22",
"isStandard": true,
"name": "Desert",
},
Object {
"id": "23",
"isStandard": true,
"name": "Disco",
},
Object {
"id": "24",
"isStandard": false,
"name": "Durian",
},
Object {
"id": "25",
"isStandard": true,
"name": "Electric",
},
Object {
"id": "26",
"isStandard": true,
"name": "Faerie",
},
Object {
"id": "27",
"isStandard": true,
"name": "Fire",
},
Object {
"id": "28",
"isStandard": true,
"name": "Garlic",
},
Object {
"id": "29",
"isStandard": true,
"name": "Ghost",
},
Object {
"id": "30",
"isStandard": true,
"name": "Glowing",
},
Object {
"id": "31",
"isStandard": true,
"name": "Gold",
},
Object {
"id": "32",
"isStandard": false,
"name": "Gooseberry",
},
Object {
"id": "33",
"isStandard": false,
"name": "Grape",
},
Object {
"id": "34",
"isStandard": true,
"name": "Green",
},
Object {
"id": "35",
"isStandard": true,
"name": "Grey",
},
Object {
"id": "36",
"isStandard": true,
"name": "Halloween",
},
Object {
"id": "37",
"isStandard": true,
"name": "Ice",
},
Object {
"id": "38",
"isStandard": true,
"name": "Invisible",
},
Object {
"id": "39",
"isStandard": true,
"name": "Island",
},
Object {
"id": "40",
"isStandard": true,
"name": "Jelly",
},
Object {
"id": "41",
"isStandard": false,
"name": "Lemon",
},
Object {
"id": "42",
"isStandard": false,
"name": "Lime",
},
Object {
"id": "43",
"isStandard": true,
"name": "Mallow",
},
Object {
"id": "44",
"isStandard": false,
"name": "Maraquan",
},
Object {
"id": "45",
"isStandard": true,
"name": "Msp",
},
Object {
"id": "46",
"isStandard": false,
"name": "Mutant",
},
Object {
"id": "47",
"isStandard": false,
"name": "Orange",
},
Object {
"id": "48",
"isStandard": false,
"name": "Pea",
},
Object {
"id": "49",
"isStandard": false,
"name": "Peach",
},
Object {
"id": "50",
"isStandard": false,
"name": "Pear",
},
Object {
"id": "51",
"isStandard": false,
"name": "Pepper",
},
Object {
"id": "52",
"isStandard": false,
"name": "Pineapple",
},
Object {
"id": "53",
"isStandard": true,
"name": "Pink",
},
Object {
"id": "54",
"isStandard": true,
"name": "Pirate",
},
Object {
"id": "55",
"isStandard": false,
"name": "Plum",
},
Object {
"id": "56",
"isStandard": true,
"name": "Plushie",
},
Object {
"id": "57",
"isStandard": true,
"name": "Purple",
},
Object {
"id": "58",
"isStandard": true,
"name": "Quigukiboy",
},
Object {
"id": "59",
"isStandard": true,
"name": "Quigukigirl",
},
Object {
"id": "60",
"isStandard": true,
"name": "Rainbow",
},
Object {
"id": "61",
"isStandard": true,
"name": "Red",
},
Object {
"id": "62",
"isStandard": true,
"name": "Robot",
},
Object {
"id": "63",
"isStandard": true,
"name": "Royalboy",
},
Object {
"id": "64",
"isStandard": true,
"name": "Royalgirl",
},
Object {
"id": "65",
"isStandard": true,
"name": "Shadow",
},
Object {
"id": "66",
"isStandard": true,
"name": "Silver",
},
Object {
"id": "67",
"isStandard": true,
"name": "Sketch",
},
Object {
"id": "68",
"isStandard": true,
"name": "Skunk",
},
Object {
"id": "69",
"isStandard": true,
"name": "Snot",
},
Object {
"id": "70",
"isStandard": true,
"name": "Snow",
},
Object {
"id": "71",
"isStandard": true,
"name": "Speckled",
},
Object {
"id": "72",
"isStandard": true,
"name": "Split",
},
Object {
"id": "73",
"isStandard": true,
"name": "Sponge",
},
Object {
"id": "74",
"isStandard": true,
"name": "Spotted",
},
Object {
"id": "75",
"isStandard": true,
"name": "Starry",
},
Object {
"id": "76",
"isStandard": true,
"name": "Strawberry",
},
Object {
"id": "77",
"isStandard": true,
"name": "Striped",
},
Object {
"id": "78",
"isStandard": false,
"name": "Thornberry",
},
Object {
"id": "79",
"isStandard": false,
"name": "Tomato",
},
Object {
"id": "80",
"isStandard": true,
"name": "Tyrannian",
},
Object {
"id": "81",
"isStandard": true,
"name": "Usuki boy",
},
Object {
"id": "82",
"isStandard": true,
"name": "Usuki girl",
},
Object {
"id": "83",
"isStandard": true,
"name": "White",
},
Object {
"id": "84",
"isStandard": true,
"name": "Yellow",
},
Object {
"id": "85",
"isStandard": true,
"name": "Zombie",
},
Object {
"id": "86",
"isStandard": false,
"name": "Onion",
},
Object {
"id": "87",
"isStandard": true,
"name": "Magma",
},
Object {
"id": "88",
"isStandard": true,
"name": "Relic",
},
Object {
"id": "89",
"isStandard": true,
"name": "Woodland",
},
Object {
"id": "90",
"isStandard": true,
"name": "Transparent",
},
Object {
"id": "91",
"isStandard": true,
"name": "Maractite",
},
Object {
"id": "92",
"isStandard": false,
"name": "8-bit",
},
Object {
"id": "93",
"isStandard": true,
"name": "Swamp gas",
},
Object {
"id": "94",
"isStandard": true,
"name": "Water",
},
Object {
"id": "95",
"isStandard": true,
"name": "Wraith",
},
Object {
"id": "96",
"isStandard": true,
"name": "Eventide",
},
Object {
"id": "97",
"isStandard": true,
"name": "Elderlyboy",
},
Object {
"id": "98",
"isStandard": true,
"name": "Elderlygirl",
},
Object {
"id": "99",
"isStandard": true,
"name": "Stealthy",
},
Object {
"id": "100",
"isStandard": true,
"name": "Dimensional",
},
Object {
"id": "101",
"isStandard": false,
"name": "Agueena",
},
Object {
"id": "102",
"isStandard": true,
"name": "Pastel",
},
Object {
"id": "103",
"isStandard": true,
"name": "Ummagine",
},
Object {
"id": "104",
"isStandard": true,
"name": "Polka Dot",
},
Object {
"id": "105",
"isStandard": true,
"name": "Candy",
},
Object {
"id": "106",
"isStandard": true,
"name": "Marble",
},
Object {
"id": "107",
"isStandard": true,
"name": "Steampunk",
},
Object {
"id": "108",
"isStandard": true,
"name": "Toy",
},
Object {
"id": "109",
"isStandard": true,
"name": "Origami",
},
Object {
"id": "110",
"isStandard": true,
"name": "Oil Paint",
},
Object {
"id": "111",
"isStandard": true,
"name": "Mosaic",
},
Object {
"id": "112",
"isStandard": true,
"name": "Burlap",
},
],
}
`;

File diff suppressed because it is too large Load diff

View file

@ -1,314 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ItemSearch loads Neopian Times items 1`] = `
Object {
"itemSearch": Object {
"items": Array [
Object {
"id": "40431",
"name": "Neopian Times Background",
},
Object {
"id": "59391",
"name": "Neopian Times Eyrie Hat",
},
Object {
"id": "59392",
"name": "Neopian Times Eyrie Shirt and Vest",
},
Object {
"id": "59394",
"name": "Neopian Times Eyrie Shoes",
},
Object {
"id": "59393",
"name": "Neopian Times Eyrie Trousers",
},
Object {
"id": "59390",
"name": "Neopian Times Eyries Paper",
},
Object {
"id": "51098",
"name": "Neopian Times Writing Quill",
},
Object {
"id": "61101",
"name": "Neopian Times Zafara Handkerchief",
},
Object {
"id": "61100",
"name": "Neopian Times Zafara Hat",
},
Object {
"id": "61102",
"name": "Neopian Times Zafara Shirt and Vest",
},
Object {
"id": "61104",
"name": "Neopian Times Zafara Shoes",
},
Object {
"id": "61103",
"name": "Neopian Times Zafara Trousers",
},
],
"query": "Neopian Times",
},
}
`;
exports[`ItemSearch loads Neopian Times items that fit the Starry Zafara 1`] = `
Object {
"itemSearchToFit": Object {
"items": Array [
Object {
"id": "40431",
"name": "Neopian Times Background",
},
Object {
"id": "51098",
"name": "Neopian Times Writing Quill",
},
Object {
"id": "61101",
"name": "Neopian Times Zafara Handkerchief",
},
Object {
"id": "61100",
"name": "Neopian Times Zafara Hat",
},
Object {
"id": "61102",
"name": "Neopian Times Zafara Shirt and Vest",
},
Object {
"id": "61104",
"name": "Neopian Times Zafara Shoes",
},
Object {
"id": "61103",
"name": "Neopian Times Zafara Trousers",
},
],
"query": "Neopian Times",
},
}
`;
exports[`ItemSearch loads Neopian Times items that fit the Starry Zafara 5`] = `
Object {
"itemSearchToFit": Object {
"items": Array [
Object {
"id": "40431",
"name": "Neopian Times Background",
},
Object {
"id": "51098",
"name": "Neopian Times Writing Quill",
},
Object {
"id": "61101",
"name": "Neopian Times Zafara Handkerchief",
},
Object {
"id": "61100",
"name": "Neopian Times Zafara Hat",
},
Object {
"id": "61102",
"name": "Neopian Times Zafara Shirt and Vest",
},
Object {
"id": "61104",
"name": "Neopian Times Zafara Shoes",
},
Object {
"id": "61103",
"name": "Neopian Times Zafara Trousers",
},
],
"query": "Neopian Times",
},
}
`;
exports[`ItemSearch loads the first 10 hats that fit the Starry Zafara 1`] = `
Object {
"itemSearchToFit": Object {
"items": Array [
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "395669",
},
],
},
"id": "74967",
"name": "17th Birthday Party Hat",
},
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "79262",
},
],
},
"id": "49026",
"name": "Abominable Snowman Hat",
},
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "248670",
},
Object {
"id": "248671",
},
],
},
"id": "67242",
"name": "Accessories Shop Wig and Hat",
},
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "207062",
},
],
},
"id": "64177",
"name": "Acorn Hat",
},
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "293566",
},
Object {
"id": "293567",
},
],
},
"id": "69995",
"name": "Adventure in Pastel Hat and Wig",
},
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "186927",
},
],
},
"id": "62375",
"name": "Altador Cup Trophy Hat",
},
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "392019",
},
],
},
"id": "56654",
"name": "Altador Team Hat",
},
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "201066",
},
],
},
"id": "62322",
"name": "Altador Team Jester Hat",
},
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "144021",
},
],
},
"id": "58733",
"name": "Apple Bobbing Bart Hat",
},
Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "495043",
},
Object {
"id": "495044",
},
],
},
"id": "80401",
"name": "Aurricks Finest Hat",
},
],
"query": "hat",
},
}
`;
exports[`ItemSearch loads the next 10 hats that fit the Starry Zafara 1`] = `
Object {
"itemSearchToFit": Object {
"items": Array [
Object {
"id": "50168",
"name": "Babaa Hat",
},
Object {
"id": "78311",
"name": "Backwards Hat and Wig",
},
Object {
"id": "66653",
"name": "Bagel Hat Wig",
},
Object {
"id": "51366",
"name": "Balloon Sculpture Hat",
},
Object {
"id": "66236",
"name": "Banker Hat and Wig",
},
Object {
"id": "52733",
"name": "Battlefield Legends Hat",
},
Object {
"id": "57617",
"name": "Big Black Lace Pirate Hat",
},
Object {
"id": "44451",
"name": "Big Fuzzy Hat",
},
Object {
"id": "58318",
"name": "Bigsby Shadingtons Hat",
},
Object {
"id": "39883",
"name": "Bird Nest Hat",
},
],
"query": "hat",
},
}
`;

View file

@ -1,70 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Outfit loads an outfit by ID 1`] = `
Object {
"outfit": Object {
"closetedItems": Array [
Object {
"id": "36125",
"name": "Blue Newsboy Hat",
},
Object {
"id": "36467",
"name": "Daring Adventurer Hat",
},
Object {
"id": "47075",
"name": "Jordies Adventure Hat",
},
Object {
"id": "47056",
"name": "Moltara Inventor Hat and Goggles",
},
Object {
"id": "39662",
"name": "Simple Sun Hat",
},
Object {
"id": "56706",
"name": "Super Sleuth Hat and Wig",
},
Object {
"id": "38915",
"name": "Zafara Tourist Shirt",
},
Object {
"id": "56398",
"name": "Altador Cup Kreludor Frame",
},
],
"id": "31856",
"name": "Zafara Tourist",
"petAppearance": Object {
"color": Object {
"id": "34",
"name": "Green",
},
"id": "3951",
"pose": "UNKNOWN",
"species": Object {
"id": "54",
"name": "Zafara",
},
},
"wornItems": Array [
Object {
"id": "38916",
"name": "Zafara Tourist Camera",
},
Object {
"id": "51054",
"name": "Summer Fun Beach Background",
},
Object {
"id": "38914",
"name": "Zafara Tourist Hat",
},
],
},
}
`;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,283 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Species loads all species 1`] = `
Object {
"allSpecies": Array [
Object {
"id": "1",
"name": "Acara",
"standardBodyId": "93",
},
Object {
"id": "2",
"name": "Aisha",
"standardBodyId": "106",
},
Object {
"id": "3",
"name": "Blumaroo",
"standardBodyId": "47",
},
Object {
"id": "4",
"name": "Bori",
"standardBodyId": "84",
},
Object {
"id": "5",
"name": "Bruce",
"standardBodyId": "146",
},
Object {
"id": "6",
"name": "Buzz",
"standardBodyId": "250",
},
Object {
"id": "7",
"name": "Chia",
"standardBodyId": "212",
},
Object {
"id": "8",
"name": "Chomby",
"standardBodyId": "74",
},
Object {
"id": "9",
"name": "Cybunny",
"standardBodyId": "94",
},
Object {
"id": "10",
"name": "Draik",
"standardBodyId": "132",
},
Object {
"id": "11",
"name": "Elephante",
"standardBodyId": "56",
},
Object {
"id": "12",
"name": "Eyrie",
"standardBodyId": "90",
},
Object {
"id": "13",
"name": "Flotsam",
"standardBodyId": "136",
},
Object {
"id": "14",
"name": "Gelert",
"standardBodyId": "138",
},
Object {
"id": "15",
"name": "Gnorbu",
"standardBodyId": "166",
},
Object {
"id": "16",
"name": "Grarrl",
"standardBodyId": "119",
},
Object {
"id": "17",
"name": "Grundo",
"standardBodyId": "126",
},
Object {
"id": "18",
"name": "Hissi",
"standardBodyId": "67",
},
Object {
"id": "19",
"name": "Ixi",
"standardBodyId": "163",
},
Object {
"id": "20",
"name": "Jetsam",
"standardBodyId": "147",
},
Object {
"id": "21",
"name": "Jubjub",
"standardBodyId": "80",
},
Object {
"id": "22",
"name": "Kacheek",
"standardBodyId": "117",
},
Object {
"id": "23",
"name": "Kau",
"standardBodyId": "201",
},
Object {
"id": "24",
"name": "Kiko",
"standardBodyId": "51",
},
Object {
"id": "25",
"name": "Koi",
"standardBodyId": "208",
},
Object {
"id": "26",
"name": "Korbat",
"standardBodyId": "196",
},
Object {
"id": "27",
"name": "Kougra",
"standardBodyId": "143",
},
Object {
"id": "28",
"name": "Krawk",
"standardBodyId": "150",
},
Object {
"id": "29",
"name": "Kyrii",
"standardBodyId": "175",
},
Object {
"id": "30",
"name": "Lenny",
"standardBodyId": "173",
},
Object {
"id": "31",
"name": "Lupe",
"standardBodyId": "199",
},
Object {
"id": "32",
"name": "Lutari",
"standardBodyId": "52",
},
Object {
"id": "33",
"name": "Meerca",
"standardBodyId": "109",
},
Object {
"id": "34",
"name": "Moehog",
"standardBodyId": "134",
},
Object {
"id": "35",
"name": "Mynci",
"standardBodyId": "95",
},
Object {
"id": "36",
"name": "Nimmo",
"standardBodyId": "96",
},
Object {
"id": "37",
"name": "Ogrin",
"standardBodyId": "154",
},
Object {
"id": "38",
"name": "Peophin",
"standardBodyId": "55",
},
Object {
"id": "39",
"name": "Poogle",
"standardBodyId": "76",
},
Object {
"id": "40",
"name": "Pteri",
"standardBodyId": "156",
},
Object {
"id": "41",
"name": "Quiggle",
"standardBodyId": "78",
},
Object {
"id": "42",
"name": "Ruki",
"standardBodyId": "191",
},
Object {
"id": "43",
"name": "Scorchio",
"standardBodyId": "187",
},
Object {
"id": "44",
"name": "Shoyru",
"standardBodyId": "46",
},
Object {
"id": "45",
"name": "Skeith",
"standardBodyId": "178",
},
Object {
"id": "46",
"name": "Techo",
"standardBodyId": "100",
},
Object {
"id": "47",
"name": "Tonu",
"standardBodyId": "130",
},
Object {
"id": "48",
"name": "Tuskaninny",
"standardBodyId": "188",
},
Object {
"id": "49",
"name": "Uni",
"standardBodyId": "257",
},
Object {
"id": "50",
"name": "Usul",
"standardBodyId": "206",
},
Object {
"id": "51",
"name": "Wocky",
"standardBodyId": "101",
},
Object {
"id": "52",
"name": "Xweetok",
"standardBodyId": "68",
},
Object {
"id": "53",
"name": "Yurble",
"standardBodyId": "182",
},
Object {
"id": "54",
"name": "Zafara",
"standardBodyId": "180",
},
Object {
"id": "55",
"name": "Vandagyre",
"standardBodyId": "306",
},
],
}
`;

View file

@ -1,207 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`User gets public and private closet lists for current user: data 1`] = `
Object {
"user": Object {
"closetLists": Array [
Object {
"id": "184791",
"isDefaultList": false,
"items": Array [
Object {
"id": "39948",
"name": "Altador Cup Background - Lost Desert",
},
],
"name": "A Private Own List",
"ownsOrWantsItems": "OWNS",
},
Object {
"id": "184793",
"isDefaultList": false,
"items": Array [
Object {
"id": "39945",
"name": "Altador Cup Background - Haunted Woods",
},
],
"name": "A Private Want List",
"ownsOrWantsItems": "WANTS",
},
Object {
"id": "184790",
"isDefaultList": false,
"items": Array [
Object {
"id": "39955",
"name": "Altador Cup Background - Virtupets",
},
],
"name": "A Public Own List",
"ownsOrWantsItems": "OWNS",
},
Object {
"id": "184792",
"isDefaultList": false,
"items": Array [
Object {
"id": "39947",
"name": "Altador Cup Background - Shenkuu",
},
],
"name": "A Public Want List",
"ownsOrWantsItems": "WANTS",
},
Object {
"id": "user-44743-default-list-OWNS",
"isDefaultList": true,
"items": Array [
Object {
"id": "74967",
"name": "17th Birthday Party Hat",
},
Object {
"id": "49026",
"name": "Abominable Snowman Hat",
},
Object {
"id": "40319",
"name": "Blue Jelly Tiara",
},
],
"name": "Not in a list",
"ownsOrWantsItems": "OWNS",
},
Object {
"id": "user-44743-default-list-WANTS",
"isDefaultList": true,
"items": Array [
Object {
"id": "39956",
"name": "Altador Cup Background - Kreludor",
},
],
"name": "Not in a list",
"ownsOrWantsItems": "WANTS",
},
],
"id": "44743",
"username": "dti-test",
},
}
`;
exports[`User gets public and private closet lists for current user: db 1`] = `
Array [
Array [
"SELECT * FROM users WHERE id IN (?)",
Array [
"44743",
],
],
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",
],
],
Array [
"SELECT * FROM closet_lists
WHERE user_id IN (?)
ORDER BY name",
Array [
"44743",
],
],
Array [
"SELECT * FROM item_translations WHERE item_id IN (?,?,?,?,?,?,?,?) AND locale = \\"en\\"",
Array [
"39948",
"39945",
"39955",
"39947",
"74967",
"49026",
"40319",
"39956",
],
],
]
`;
exports[`User gets public closet lists, but not private, for other users: data 1`] = `
Object {
"user": Object {
"closetLists": Array [
Object {
"id": "184790",
"isDefaultList": false,
"items": Array [
Object {
"id": "39955",
"name": "Altador Cup Background - Virtupets",
},
],
"name": "A Public Own List",
"ownsOrWantsItems": "OWNS",
},
Object {
"id": "184792",
"isDefaultList": false,
"items": Array [
Object {
"id": "39947",
"name": "Altador Cup Background - Shenkuu",
},
],
"name": "A Public Want List",
"ownsOrWantsItems": "WANTS",
},
],
"id": "44743",
"username": "dti-test",
},
}
`;
exports[`User gets public closet lists, but not private, for other users: db 1`] = `
Array [
Array [
"SELECT * FROM users WHERE id IN (?)",
Array [
"44743",
],
],
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",
],
],
Array [
"SELECT * FROM closet_lists
WHERE user_id IN (?)
ORDER BY name",
Array [
"44743",
],
],
Array [
"SELECT * FROM item_translations WHERE item_id IN (?,?) AND locale = \\"en\\"",
Array [
"39955",
"39947",
],
],
]
`;

View file

@ -1,201 +0,0 @@
import fs from "fs";
import path from "path";
import { ApolloServer } from "apollo-server";
import { createTestClient } from "apollo-server-testing";
import { AuthenticationClient } from "auth0";
import auth from "../auth";
const actualAuth = jest.requireActual("../auth");
import connectToDb from "../db";
const actualConnectToDb = jest.requireActual("../db");
import { config } from "../index";
let accessTokenForQueries = null;
const { query, mutate } = createTestClient(
new ApolloServer({
...config,
context: () =>
config.context({
req: {
headers: {
authorization: accessTokenForQueries
? `Bearer ${accessTokenForQueries}`
: undefined,
},
},
}),
})
);
// 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 dbExecuteFn;
let db;
let dbEnvironment = "production";
let dbSetupDone = false;
const dbSetupScripts = [
fs
.readFileSync(
path.join(__dirname, "../../../scripts/setup-mysql-dev-constants.sql")
)
.toString(),
fs
.readFileSync(
path.join(__dirname, "../../../scripts/setup-mysql-dev-schema.sql")
)
.toString(),
];
beforeAll(() => {
connectToDb.mockImplementation(async () => {
let options;
if (dbEnvironment === "test") {
options = {
host: "localhost",
user: "impress_2020_test",
password: "impress_2020_test",
database: "impress_2020_test",
};
}
db = await actualConnectToDb(options);
if (dbEnvironment === "test" && !dbSetupDone) {
for (const script of dbSetupScripts) {
await db.query(script);
}
}
dbSetupDone = true;
dbExecuteFn = jest.spyOn(db, "execute");
return db;
});
// Mock out a current "now" date, for consistent snapshots
const ActualDate = Date;
const NOW = new ActualDate("2020-01-01T00:00:00.000Z");
jest.spyOn(global, "Date").mockImplementation(() => NOW);
Date.now = () => NOW.getTime();
});
beforeEach(() => {
// Restore auth values to default state.
accessTokenForQueries = null;
auth.getUserIdFromToken.mockImplementation(actualAuth.getUserIdFromToken);
// Restore db values to default state.
if (dbExecuteFn) {
dbExecuteFn.mockClear();
}
dbEnvironment = "production";
dbSetupDone = false;
db = null;
});
afterAll(() => {
if (db) {
db.end();
}
Date.mockRestore();
});
const getDbCalls = () => (dbExecuteFn ? dbExecuteFn.mock.calls : []);
const clearDbCalls = () => dbExecuteFn?.mockClear();
function useTestDb() {
if (db) {
throw new Error(`can't call useTestDb() if db mock already exists`);
}
dbEnvironment = "test";
}
jest.mock("../auth");
async function logInAsTestUser() {
if (dbEnvironment === "production") {
const auth0 = new AuthenticationClient({
domain: "openneo.us.auth0.com",
clientId: process.env.AUTH0_TEST_CLIENT_ID,
clientSecret: process.env.AUTH0_TEST_CLIENT_SECRET,
});
const res = await auth0.passwordGrant({
username: "dti-test",
password: process.env.DTI_TEST_USER_PASSWORD,
audience: "https://impress-2020.openneo.net/api",
});
accessTokenForQueries = res.access_token;
} else if (dbEnvironment === "test") {
// Create a test user record. Most of these values don't matter.
const db = await connectToDb();
await db.query(
`INSERT INTO users (id, name, auth_server_id, remote_id)
VALUES (1, "test-user-1", 1, 1)`
);
// Mock the server's auth code to return user ID 1.
auth.getUserIdFromToken.mockImplementation(async () => "1");
accessTokenForQueries = "mock-access-token-test-user-1";
} else {
throw new Error(`unexpected dbEnvironment ${dbEnvironment}`);
}
}
async function createItem(id) {
if (dbEnvironment !== "test") {
throw new Error(`Please only use createItem in test db!`);
}
const name = `Test Item ${id}`;
const db = await connectToDb();
await Promise.all([
db.query(
`INSERT INTO items (id, zones_restrict, thumbnail_url, category,
type, rarity_index, price, weight_lbs)
VALUES (?, "00000000000000000000000000000000000000000000000",
"http://example.com/favicon.ico", "Clothes", "Clothes", 101,
0, 1);
`,
[id]
),
db.query(
`INSERT INTO item_translations (item_id, locale, name, description,
rarity)
VALUES (?, "en", ?, "This is a test item.", "Special")
`,
[id, name]
),
]);
}
// Add a new `expect(res).toHaveNoErrors()` to call after GraphQL calls!
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,
};
}
},
});
// Use the new modeling code, even though it's disabled in most environments,
// in order to test it.
process.env["USE_NEW_MODELING"] = "1";
module.exports = {
query,
mutate,
getDbCalls,
clearDbCalls,
connectToDb,
useTestDb,
logInAsTestUser,
createItem,
};