From d9d572d444de537ebf98b317d2aa447279ba7aa2 Mon Sep 17 00:00:00 2001 From: Stephanie Freitag <stephanie.freitag@holi.team> Date: Fri, 18 Aug 2023 18:23:59 +0200 Subject: [PATCH] NOISSUE: adjust range for selection random pages --- app/betterplace.ts | 7 +++---- app/betterplace_test.ts | 18 +++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/betterplace.ts b/app/betterplace.ts index d65eb85..95bda6a 100644 --- a/app/betterplace.ts +++ b/app/betterplace.ts @@ -27,7 +27,7 @@ const PICTURE_TYPE_REGEX = /(.*)_(\d+)x(\d+)/; export const SUPPORTED_LANGUAGES = ["en", "de"]; export const DEFAULT_LANGUAGE: BetterPlaceLanguage = "en"; const DEFAULT_PAGE_SIZE = 10; -const MAX_PAGE_FOR_RANDOMIZATION = 1250; +const MAX_PAGE_FOR_RANDOMIZATION = 10; const cleanUpHtml = (html: string): string => { let result = ""; @@ -251,10 +251,9 @@ const fetchPageOfProjects = ( }); }; -// Do not select projects from too far back and not the first two pages +// Do not select projects from too far back const randomPageForToday = () => - (new Date().setUTCHours(0, 0, 0, 0) / 100000) % MAX_PAGE_FOR_RANDOMIZATION + - 2; + (new Date().setUTCHours(0, 0, 0, 0) / 100000) % MAX_PAGE_FOR_RANDOMIZATION; export const fetchProjects = ( { offset = 0, limit = DEFAULT_PAGE_SIZE, location }: ProjectsParameters, diff --git a/app/betterplace_test.ts b/app/betterplace_test.ts index 47d01d5..dcff85e 100644 --- a/app/betterplace_test.ts +++ b/app/betterplace_test.ts @@ -185,7 +185,7 @@ describe("betterplace", () => { let time: FakeTime; beforeEach(() => { - time = new FakeTime(new Date(2023, 8, 13, 12)); + time = new FakeTime(new Date(2023, 8, 12, 12)); }); afterEach(() => { @@ -248,7 +248,7 @@ describe("betterplace", () => { await fetchProjects({}, "de"); - assertSpyCall(fetchStub, 0, { args: [urlForPage(635)] }); + assertSpyCall(fetchStub, 0, { args: [urlForPage(9)] }); }); it("queries a different random page the next day", async () => { @@ -257,7 +257,7 @@ describe("betterplace", () => { await fetchProjects({}, "de"); - assertSpyCall(fetchStub, 0, { args: [urlForPage(249)] }); + assertSpyCall(fetchStub, 0, { args: [urlForPage(3)] }); }); it("resumes normal pagination after the first page", async () => { @@ -275,7 +275,7 @@ describe("betterplace", () => { await fetchProjects({ offset: 10 }, "de"); await fetchProjects({ offset: 20 }, "de"); - assertSpyCall(fetchStub, 0, { args: [urlForPage(635)] }); + assertSpyCall(fetchStub, 0, { args: [urlForPage(9)] }); assertSpyCall(fetchStub, 1, { args: [urlForPage(1)] }); assertSpyCall(fetchStub, 2, { args: [urlForPage(2)] }); }); @@ -292,12 +292,12 @@ describe("betterplace", () => { ); await fetchProjects({}, "de"); - await fetchProjects({ offset: 6340 }, "de"); - await fetchProjects({ offset: 6350 }, "de"); + await fetchProjects({ offset: 80 }, "de"); + await fetchProjects({ offset: 90 }, "de"); - assertSpyCall(fetchStub, 0, { args: [urlForPage(635)] }); - assertSpyCall(fetchStub, 1, { args: [urlForPage(634)] }); - assertSpyCall(fetchStub, 2, { args: [urlForPage(636)] }); + assertSpyCall(fetchStub, 0, { args: [urlForPage(9)] }); + assertSpyCall(fetchStub, 1, { args: [urlForPage(8)] }); + assertSpyCall(fetchStub, 2, { args: [urlForPage(10)] }); }); it("does not query random projects for the first page when filtering for location", async () => { -- GitLab