1- import { ObjectId } from "mongodb" ;
21import { faker } from "@faker-js/faker" ;
32import { GCAL_MAX_RECURRENCES } from "@core/constants/core.constants" ;
43import dayjs from "@core/util/date/dayjs" ;
4+ import { CompassEventRRule } from "@core/util/event/compass.event.rrule" ;
55import { parseCompassEventDate } from "@core/util/event/event.util" ;
66import {
77 createMockBaseEvent ,
88 generateCompassEventDates ,
99} from "@core/util/test/ccal.event.factory" ;
10- import { CompassEventRRule } from "@backend/event/classes/compass.event.rrule" ;
1110
1211describe ( "CompassEventRRule: " , ( ) => {
1312 it ( `should return the correct number of events based on rrule count` , ( ) => {
@@ -18,10 +17,7 @@ describe("CompassEventRRule: ", () => {
1817 recurrence : { rule : [ rruleString ] } ,
1918 } ) ;
2019
21- const rrule = new CompassEventRRule ( {
22- ...baseEvent ,
23- _id : new ObjectId ( baseEvent . _id ) ,
24- } ) ;
20+ const rrule = new CompassEventRRule ( baseEvent ) ;
2521
2622 expect ( rrule . toString ( ) ) . toContain ( "RRULE:FREQ=DAILY" ) ;
2723 expect ( rrule . toString ( ) ) . toContain ( `COUNT=${ count } ` ) ;
@@ -36,10 +32,7 @@ describe("CompassEventRRule: ", () => {
3632 recurrence : { rule : [ rruleString ] } ,
3733 } ) ;
3834
39- const rrule = new CompassEventRRule ( {
40- ...baseEvent ,
41- _id : new ObjectId ( baseEvent . _id ) ,
42- } ) ;
35+ const rrule = new CompassEventRRule ( baseEvent ) ;
4336
4437 expect ( rrule . toString ( ) ) . toContain ( "RRULE:FREQ=DAILY" ) ;
4538 expect ( rrule . toString ( ) ) . toContain ( `COUNT=${ GCAL_MAX_RECURRENCES } ` ) ;
@@ -49,10 +42,7 @@ describe("CompassEventRRule: ", () => {
4942
5043 it ( "should return the rrule in system timezone" , ( ) => {
5144 const baseEvent = createMockBaseEvent ( ) ;
52- const rrule = new CompassEventRRule ( {
53- ...baseEvent ,
54- _id : new ObjectId ( baseEvent . _id ) ,
55- } ) ;
45+ const rrule = new CompassEventRRule ( baseEvent ) ;
5646 const startDate = parseCompassEventDate ( baseEvent . startDate ! ) ;
5747 const events = rrule . all ( ) ;
5848
@@ -65,13 +55,7 @@ describe("CompassEventRRule: ", () => {
6555
6656 it ( "should return the rrule without DTSTART and DTEND" , ( ) => {
6757 const baseEvent = createMockBaseEvent ( ) ;
68- const rrule = new CompassEventRRule ( {
69- ...baseEvent ,
70- _id : new ObjectId ( baseEvent . _id ) ,
71- } ) ;
72-
73- expect ( rrule . toString ( ) . includes ( "DTSTART" ) ) . toEqual ( false ) ;
74- expect ( rrule . toString ( ) . includes ( "DTEND" ) ) . toEqual ( false ) ;
58+ const rrule = new CompassEventRRule ( baseEvent ) ;
7559
7660 expect (
7761 rrule . toRecurrence ( ) . some ( ( rule ) => rule . includes ( "DTSTART" ) ) ,
@@ -85,10 +69,7 @@ describe("CompassEventRRule: ", () => {
8569 describe ( "base" , ( ) => {
8670 it ( "should return the recurrence string as an array" , ( ) => {
8771 const baseEvent = createMockBaseEvent ( ) ;
88- const rrule = new CompassEventRRule ( {
89- ...baseEvent ,
90- _id : new ObjectId ( baseEvent . _id ) ,
91- } ) ;
72+ const rrule = new CompassEventRRule ( baseEvent ) ;
9273 const recurrence = rrule . toRecurrence ( ) ;
9374
9475 expect ( recurrence ) . toBeInstanceOf ( Array ) ;
@@ -104,10 +85,7 @@ describe("CompassEventRRule: ", () => {
10485 it ( `should return a maximum of ${ GCAL_MAX_RECURRENCES } compass instances if no count is supplied in the recurrence` , ( ) => {
10586 const rule = [ "RRULE:FREQ=DAILY" ] ;
10687 const baseEvent = createMockBaseEvent ( { recurrence : { rule } } ) ;
107- const rrule = new CompassEventRRule ( {
108- ...baseEvent ,
109- _id : new ObjectId ( baseEvent . _id ) ,
110- } ) ;
88+ const rrule = new CompassEventRRule ( baseEvent ) ;
11189 const instances = rrule . instances ( ) ;
11290
11391 expect ( instances ) . toBeInstanceOf ( Array ) ;
@@ -117,10 +95,7 @@ describe("CompassEventRRule: ", () => {
11795 it ( `should return a maximum of ${ GCAL_MAX_RECURRENCES } compass instances if count exceeds maximum recurrence` , ( ) => {
11896 const rule = [ "RRULE:FREQ=DAILY;COUNT=1000" ] ;
11997 const baseEvent = createMockBaseEvent ( { recurrence : { rule } } ) ;
120- const rrule = new CompassEventRRule ( {
121- ...baseEvent ,
122- _id : new ObjectId ( baseEvent . _id ) ,
123- } ) ;
98+ const rrule = new CompassEventRRule ( baseEvent ) ;
12499 const instances = rrule . instances ( ) ;
125100
126101 expect ( instances ) . toBeInstanceOf ( Array ) ;
@@ -131,10 +106,7 @@ describe("CompassEventRRule: ", () => {
131106 const count = faker . number . int ( { min : 1 , max : GCAL_MAX_RECURRENCES } ) ;
132107 const rule = [ `RRULE:FREQ=DAILY;COUNT=${ count } ` ] ;
133108 const baseEvent = createMockBaseEvent ( { recurrence : { rule } } ) ;
134- const rrule = new CompassEventRRule ( {
135- ...baseEvent ,
136- _id : new ObjectId ( baseEvent . _id ) ,
137- } ) ;
109+ const rrule = new CompassEventRRule ( baseEvent ) ;
138110 const instances = rrule . instances ( ) ;
139111
140112 expect ( instances ) . toBeInstanceOf ( Array ) ;
@@ -146,10 +118,7 @@ describe("CompassEventRRule: ", () => {
146118 const date = dayjs ( ) . startOf ( "year" ) ; // specific date for testing
147119 const dates = generateCompassEventDates ( { date, allDay : true } ) ;
148120 const baseEvent = createMockBaseEvent ( { ...dates , recurrence : { rule } } ) ;
149- const rrule = new CompassEventRRule ( {
150- ...baseEvent ,
151- _id : new ObjectId ( baseEvent . _id ) ,
152- } ) ;
121+ const rrule = new CompassEventRRule ( baseEvent ) ;
153122 const instances = rrule . instances ( ) ;
154123 const startDate = parseCompassEventDate ( baseEvent . startDate ! ) ;
155124 const endDate = parseCompassEventDate ( baseEvent . endDate ! ) ;
@@ -174,10 +143,7 @@ describe("CompassEventRRule: ", () => {
174143 const date = dayjs ( ) . startOf ( "year" ) ; // specific date for testing
175144 const dates = generateCompassEventDates ( { date } ) ;
176145 const baseEvent = createMockBaseEvent ( { ...dates , recurrence : { rule } } ) ;
177- const rrule = new CompassEventRRule ( {
178- ...baseEvent ,
179- _id : new ObjectId ( baseEvent . _id ) ,
180- } ) ;
146+ const rrule = new CompassEventRRule ( baseEvent ) ;
181147 const instances = rrule . instances ( ) ;
182148 const startDate = parseCompassEventDate ( baseEvent . startDate ! ) ;
183149 const endDate = parseCompassEventDate ( baseEvent . endDate ! ) ;
0 commit comments