From fb8ccee797321f05e0b39214df437cc1cbbfe110 Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Wed, 27 May 2020 00:46:55 -0700 Subject: [PATCH] skip non-SWF (music) assets --- src/server/index.js | 10 ++- src/server/query-tests/Item.test.js | 68 +++++++++++++++++++ .../__snapshots__/Item.test.js.snap | 18 +++++ 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/src/server/index.js b/src/server/index.js index 7d1d530..36833eb 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -171,15 +171,19 @@ const resolvers = { speciesId: speciesId, colorId: colorId, }); - const swfAssets = await itemSwfAssetLoader.load({ + const allSwfAssets = await itemSwfAssetLoader.load({ itemId: item.id, bodyId: petType.bodyId, }); - - if (swfAssets.length === 0) { + if (allSwfAssets.length === 0) { + // If there's no assets at all, treat it as non-fitting: no appearance. + // (If there are assets but they're non-SWF, we'll treat this as + // fitting, but with an *empty* appearance.) return null; } + const swfAssets = allSwfAssets.filter((sa) => sa.url.endsWith(".swf")); + const restrictedZones = []; for (const [i, bit] of Array.from(item.zonesRestrict).entries()) { if (bit === "1") { diff --git a/src/server/query-tests/Item.test.js b/src/server/query-tests/Item.test.js index 7e48c98..fdcb6db 100644 --- a/src/server/query-tests/Item.test.js +++ b/src/server/query-tests/Item.test.js @@ -52,6 +52,7 @@ describe("Item", () => { layers { id imageUrl(size: SIZE_600) + svgUrl zone { id depth @@ -133,4 +134,71 @@ describe("Item", () => { ] `); }); + + 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 [ + "SELECT * FROM items WHERE id IN (?)", + Array [ + "42829", + ], + ], + Array [ + "SELECT * FROM item_translations WHERE item_id IN (?) AND locale = \\"en\\"", + 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", + ], + ], + ] + `); + }); }); diff --git a/src/server/query-tests/__snapshots__/Item.test.js.snap b/src/server/query-tests/__snapshots__/Item.test.js.snap index afa7503..e92e633 100644 --- a/src/server/query-tests/__snapshots__/Item.test.js.snap +++ b/src/server/query-tests/__snapshots__/Item.test.js.snap @@ -9,6 +9,7 @@ Object { Object { "id": "37128", "imageUrl": "https://impress-asset-images.s3.amazonaws.com/object/000/000/014/14856/600x600.png?v2-1587653266000", + "svgUrl": null, "zone": Object { "depth": 30, "id": "26", @@ -34,6 +35,7 @@ Object { Object { "id": "37129", "imageUrl": "https://impress-asset-images.s3.amazonaws.com/object/000/000/014/14857/600x600.png?v2-0", + "svgUrl": null, "zone": Object { "depth": 44, "id": "40", @@ -59,6 +61,7 @@ Object { Object { "id": "30203", "imageUrl": "https://impress-asset-images.s3.amazonaws.com/object/000/000/006/6829/600x600.png?v2-0", + "svgUrl": null, "zone": Object { "depth": 3, "id": "3", @@ -99,3 +102,18 @@ Object { ], } `; + +exports[`Item skips appearance data for audio assets 1`] = ` +Object { + "items": Array [ + Object { + "appearanceOn": Object { + "layers": Array [], + "restrictedZones": Array [], + }, + "id": "42829", + "name": "Time Tunnel Music Track", + }, + ], +} +`;