Skip to content

Commit

Permalink
Merge pull request #126 from wellcomecollection/nextOpeningtimes-list…
Browse files Browse the repository at this point in the history
…-starts-today

nextOpeningDates start at and include today
  • Loading branch information
agnesgaroux committed May 8, 2024
2 parents c966fbe + bb808de commit 66155ad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
5 changes: 1 addition & 4 deletions api/src/controllers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ export function getNextOpeningDates(
// create a dateList of 21 consecutive days starting tomorrow
// 21 is arbitrary, we just need to have at least 12 once all the closed days have been removed
const dateNow = new Date();
const timeSeriesStart = addDays(dateNow, 1);
const dateList = [...Array(21).keys()].map((day) =>
addDays(timeSeriesStart, day)
);
const dateList = [...Array(21).keys()].map((day) => addDays(dateNow, day));

// day(s) of the week when the venue is normally closed, as ["monday", "sunday", ...]
const regularClosedDays = regularOpeningDays
Expand Down
10 changes: 5 additions & 5 deletions api/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ const mockDateNow = (dateToMock: string) => {
};

describe("getNextOpeningDates", () => {
it("start the dateList at today + 1", () => {
it("start the dateList from today", () => {
mockDateNow("2024-03-12T08:00:00.000Z");

const expectedStart = {
open: "2024-03-13T10:00:00.000Z",
close: "2024-03-13T18:00:00.000Z",
open: "2024-03-12T10:00:00.000Z",
close: "2024-03-12T18:00:00.000Z",
};

expect(getNextOpeningDates(regularOpeningDays, [])[0]).toEqual(
Expand All @@ -90,6 +90,7 @@ describe("getNextOpeningDates", () => {
mockDateNow("2024-03-12T10:00:00.000Z");

const expectedNextOpeningDates = [
{ open: "2024-03-12T10:00:00.000Z", close: "2024-03-12T18:00:00.000Z" },
{ open: "2024-03-13T10:00:00.000Z", close: "2024-03-13T18:00:00.000Z" },
{ open: "2024-03-14T10:00:00.000Z", close: "2024-03-14T20:00:00.000Z" },
{ open: "2024-03-15T10:00:00.000Z", close: "2024-03-15T18:00:00.000Z" },
Expand All @@ -107,7 +108,6 @@ describe("getNextOpeningDates", () => {
{ open: "2024-03-29T10:00:00.000Z", close: "2024-03-29T18:00:00.000Z" },
{ open: "2024-03-30T10:00:00.000Z", close: "2024-03-30T16:00:00.000Z" },
{ open: "2024-04-01T09:00:00.000Z", close: "2024-04-01T17:00:00.000Z" },
{ open: "2024-04-02T09:00:00.000Z", close: "2024-04-02T17:00:00.000Z" },
];

expect(getNextOpeningDates(regularOpeningDays, [])).toStrictEqual(
Expand All @@ -119,6 +119,7 @@ describe("getNextOpeningDates", () => {
mockDateNow("2024-03-12T10:00:00.000Z");

const expectedNextOpeningDates = [
{ open: "2024-03-12T10:00:00.000Z", close: "2024-03-12T18:00:00.000Z" },
{ open: "2024-03-13T10:00:00.000Z", close: "2024-03-13T18:00:00.000Z" },
{ open: "2024-03-14T10:00:00.000Z", close: "2024-03-14T20:00:00.000Z" },
{ open: "2024-03-15T10:00:00.000Z", close: "2024-03-15T18:00:00.000Z" },
Expand All @@ -133,7 +134,6 @@ describe("getNextOpeningDates", () => {
{ open: "2024-03-26T10:00:00.000Z", close: "2024-03-26T18:00:00.000Z" },
{ open: "2024-03-27T10:00:00.000Z", close: "2024-03-27T18:00:00.000Z" },
{ open: "2024-03-29T10:00:00.000Z", close: "2024-03-29T18:00:00.000Z" },
{ open: "2024-04-02T09:00:00.000Z", close: "2024-04-02T17:00:00.000Z" },
];

expect(
Expand Down
8 changes: 4 additions & 4 deletions api/test/venues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ const venueData = {
};

const expectedNextOpeningDates = [
{
open: "2024-04-02T09:00:00.000Z",
close: "2024-04-02T17:00:00.000Z",
},
{
open: "2024-04-03T09:00:00.000Z",
close: "2024-04-03T17:00:00.000Z",
Expand Down Expand Up @@ -179,8 +183,4 @@ const expectedNextOpeningDates = [
open: "2024-04-22T09:00:00.000Z",
close: "2024-04-22T17:00:00.000Z",
},
{
open: "2024-04-23T09:00:00.000Z",
close: "2024-04-23T17:00:00.000Z",
},
];

0 comments on commit 66155ad

Please sign in to comment.