Skip to content
Open
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
65 changes: 58 additions & 7 deletions clients/javascript/tests/account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('Account API', () => {
let eventId2: string
let recurringEventId: string
let recurringExceptionEventId: string
let expiredRecurringEventId: string

const externalId = 'externalId'
const externalId2 = 'externalId2'
Expand Down Expand Up @@ -174,6 +175,20 @@ describe('Account API', () => {
})

recurringExceptionEventId = exceptionEventRes.event.id

const expiredRecurringEventRes = await adminClient.events.create(userId, {
calendarId,
status: 'confirmed',
duration: 500,
startTime: new Date(1400),
recurrence: {
freq: 'weekly',
interval: 1,
until: new Date(3000).toISOString(),
},
})

expiredRecurringEventId = expiredRecurringEventRes.event.id
})

it('should be able to search for events in the account (by startTime, for multiple users)', async () => {
Expand All @@ -187,7 +202,7 @@ describe('Account API', () => {
},
},
})
expect(res.events.length).toBe(3)
expect(res.events.length).toBe(4)
expect(res.events).toEqual(
expect.arrayContaining([
expect.objectContaining({
Expand All @@ -199,6 +214,9 @@ describe('Account API', () => {
expect.objectContaining({
id: eventId2,
}),
expect.objectContaining({
id: expiredRecurringEventId,
}),
])
)
})
Expand All @@ -215,7 +233,7 @@ describe('Account API', () => {
},
sort: 'startTimeAsc',
})
expect(res.events.length).toBe(3)
expect(res.events.length).toBe(4)
// Expect this order explicitly as we sort by startTimeAsc
expect(res.events).toEqual([
expect.objectContaining({
Expand All @@ -227,6 +245,9 @@ describe('Account API', () => {
expect.objectContaining({
id: eventId2,
}),
expect.objectContaining({
id: expiredRecurringEventId,
}),
])
})

Expand All @@ -247,7 +268,7 @@ describe('Account API', () => {
// Expect only the last one, as we explicitly sorted by startTimeDesc and limited to 1
expect(res.events).toEqual([
expect.objectContaining({
id: eventId2,
id: expiredRecurringEventId,
}),
])
})
Expand All @@ -263,7 +284,7 @@ describe('Account API', () => {
},
},
})
expect(res.events.length).toBe(3)
expect(res.events.length).toBe(4)
expect(res.events).toEqual(
expect.arrayContaining([
expect.objectContaining({
Expand All @@ -275,6 +296,9 @@ describe('Account API', () => {
expect.objectContaining({
id: recurringExceptionEventId,
}),
expect.objectContaining({
id: expiredRecurringEventId,
}),
])
)
})
Expand All @@ -290,11 +314,14 @@ describe('Account API', () => {
},
},
})
expect(res.events.length).toBe(1)
expect(res.events.length).toBe(2)
expect(res.events).toEqual([
expect.objectContaining({
id: recurringEventId,
}),
expect.objectContaining({
id: expiredRecurringEventId,
}),
])
})

Expand Down Expand Up @@ -335,15 +362,39 @@ describe('Account API', () => {
eq: userId,
},
recurrence: {
existsAndRecurringAt: new Date(10000),
existsAndRecurringAt: new Date(1500),
},
},
})
expect(res.events.length).toBe(1)

expect(res.events.length).toBe(2)
expect(res.events).toEqual([
expect.objectContaining({
id: recurringEventId,
}),
expect.objectContaining({
id: expiredRecurringEventId,
}),
])

// Search outside of the recurrence range
const res2 = await adminClient.account.searchEventsInAccount({
filter: {
userId: {
eq: userId,
},
recurrence: {
existsAndRecurringAt: new Date(10000),
},
},
})

// Only contains the recurring event, and not the expired one
expect(res2.events.length).toBe(1)
expect(res2.events).toEqual([
expect.objectContaining({
id: recurringEventId,
}),
])
})

Expand Down
Loading