From ee01799ee12105c04dd97ac943a3fb77cf9609fd Mon Sep 17 00:00:00 2001 From: meetul Date: Fri, 9 Feb 2024 12:09:27 +0530 Subject: [PATCH] update test --- schema.graphql | 2 +- src/constants.ts | 10 ++++++++++ .../generateRecurrenceRuleString.ts | 4 ++-- src/typeDefs/inputs.ts | 2 +- src/types/generatedGraphQLTypes.ts | 2 +- tests/resolvers/Mutation/createEvent.spec.ts | 11 ++++++++--- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/schema.graphql b/schema.graphql index 3def5ece74..3a9565b223 100644 --- a/schema.graphql +++ b/schema.graphql @@ -908,7 +908,7 @@ enum Recurrance { input RecurrenceRuleInput { count: Int frequency: Frequency - weekdays: [WeekDays] + weekDays: [WeekDays] } enum Status { diff --git a/src/constants.ts b/src/constants.ts index 8256b67f37..b4490c7a34 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,6 @@ import { getEnvIssues, envSchema } from "./env"; import crypto from "crypto"; +import type { WeekDays } from "./types/generatedGraphQLTypes"; const issues = getEnvIssues(); let ENV = process.env; @@ -529,6 +530,15 @@ export const REDIS_PASSWORD = process.env.REDIS_PASSWORD; export const MILLISECONDS_IN_A_WEEK = 7 * 24 * 60 * 60 * 1000; +export const NORMAL_WEEKDAYS: WeekDays[] = [ + "SU", + "MO", + "TU", + "WE", + "TH", + "FR", + "SA", +]; export const RECURRING_EVENT_INSTANCES_MONTH_LIMIT = 6; export const RECURRENCE_FREQUENCIES = ["YEARLY", "MONTHLY", "WEEKLY", "DAILY"]; export const RECURRENCE_WEEKDAYS = [ diff --git a/src/helpers/event/recurringEventHelpers/generateRecurrenceRuleString.ts b/src/helpers/event/recurringEventHelpers/generateRecurrenceRuleString.ts index 948b41bb05..350cbe0c9b 100644 --- a/src/helpers/event/recurringEventHelpers/generateRecurrenceRuleString.ts +++ b/src/helpers/event/recurringEventHelpers/generateRecurrenceRuleString.ts @@ -18,7 +18,7 @@ export const generateRecurrenceRuleString = ( recurrenceEndDate?: Date ): string => { // destructure the rules - const { frequency, count, weekdays } = recurrenceRuleData; + const { frequency, count, weekDays } = recurrenceRuleData; // recurrence start date // (not necessarily the start date of the first recurring instance) @@ -33,7 +33,7 @@ export const generateRecurrenceRuleString = ( : ""; // string representing the days of the week the event would recur - const weekdaysString = weekdays?.length ? weekdays.join(",") : ""; + const weekdaysString = weekDays?.length ? weekDays.join(",") : ""; // initiate recurrence rule string let recurrenceRuleString = `DTSTART:${formattedRecurrenceStartDate}\nRRULE:FREQ=${frequency}`; diff --git a/src/typeDefs/inputs.ts b/src/typeDefs/inputs.ts index ab1dc00142..89fecd3d24 100644 --- a/src/typeDefs/inputs.ts +++ b/src/typeDefs/inputs.ts @@ -246,7 +246,7 @@ export const inputs = gql` input RecurrenceRuleInput { frequency: Frequency - weekdays: [WeekDays] + weekDays: [WeekDays] count: Int } diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index b61092127c..b944e6e9ef 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -1677,7 +1677,7 @@ export type Recurrance = export type RecurrenceRuleInput = { count?: InputMaybe; frequency?: InputMaybe; - weekdays?: InputMaybe>>; + weekDays?: InputMaybe>>; }; export type Status = diff --git a/tests/resolvers/Mutation/createEvent.spec.ts b/tests/resolvers/Mutation/createEvent.spec.ts index 5d2280ed4b..6ae4f99bbf 100644 --- a/tests/resolvers/Mutation/createEvent.spec.ts +++ b/tests/resolvers/Mutation/createEvent.spec.ts @@ -11,6 +11,7 @@ import { import { LENGTH_VALIDATION_ERROR, + NORMAL_WEEKDAYS, ORGANIZATION_NOT_AUTHORIZED_ERROR, ORGANIZATION_NOT_FOUND_ERROR, USER_NOT_FOUND_ERROR, @@ -403,6 +404,10 @@ describe("resolvers -> Mutation -> createEvent", () => { let startDate = new Date(); startDate = addMonths(startDate, 1); + const today = startDate.getDay(); + const nextDay = (today + 1) % 7; + + const weekDays = [NORMAL_WEEKDAYS[today], NORMAL_WEEKDAYS[nextDay]]; const args: MutationCreateEventArgs = { data: { @@ -422,8 +427,8 @@ describe("resolvers -> Mutation -> createEvent", () => { }, recurrenceRuleData: { frequency: "WEEKLY", - weekdays: ["TH", "SA"], - count: 5, + weekDays, + count: 10, }, }; @@ -471,7 +476,7 @@ describe("resolvers -> Mutation -> createEvent", () => { }).lean(); expect(recurringEvents).toBeDefined(); - expect(recurringEvents).toHaveLength(5); + expect(recurringEvents).toHaveLength(10); const attendeeExists = await EventAttendee.exists({ userId: testUser?._id,