Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Feb 9, 2024
1 parent abf5d91 commit ee01799
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ enum Recurrance {
input RecurrenceRuleInput {
count: Int
frequency: Frequency
weekdays: [WeekDays]
weekDays: [WeekDays]
}

enum Status {
Expand Down
10 changes: 10 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}`;
Expand Down
2 changes: 1 addition & 1 deletion src/typeDefs/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const inputs = gql`
input RecurrenceRuleInput {
frequency: Frequency
weekdays: [WeekDays]
weekDays: [WeekDays]
count: Int
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/generatedGraphQLTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ export type Recurrance =
export type RecurrenceRuleInput = {
count?: InputMaybe<Scalars['Int']['input']>;
frequency?: InputMaybe<Frequency>;
weekdays?: InputMaybe<Array<InputMaybe<WeekDays>>>;
weekDays?: InputMaybe<Array<InputMaybe<WeekDays>>>;
};

export type Status =
Expand Down
11 changes: 8 additions & 3 deletions tests/resolvers/Mutation/createEvent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

import {
LENGTH_VALIDATION_ERROR,
NORMAL_WEEKDAYS,
ORGANIZATION_NOT_AUTHORIZED_ERROR,
ORGANIZATION_NOT_FOUND_ERROR,
USER_NOT_FOUND_ERROR,
Expand Down Expand Up @@ -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: {
Expand All @@ -422,8 +427,8 @@ describe("resolvers -> Mutation -> createEvent", () => {
},
recurrenceRuleData: {
frequency: "WEEKLY",
weekdays: ["TH", "SA"],
count: 5,
weekDays,
count: 10,
},
};

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ee01799

Please sign in to comment.