-
Notifications
You must be signed in to change notification settings - Fork 13.2k
fix(api-v2): respect requested slot range for rolling windows #28939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gfernandez-me
wants to merge
3
commits into
calcom:main
Choose a base branch
from
gfernandez-me:fix-v2-slots-rolling-window
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
apps/api/v2/src/modules/slots/slots-2024-09-04/services/slots-input.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { Test } from "@nestjs/testing"; | ||
| import type { TestingModule } from "@nestjs/testing"; | ||
| import { SlotsInputService_2024_09_04 } from "@/modules/slots/slots-2024-09-04/services/slots-input.service"; | ||
| import { TeamsEventTypesRepository } from "@/modules/teams/event-types/teams-event-types.repository"; | ||
| import { TeamsRepository } from "@/modules/teams/teams/teams.repository"; | ||
| import { UsersRepository } from "@/modules/users/users.repository"; | ||
| import { EventTypesRepository_2024_06_14 } from "@/platform/event-types/event-types_2024_06_14/event-types.repository"; | ||
|
|
||
| jest.mock( | ||
| "@calcom/platform-libraries", | ||
| () => ({ | ||
| dynamicEvent: { | ||
| id: -1, | ||
| slug: "dynamic", | ||
| length: 30, | ||
| teamId: null, | ||
| }, | ||
| }), | ||
| { virtual: true } | ||
| ); | ||
|
|
||
| describe("SlotsInputService_2024_09_04", () => { | ||
| let service: SlotsInputService_2024_09_04; | ||
| let eventTypeRepository: EventTypesRepository_2024_06_14; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| providers: [ | ||
| SlotsInputService_2024_09_04, | ||
| { | ||
| provide: EventTypesRepository_2024_06_14, | ||
| useValue: { | ||
| getEventTypeById: jest.fn(), | ||
| }, | ||
| }, | ||
| { | ||
| provide: UsersRepository, | ||
| useValue: {}, | ||
| }, | ||
| { | ||
| provide: TeamsRepository, | ||
| useValue: {}, | ||
| }, | ||
| { | ||
| provide: TeamsEventTypesRepository, | ||
| useValue: {}, | ||
| }, | ||
| ], | ||
| }).compile(); | ||
|
|
||
| service = module.get<SlotsInputService_2024_09_04>(SlotsInputService_2024_09_04); | ||
| eventTypeRepository = module.get<EventTypesRepository_2024_06_14>(EventTypesRepository_2024_06_14); | ||
|
|
||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("defaults v2 slot requests to UTC and disables rolling window start adjustment", async () => { | ||
| (eventTypeRepository.getEventTypeById as jest.Mock).mockResolvedValue({ | ||
| id: 123, | ||
| slug: "discovery-call", | ||
| teamId: null, | ||
| }); | ||
|
|
||
| await expect( | ||
| service.transformGetSlotsQuery({ | ||
| type: "byEventTypeId", | ||
| eventTypeId: 123, | ||
| start: "2050-12-09", | ||
| end: "2050-12-10", | ||
| }) | ||
| ).resolves.toMatchObject({ | ||
| startTime: "2050-12-09T00:00:00.000Z", | ||
| endTime: "2050-12-10T23:59:59.000Z", | ||
| timeZone: "UTC", | ||
| disableRollingWindowAdjustment: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("preserves an explicitly requested time zone", async () => { | ||
| (eventTypeRepository.getEventTypeById as jest.Mock).mockResolvedValue({ | ||
| id: 123, | ||
| slug: "discovery-call", | ||
| teamId: null, | ||
| }); | ||
|
|
||
| await expect( | ||
| service.transformGetSlotsQuery({ | ||
| type: "byEventTypeId", | ||
| eventTypeId: 123, | ||
| start: "2050-12-09", | ||
| end: "2050-12-10", | ||
| timeZone: "Europe/Rome", | ||
| }) | ||
| ).resolves.toMatchObject({ | ||
| timeZone: "Europe/Rome", | ||
| disableRollingWindowAdjustment: true, | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
disableRollingWindowAdjustment: trueon every v2 request causes rolling-window period checks to use only the caller’s requested range, not the near-term dates thatcalculatePeriodLimitsdepends on to compute the true window end. For rolling-window event types, a request that starts in the future (for example, a 14-day window queried from day 20 onward) can now return slots outside the configured booking window because missing early dates are treated as non-bookable and push the computed end date forward. Previously, the one-month lookback mitigated this by including near-term dates in the computation.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by removing
disableRollingWindowAdjustmentfrom the v2 slots path and shared slots input schema. The rolling-window one-month lookback is still enabled for bounds calculation, while v2 requests still defaulttimeZonetoUTC, so the existing final requested-range filter trims the response to the caller’sstart/endrange.