Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nextOpeningDates start at and include today #126

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
},
];
Loading