Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukatarman committed Dec 6, 2023
1 parent 5e33d8d commit ec1fb69
Showing 1 changed file with 22 additions and 55 deletions.
77 changes: 22 additions & 55 deletions backend/src/features/game-identifier/game.identifier.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ describe("game.identifier.js", function () {
describe(".tryViaSteamWeb", function () {
describe("gets zero steamApps from the database and stops. So,", function () {
beforeAll(async function () {
this.options = {
batchSize: 1,
unitDelay: 0,
};

this.steamClientMock = createSteamMock([undefined]);

this.steamAppsRepository = createSteamAppsRepositoryMock([], undefined);
Expand Down Expand Up @@ -82,7 +77,7 @@ describe("game.identifier.js", function () {

describe("gets one game out of a batch of one steamApp, and inserts it into the database. So,", function () {
beforeAll(async function () {
this.app = [{ appid: 1, name: "Animaddicts" }];
this.app = getXSampleSteamApps(1);

this.games = discoverGamesFromSteamWeb(this.app, [
animaddicts2gameHtmlDetailsPage,
Expand Down Expand Up @@ -196,15 +191,7 @@ describe("game.identifier.js", function () {

describe("gets one game out of a batch of two steamApps, and inserts it into the database. So,", function () {
beforeAll(async function () {
this.options = {
batchSize: 2,
unitDelay: 0,
};

this.apps = [
{ appid: 1, name: "Animaddicts" },
{ appid: 2, name: "Glitchhikers Soundtrack" },
];
this.apps = getXSampleSteamApps(2);

this.htmlDetailsPages = [
animaddicts2gameHtmlDetailsPage,
Expand Down Expand Up @@ -519,10 +506,7 @@ describe("game.identifier.js", function () {

describe("gets one game from a batch of two steamApps from the database and inserts them into the database. So,", function () {
beforeAll(async function () {
this.apps = [
{ appid: 1, name: "Elden Ring" },
{ appid: 2, name: "Swords and Soldiers Beta" },
];
this.apps = getXSampleSteamApps(2);

this.htmlDetailsPages = [
eldenRingHttpDetailsSteamcharts,
Expand Down Expand Up @@ -645,11 +629,7 @@ describe("game.identifier.js", function () {

describe("gets two games from a batch of three steamApps from the database and inserts them into the database. So,", function () {
beforeAll(async function () {
this.apps = [
{ appid: 1, name: "Elden Ring" },
{ appid: 2, name: "Swords and Soldiers Beta" },
{ appid: 3, name: "Mortal Darkness" },
];
this.apps = getXSampleSteamApps(3);

this.htmlDetailsPages = [
eldenRingHttpDetailsSteamcharts,
Expand Down Expand Up @@ -895,30 +875,22 @@ describe("game.identifier.js", function () {
describe("Finds four games with missing properties,", function () {
describe("with the second and third games' pages experiencing an error", function () {
beforeAll(async function () {
this.options = {
batchSize: 4,
unitDelay: 0,
};

this.steamApps = getXSampleSteamApps(4);

this.failedSteamApps = getTwoFailedSteamApps(this.steamApps);

this.gamesRepoReturn = getXGamesWithoutDetails(4);

this.steamClientMock = createSteamMock([
const pagesArray = [
counterStrikeHtmlDetailsSteamDb,
"",
"",
riskOfRainHtmlDetailsSteamDb,
]);
];

const htmlPages = createHtmlDetailsPages([
counterStrikeHtmlDetailsSteamDb,
"",
"",
riskOfRainHtmlDetailsSteamDb,
]);
this.steamClientMock = createSteamMock(pagesArray);

const htmlPages = createHtmlDetailsPages(pagesArray);

updateMissingDetails(this.gamesRepoReturn, htmlPages);

Expand All @@ -936,7 +908,7 @@ describe("game.identifier.js", function () {
this.gamesRepository,
this.historyChecksRepository,
createLoggerMock(),
this.options,
createConfigMock(4).features,
);

await this.identifier.updateGamesWithoutDetails();
Expand All @@ -946,10 +918,8 @@ describe("game.identifier.js", function () {
expect(this.gamesRepository.getGamesWithoutDetails).toHaveBeenCalledTimes(1);
});

it("getGamesWithoutDetails was called with 'this.options.batchSize'", function () {
expect(this.gamesRepository.getGamesWithoutDetails).toHaveBeenCalledWith(
this.options.batchSize,
);
it("getGamesWithoutDetails was called with the correct batch size", function () {
expect(this.gamesRepository.getGamesWithoutDetails).toHaveBeenCalledWith(4);
});

it("getGamesWithoutDetails was called before getSteamAppsById", function () {
Expand Down Expand Up @@ -1019,7 +989,7 @@ describe("game.identifier.js", function () {
expect(this.gamesRepository.updateGameDetails).toHaveBeenCalledTimes(1);
});

it("updateGameDetails was called with the correct arguments", function () {
it("updateGameDetails was called with the correct argument", function () {
expect(this.gamesRepository.updateGameDetails).toHaveBeenCalledWith(
this.gamesRepoReturn,
);
Expand Down Expand Up @@ -1052,12 +1022,12 @@ describe("game.identifier.js", function () {
expect(this.gamesRepository.getGamesWithoutReleaseDates).toHaveBeenCalledTimes(1);
});

it("getGamesWithoutDetails was called with the correct batch size", function () {
it("getGamesWithoutReleaseDates was called with the correct batch size", function () {
expect(this.gamesRepository.getGamesWithoutReleaseDates).toHaveBeenCalledWith(2);
});

it("getSteamAppsById was not called", function () {
expect(this.steamAppsRepository.getSteamAppsById).toHaveBeenCalledTimes(1);
expect(this.steamAppsRepository.getSteamAppsById).toHaveBeenCalledTimes(0);
});

it("getSteamDbHtmlDetailsPage was not called", function () {
Expand Down Expand Up @@ -1168,21 +1138,18 @@ describe("game.identifier.js", function () {

this.gamesRepoReturn = Game.manyFromDbEntry(getXGamesWithoutDetails(4));

this.steamClientMock = createSteamMock([
const pages = [
counterStrikeHtmlDetailsSteamDb,
"",
"",
riskOfRainHtmlDetailsSteamDb,
]);
];

this.failedSteamApps = getTwoFailedSteamApps(this.steamApps);
this.steamClientMock = createSteamMock(pages);

const htmlPages = [
{ page: counterStrikeHtmlDetailsSteamDb, id: 1 },
{ page: "", id: 2 },
{ page: "", id: 3 },
{ page: riskOfRainHtmlDetailsSteamDb, id: 4 },
];
const htmlPages = createHtmlDetailsPages(pages);

this.failedSteamApps = getTwoFailedSteamApps(this.steamApps);

updateMissingReleaseDates(this.gamesRepoReturn, htmlPages);

Expand All @@ -1200,7 +1167,7 @@ describe("game.identifier.js", function () {
this.gamesRepository,
this.historyChecksRepository,
createLoggerMock(),
createConfigMock(2).features,
createConfigMock(4).features,
);

await this.identifier.updateGamesWithoutReleaseDates();
Expand Down

0 comments on commit ec1fb69

Please sign in to comment.