diff --git a/app/betterplace.ts b/app/betterplace.ts index d65eb850b5d2653a3cefdf6e893b1b32f7e396a2..95bda6a176860dababba33a98e5bb8831fc9d30d 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 47d01d56939f469528f5969af0077179cf55c419..dcff85e323e70a6a6f774c6cf5c2d9d335814f66 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 () => {