-
Notifications
You must be signed in to change notification settings - Fork 11.6k
feat(api-v2): add event-type level selected calendars for conflict checking #26730
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
ThyMinimalDev
wants to merge
23
commits into
main
Choose a base branch
from
devin/event-type-selected-calendars-1768203692
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.
+551
−11
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b2751c5
feat(api-v2): add event-type level selected calendars for conflict ch…
devin-ai-integration[bot] 9ea142b
test(api-v2): add e2e tests for event-type level selected calendars
devin-ai-integration[bot] 3bb490d
Merge branch 'main' into devin/event-type-selected-calendars-1768203692
ThyMinimalDev 152dff0
fix(api-v2): address review feedback for selected calendars feature
devin-ai-integration[bot] 62f4854
Merge branch 'devin/event-type-selected-calendars-1768203692' of http…
devin-ai-integration[bot] 8eb70de
fix(api-v2): include selectedCalendars in GET event-type endpoint
devin-ai-integration[bot] 646253d
Merge branch 'main' into devin/event-type-selected-calendars-1768203692
devin-ai-integration[bot] 7dc025a
Merge branch 'main' into devin/event-type-selected-calendars-1768203692
ThyMinimalDev 072f5f1
refactor(api-v2): address review feedback for selected calendars
devin-ai-integration[bot] 53ba3e9
fix(api-v2): forward destinationCalendar to updateEventType in create…
devin-ai-integration[bot] d2f8059
refactor(api-v2): remove useEventLevelSelectedCalendars from API types
devin-ai-integration[bot] 9277dfb
fix(api-v2): remove useEventLevelSelectedCalendars from public endpoi…
devin-ai-integration[bot] 6c29eb0
fix(api-v2): remove remaining useEventLevelSelectedCalendars referenc…
devin-ai-integration[bot] b1df6e3
Merge branch 'devin/event-type-selected-calendars-1768203692' of http…
devin-ai-integration[bot] 05aa421
fix(api-v2): revert function rename and fix type error in output service
devin-ai-integration[bot] 7d238dd
fix(api-v2): update E2E tests to remove useEventLevelSelectedCalendar…
devin-ai-integration[bot] fc259b4
refactor(api-v2): separate function for removing selectedCalendars fr…
devin-ai-integration[bot] 8f67055
Merge branch 'main' into devin/event-type-selected-calendars-1768203692
ThyMinimalDev 34cd105
refactor(api-v2): move Prisma calls from service to repositories
devin-ai-integration[bot] e3aa227
Merge branch 'devin/event-type-selected-calendars-1768203692' of http…
devin-ai-integration[bot] c504e31
fix(api-v2): restore PrismaWriteService in service constructor
devin-ai-integration[bot] 450ab6a
refactor(api-v2): keep transaction in service, move Prisma calls to r…
devin-ai-integration[bot] 5138284
refactor(api-v2): move selected calendar tx methods to SelectedCalend…
devin-ai-integration[bot] 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
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 |
|---|---|---|
|
|
@@ -3189,4 +3189,206 @@ describe("Event types Endpoints", () => { | |
| await app.close(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Event-type level selected calendars", () => { | ||
| let app: INestApplication; | ||
|
|
||
| let oAuthClient: PlatformOAuthClient; | ||
| let organization: Team; | ||
| let userRepositoryFixture: UserRepositoryFixture; | ||
| let oauthClientRepositoryFixture: OAuthClientRepositoryFixture; | ||
| let teamRepositoryFixture: TeamRepositoryFixture; | ||
| let eventTypesRepositoryFixture: EventTypesRepositoryFixture; | ||
| let apiKeysRepositoryFixture: ApiKeysRepositoryFixture; | ||
|
|
||
| const userEmail = `selected-calendars-test-${randomString()}@api.com`; | ||
| const name = `selected-calendars-test-${randomString()}`; | ||
| const username = name; | ||
| let user: User; | ||
| let apiKeyString: string; | ||
| let createdEventTypeId: number; | ||
|
|
||
| beforeAll(async () => { | ||
| const moduleRef = await Test.createTestingModule({ | ||
| providers: [PrismaExceptionFilter, HttpExceptionFilter], | ||
| imports: [AppModule, UsersModule, EventTypesModule_2024_06_14, TokensModule], | ||
| }) | ||
| .overrideGuard(PermissionsGuard) | ||
| .useValue({ | ||
| canActivate: () => true, | ||
| }) | ||
| .compile(); | ||
|
|
||
| app = moduleRef.createNestApplication(); | ||
| bootstrap(app as NestExpressApplication); | ||
|
|
||
| oauthClientRepositoryFixture = new OAuthClientRepositoryFixture(moduleRef); | ||
| userRepositoryFixture = new UserRepositoryFixture(moduleRef); | ||
| teamRepositoryFixture = new TeamRepositoryFixture(moduleRef); | ||
| eventTypesRepositoryFixture = new EventTypesRepositoryFixture(moduleRef); | ||
| apiKeysRepositoryFixture = new ApiKeysRepositoryFixture(moduleRef); | ||
|
|
||
| organization = await teamRepositoryFixture.create({ | ||
| name: `selected-calendars-org-${randomString()}`, | ||
| slug: `selected-calendars-org-slug-${randomString()}`, | ||
| }); | ||
|
|
||
| oAuthClient = await createOAuthClient(organization.id); | ||
|
|
||
| user = await userRepositoryFixture.create({ | ||
| email: userEmail, | ||
| name, | ||
| username, | ||
| }); | ||
|
|
||
| const { keyString } = await apiKeysRepositoryFixture.createApiKey(user.id, null); | ||
| apiKeyString = `cal_test_${keyString}`; | ||
|
|
||
| await app.init(); | ||
| }); | ||
|
|
||
| async function createOAuthClient(organizationId: number) { | ||
| const data = { | ||
| logo: "logo-url", | ||
| name: "name", | ||
| redirectUris: ["redirect-uri"], | ||
| permissions: 32, | ||
| }; | ||
| const secret = "secret"; | ||
|
|
||
| const client = await oauthClientRepositoryFixture.create(organizationId, data, secret); | ||
| return client; | ||
| } | ||
|
|
||
| it("should create an event type with selectedCalendars", async () => { | ||
| const body: CreateEventTypeInput_2024_06_14 = { | ||
| title: "Event with selected calendars", | ||
| slug: `event-selected-calendars-${randomString()}`, | ||
| lengthInMinutes: 30, | ||
| locations: [ | ||
| { | ||
| type: "integration", | ||
| integration: "cal-video", | ||
| }, | ||
| ], | ||
| selectedCalendars: [ | ||
| { | ||
| integration: "google_calendar", | ||
| externalId: "primary", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const response = await request(app.getHttpServer()) | ||
| .post("/api/v2/event-types") | ||
| .set(CAL_API_VERSION_HEADER, VERSION_2024_06_14) | ||
| .set("Authorization", `Bearer ${apiKeyString}`) | ||
| .send(body) | ||
| .expect(201); | ||
|
|
||
| const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body; | ||
| const createdEventType = responseBody.data; | ||
|
|
||
| expect(createdEventType).toHaveProperty("id"); | ||
| expect(createdEventType.title).toEqual(body.title); | ||
| expect(createdEventType.selectedCalendars).toBeDefined(); | ||
| expect(createdEventType.selectedCalendars).toHaveLength(1); | ||
| expect(createdEventType.selectedCalendars?.[0].integration).toEqual("google_calendar"); | ||
| expect(createdEventType.selectedCalendars?.[0].externalId).toEqual("primary"); | ||
|
|
||
| createdEventTypeId = createdEventType.id; | ||
| }); | ||
|
|
||
| it("should update an event type with selectedCalendars", async () => { | ||
| const updateBody: UpdateEventTypeInput_2024_06_14 = { | ||
| selectedCalendars: [ | ||
| { | ||
| integration: "google_calendar", | ||
| externalId: "primary", | ||
| }, | ||
| { | ||
| integration: "google_calendar", | ||
| externalId: "[email protected]", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const response = await request(app.getHttpServer()) | ||
| .patch(`/api/v2/event-types/${createdEventTypeId}`) | ||
| .set(CAL_API_VERSION_HEADER, VERSION_2024_06_14) | ||
| .set("Authorization", `Bearer ${apiKeyString}`) | ||
| .send(updateBody) | ||
| .expect(200); | ||
|
|
||
| const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body; | ||
| const updatedEventType = responseBody.data; | ||
|
|
||
| expect(updatedEventType.selectedCalendars).toBeDefined(); | ||
| expect(updatedEventType.selectedCalendars).toHaveLength(2); | ||
| }); | ||
|
|
||
| it("should get an event type with selectedCalendars via authenticated endpoint", async () => { | ||
| const response = await request(app.getHttpServer()) | ||
| .get(`/api/v2/event-types/${createdEventTypeId}`) | ||
| .set(CAL_API_VERSION_HEADER, VERSION_2024_06_14) | ||
| .set("Authorization", `Bearer ${apiKeyString}`) | ||
| .expect(200); | ||
|
|
||
| const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body; | ||
| const eventType = responseBody.data; | ||
|
|
||
| expect(eventType.selectedCalendars).toBeDefined(); | ||
| expect(eventType.selectedCalendars).toHaveLength(2); | ||
| }); | ||
|
|
||
| it("should NOT include selectedCalendars in public endpoint response", async () => { | ||
| const response = await request(app.getHttpServer()) | ||
| .get(`/api/v2/event-types?username=${user.username}`) | ||
| .set(CAL_API_VERSION_HEADER, VERSION_2024_06_14) | ||
| .expect(200); | ||
|
|
||
| const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14[]> = response.body; | ||
| const eventTypes = responseBody.data; | ||
|
|
||
| const eventType = eventTypes.find((et) => et.id === createdEventTypeId); | ||
| expect(eventType).toBeDefined(); | ||
| expect(eventType?.selectedCalendars).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("should clear selectedCalendars when empty array is provided", async () => { | ||
| const updateBody: UpdateEventTypeInput_2024_06_14 = { | ||
| selectedCalendars: [], | ||
| }; | ||
|
|
||
| const response = await request(app.getHttpServer()) | ||
| .patch(`/api/v2/event-types/${createdEventTypeId}`) | ||
| .set(CAL_API_VERSION_HEADER, VERSION_2024_06_14) | ||
| .set("Authorization", `Bearer ${apiKeyString}`) | ||
| .send(updateBody) | ||
| .expect(200); | ||
|
|
||
| const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body; | ||
| const updatedEventType = responseBody.data; | ||
|
|
||
| expect( | ||
| updatedEventType.selectedCalendars === undefined || updatedEventType.selectedCalendars?.length === 0 | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| try { | ||
| await eventTypesRepositoryFixture.delete(createdEventTypeId); | ||
| } catch (e) { | ||
| console.log(e); | ||
| } | ||
| await oauthClientRepositoryFixture.delete(oAuthClient.id); | ||
| await teamRepositoryFixture.delete(organization.id); | ||
| try { | ||
| await userRepositoryFixture.delete(user.id); | ||
| } catch (e) { | ||
| console.log(e); | ||
| } | ||
| await app.close(); | ||
| }); | ||
| }); | ||
| }); | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.