Skip to content

Commit

Permalink
refactor: change default empty release date to null (#229)
Browse files Browse the repository at this point in the history
refactor: change default empty release date to null 

# changed using empty string to null in cases of missing or invalid release dates (game data model)
# adjusted mocks to reflect this change
# added the last night unreleased html page mock
# added null check on games repo getGamesWithoutReleaseDates method
# slightly improved some test descriptions
# removed some unnecessary tests

Previously, an empty string was used in the cases of invalid or unavailable dates. That has been replaced with "null" instead. Also replaced in other appropriate places (like games repository call getting missing dates is now checking for "null" instead of empty string).

Issue-ref: #228
  • Loading branch information
lukatarman authored May 28, 2024
1 parent c7dc4d6 commit c773c2a
Show file tree
Hide file tree
Showing 7 changed files with 1,917 additions and 76 deletions.

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions backend/src/core/models/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export class Game {
#extractReleaseDateViaSteamWeb(page) {
const releaseDateElement = page.querySelector(".release_date .date");

if (!releaseDateElement) return "";
if (!releaseDateElement) return null;

const releaseDate = new Date(`${releaseDateElement.textContent.trim()} UTC`);

return releaseDate == "Invalid Date" ? "" : releaseDate;
return releaseDate == "Invalid Date" ? null : releaseDate;
}

#extractDevelopersViaSteamWeb(page) {
Expand Down Expand Up @@ -94,11 +94,11 @@ export class Game {
}

#extractReleaseDateViaSteamApi(steamApiApp) {
if (!steamApiApp.releaseDate) return "";
if (!steamApiApp.releaseDate) return null;

const releaseDate = new Date(`${steamApiApp.releaseDate} UTC`);

return releaseDate == "Invalid Date" ? "" : releaseDate;
return releaseDate == "Invalid Date" ? null : releaseDate;
}

#extractDevelopersViaSteamApi(steamApiApp) {
Expand Down Expand Up @@ -172,7 +172,7 @@ export class Game {

const date = this.#extractReleaseDateViaSteamApi(steamApiApp);

if (date === "") return;
if (date === null) return;

this.releaseDate = date;
}
Expand Down
8 changes: 4 additions & 4 deletions backend/src/core/models/game.mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export const getGamesDatasetMock = () => {
{
id: 2218750,
name: "Halls of Torment",
releaseDate: "",
releaseDate: null,
developers: ["Chasing Carrots"],
image: null,
imageUrl: "https://cdn.akamai.steamstatic.com/steam/apps/2218750/header.jpg",
Expand All @@ -327,7 +327,7 @@ export const getGamesDatasetMock = () => {
{
id: 239140,
name: "Dying Light",
releaseDate: "",
releaseDate: null,
developers: ["Sample Dev"],
image: null,
imageUrl: "https://cdn.akamai.steamstatic.com/steam/apps/239140/header.jpg",
Expand Down Expand Up @@ -565,7 +565,7 @@ export const getGamesDatasetMock = () => {
{
id: 620,
name: "Portal 2",
releaseDate: "",
releaseDate: null,
developers: ["Valve"],
image: null,
imageUrl: "https://cdn.akamai.steamstatic.com/steam/apps/620/header.jpg",
Expand All @@ -591,7 +591,7 @@ export const getGamesDatasetMock = () => {
{
id: 646910,
name: "The Crew 2",
releaseDate: "",
releaseDate: null,
developers: [],
image: null,
imageUrl: "https://cdn.akamai.steamstatic.com/steam/apps/646910/header.jpg",
Expand Down
76 changes: 14 additions & 62 deletions backend/src/core/models/game.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { eldenRingSteamApiData } from "../../../assets/steam-api-responses/elden
import { theLastNightSteamApiData } from "../../../assets/steam-api-responses/the.last.night.unreleased.js";
import { crusaderKingsDetailsPage } from "../../../assets/steam-web-html-details-pages/crusader.kings.multiple.developers.html.details.page.js";
import { eldenRingGameHtmlDetailsPage } from "../../../assets/steam-web-html-details-pages/elden.ring.game.html.details.page.js";
import { mortalDarknessGameHtmlDetailsPage } from "../../../assets/steam-web-html-details-pages/mortal.darkness.game.html.details.page.js";
import { riskOfRainHtmlDetailsPageMissingInfo } from "../../../assets/steam-web-html-details-pages/risk.of.rain.missing.additional.info.page.js";
import { theLastNightUnreleasedHtmlDetailsPage } from "../../../assets/steam-web-html-details-pages/the.last.night.unreleased.html.details.page.js";
import { Game } from "./game.js";
import { getEldenRingGameWithDetails, getXGamesWithoutDetails } from "./game.mocks.js";
import { PlayerHistory } from "./player.history.js";
Expand Down Expand Up @@ -57,15 +57,15 @@ describe("Game", function () {
expect(this.result).toBeInstanceOf(Game);
});

it("the game's release date will be an empty string", function () {
expect(this.result.releaseDate).toBe("");
it("the game's release date will be null", function () {
expect(this.result.releaseDate).toBe(null);
});
});

describe("if the provided HTML page includes a release date,", function () {
describe("if the provided HTML page includes an invalid date,", function () {
beforeAll(function () {
const steamApp = getXSampleSteamApps(1)[0];
const page = getParsedHtmlPage(mortalDarknessGameHtmlDetailsPage);
const page = getParsedHtmlPage(theLastNightUnreleasedHtmlDetailsPage);

this.result = Game.fromSteamApp(steamApp, page);
});
Expand All @@ -74,8 +74,8 @@ describe("Game", function () {
expect(this.result).toBeInstanceOf(Game);
});

it("the game's release date is set to the correct date'", function () {
expect(this.result.releaseDate.toISOString()).toEqual("2023-08-01T00:00:00.000Z");
it("the game's release date is set to null'", function () {
expect(this.result.releaseDate).toBe(null);
});
});

Expand Down Expand Up @@ -133,23 +133,6 @@ describe("Game", function () {
});
});

describe("if the provided HTML page includes genres,", function () {
beforeAll(function () {
const steamApp = getXSampleSteamApps(1)[0];
const page = getParsedHtmlPage(mortalDarknessGameHtmlDetailsPage);

this.result = Game.fromSteamApp(steamApp, page);
});

it("the result is an instance of game", function () {
expect(this.result).toBeInstanceOf(Game);
});

it("the game's genres get updated with the correct values", function () {
expect(this.result.genres).toEqual(["Action", "Adventure", "Indie", "RPG"]);
});
});

describe("if the provided HTML page does not include a game description,", function () {
beforeAll(function () {
const steamApp = getXSampleSteamApps(1)[0];
Expand All @@ -166,25 +149,6 @@ describe("Game", function () {
expect(this.result.description).toEqual("");
});
});

describe("if the provided HTML page includes a description,", function () {
beforeAll(function () {
const steamApp = getXSampleSteamApps(1)[0];
const page = getParsedHtmlPage(mortalDarknessGameHtmlDetailsPage);

this.result = Game.fromSteamApp(steamApp, page);
});

it("the result is an instance of game", function () {
expect(this.result).toBeInstanceOf(Game);
});

it("the game's description is updated with the correct value", function () {
expect(this.result.description).toBe(
"“One grim dawn and noble I wake, The darkness is rampant, our oath shall break. A noble warrior soon shall rise, and clear the air of the darkened skies.”",
);
});
});
});

describe(".fromSteamApi", function () {
Expand Down Expand Up @@ -219,19 +183,19 @@ describe("Game", function () {
this.result = Game.fromSteamApi(theLastNightSteamApiData);
});

it("the game's release date will be an empty string", function () {
expect(this.result.releaseDate).toBe("");
it("the game's release date will be null", function () {
expect(this.result.releaseDate).toBe(null);
});
});
});

describe("if the provided steam api app doesn't include a release date", function () {
describe("if the provided steam api app doesn't include a valid release date", function () {
beforeAll(function () {
this.result = Game.fromSteamApi(getXSampleRawSteamApiApps(1)[0]);
});

it("the game's release date will be set to an empty string", function () {
expect(this.result.releaseDate).toBe("");
it("the game's release date will be set to null", function () {
expect(this.result.releaseDate).toBe(null);
});
});

Expand Down Expand Up @@ -446,19 +410,7 @@ describe("Game", function () {
this.result.pushSteamchartsPlayerHistory(gameHistories);
});

it("The result is an instance of Game", function () {
expect(this.result).toBeInstanceOf(Game);
});

it("The result has a property release date, which equals an empty string", function () {
expect(this.result.releaseDate).toBe("");
});

it("The result has a property developers, which equals an empty array", function () {
expect(this.result.developers).toEqual([]);
});

it("The game has three new player history entries", function () {
it("The game has four player history entries", function () {
expect(this.result.playerHistory.length).toBe(4);
});

Expand Down Expand Up @@ -504,7 +456,7 @@ describe("Game", function () {
});

it("the release date stays unchanged", function () {
expect(this.game.releaseDate).toBe("");
expect(this.game.releaseDate).toBe(null);
});
});

Expand Down
4 changes: 2 additions & 2 deletions backend/src/core/models/games.aggregate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("GamesAggregate", function () {
});

describe(".extractReleaseDatesViaSteamApi.", function () {
describe("When we try to update two games with missing release dates, one of them missing a release date", function () {
describe("When we try to update two games with missing release dates, one of them having in invalid date", function () {
beforeAll(function () {
const gameIds = [1245620, 612400];

Expand All @@ -86,7 +86,7 @@ describe("GamesAggregate", function () {
});

it("the second game's release date remains unchanged", function () {
expect(this.gamesArray.content[1].releaseDate).toEqual("");
expect(this.gamesArray.content[1].releaseDate).toEqual(null);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion backend/src/core/repositories/games.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class GamesRepository {
.aggregate([
{
$match: {
$or: [{ releaseDate: { $eq: "" } }, { releaseDate: { $gt: new Date() } }],
$or: [{ releaseDate: { $eq: null } }, { releaseDate: { $gt: new Date() } }],
},
},
{ $limit: amount },
Expand Down
4 changes: 2 additions & 2 deletions backend/src/core/repositories/games.repository.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ describe("GamesRepository", function () {

it("the second game is missing the release date", function () {
expect(this.result.content[1].id).toBe(2218750);
expect(this.result.content[1].releaseDate).toBe("");
expect(this.result.content[1].releaseDate).toBe(null);
});

it("the third game is missing the release date", function () {
expect(this.result.content[2].id).toBe(239140);
expect(this.result.content[2].releaseDate).toBe("");
expect(this.result.content[2].releaseDate).toBe(null);
});
});
});
Expand Down

0 comments on commit c773c2a

Please sign in to comment.