calcom/apps/web/test/lib/getAvailabilityFromSchedule.test.ts
Omar López 2e6bc5e5b4 Fixes/app store keys in db (#2651)
* Adds available apps

* Adds App Model

* WIP

* Updates seeder script

* Seeder fixes

* lowercase categories

* Upgrades prisma

* WIP

* WIP

* Hopefully fixes circular deps

* Type fixes

* Fixes seeder

* Adds migration to connect Credentials to Apps

* Updates app store callbacks

* Updates google credentials

* Uses dirName from DB

* Type fixes

* Update reschedule.ts

* Seeder fixes

* Fixes categories listing

* Update index.ts

* Update schema.prisma

* Updates dependencies

* Renames giphy app

* Uses dynamic imports for app metadata

* Fixes credentials error

* Uses dynamic import for api handlers

* Dynamic import fixes

* Allows for simple folder names in app store

* Squashes app migrations

* seeder fixes

* Fixes dyamic imports

* Update apiHandlers.tsx
2022-05-02 16:21:11 -06:00

72 lines
2 KiB
TypeScript

import { expect, it } from "@jest/globals";
import { Availability } from "@prisma/client";
import dayjs from "dayjs";
import customParseFormat from "dayjs/plugin/customParseFormat";
import MockDate from "mockdate";
import { getAvailabilityFromSchedule } from "@lib/availability";
dayjs.extend(customParseFormat);
MockDate.set("2021-06-20T11:59:59Z");
//parse "hh:mm-hh:mm" into <Availability> object
const parseWorkingHours = (workingHours: string) => {
const times = workingHours.split("-").map((time) => dayjs(time, "hh:mm").toDate());
return { start: times[0], end: times[1] };
};
const p = parseWorkingHours;
// mocked working hours
const fulltimeWH = p("09:00-17:00");
const morningWH = p("09:00-12:00");
const afternoonWH = p("13:00-17:00");
it("should return an empty availability array when received an empty schedule", async () => {
const schedule = [[]];
expect(getAvailabilityFromSchedule(schedule)).toStrictEqual([]);
});
it("should return availability for all workable days from 9:00 to 17:00", async () => {
const schedule = [[], [fulltimeWH], [fulltimeWH], [fulltimeWH], [fulltimeWH], [fulltimeWH], []];
const expected = [
{
days: [1, 2, 3, 4, 5],
startTime: fulltimeWH.start,
endTime: fulltimeWH.end,
},
] as Availability[];
expect(getAvailabilityFromSchedule(schedule)).toStrictEqual(expected);
});
it("should return the available days grouped by the available time slots", async () => {
const schedule = [
[],
[afternoonWH],
[afternoonWH],
[morningWH, afternoonWH],
[fulltimeWH],
[morningWH],
[],
];
const expected = [
{
days: [1, 2, 3],
startTime: afternoonWH.start,
endTime: afternoonWH.end,
},
{
days: [3, 5],
startTime: morningWH.start,
endTime: morningWH.end,
},
{
days: [4],
startTime: fulltimeWH.start,
endTime: fulltimeWH.end,
},
] as Availability[];
expect(getAvailabilityFromSchedule(schedule)).toStrictEqual(expected);
});