Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Revadike committed Oct 14, 2021
1 parent 3b2abd6 commit b904b06
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"eslint.format.enable": true,
"editor.formatOnSave": true,
"files.eol": "\n",
"eslint.alwaysShowStatus": true,
"prettier.requireConfig": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
}
}
11 changes: 6 additions & 5 deletions src/gamePromotions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ async function getAddonForSlug(client, slug) {

async function getOfferId(client, promo, locale = "en-US") {
let offerId = null;
let slug = promo.productSlug || promo.urlSlug;
let isBundle = (promo) => Boolean(promo.categories.find((cat) => cat.path === "bundles"));
let isAddon = (promo) => Boolean(promo.categories.find((cat) => cat.path === "addons"));

if (isAddon(promo)) {
let result = await getAddonForSlug(client, promo.urlSlug.split("/")[0], locale);
let result = await getAddonForSlug(client, slug.split("/")[0], locale);
// eslint-disable-next-line prefer-destructuring
offerId = result.data.StorePageMapping.mapping.mappings.offerId;
} else if (isBundle(promo)) {
let result = await client.getBundleForSlug(promo.urlSlug.split("/")[0], locale);
let page = result.pages.find((p) => p.offer.id === promo.id) || result.pages[0];
let result = await client.getBundleForSlug(slug.split("/")[0], locale);
let page = result.pages ? result.pages.find((p) => p.offer.id === promo.id) || result.pages[0] : result;
offerId = page.offer.id;
} else {
let result = await client.getProductForSlug(promo.urlSlug.split("/")[0], locale);
let page = result.pages.find((p) => p.offer.id === promo.id) || result.pages[0];
let result = await client.getProductForSlug(slug.split("/")[0], locale);
let page = result.pages ? result.pages.find((p) => p.offer.id === promo.id) || result.pages[0] : result;
offerId = page.offer.id;
}

Expand Down
5 changes: 3 additions & 2 deletions test/gamePromotions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"use strict";

const { readFileSync } = require("fs");
const { resolve } = require("path");
const gamePromotions = require("../src/gamePromotions.js");
const { expect } = require("chai");

Expand All @@ -10,7 +11,7 @@ function readData(name, date = null) {
if (date) {
filename += `_${date}`;
}
return JSON.parse(readFileSync(`${__dirname}/data/${filename}.json`).toString());
return JSON.parse(readFileSync(resolve(__dirname, "data", `${filename}.json`)).toString());
}

let client = {};
Expand Down Expand Up @@ -40,7 +41,7 @@ describe("freeGamesPromotions", () => {
});

expect(freeGames).to.deep.include({
"title": "Hitman 2016",
"title": "HITMAN",
"id": "e8efad3d47a14284867fef2c347c321d",
"namespace": "3c06b15a8a2845c0b725d4f952fe00aa",
});
Expand Down

0 comments on commit b904b06

Please sign in to comment.