-
Notifications
You must be signed in to change notification settings - Fork 52
feat(user-metadata): enhance Google metadata handling and update tests #1531
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a03f9e4
feat(user-metadata): enhance Google metadata handling and update tests
tyler-dane 5f3a5d0
fix(backend): guard stale watch metadata assessment errors
cursoragent c814d52
fix(backend): prevent concurrent sync by skipping assessment in impor…
cursoragent 5d674fa
fix(sync,web): recover invalid sync tokens and handle connected status
cursoragent f7034db
fix(web): remove redundant syncStatus check in useConnectGoogle hook
cursoragent 2942646
feat(sync): enhance gcal import handling in SyncController tests
tyler-dane dc14431
fix(util): improve error handling in waitUntilEvent utility
tyler-dane 9f9fa34
feat(auth): enhance Google Calendar connection handling in useConnect…
tyler-dane 04413ed
feat(sync): enhance Google Calendar import functionality and testing
tyler-dane d239a1f
feat(sync): improve Google Calendar repair functionality in useConnec…
tyler-dane 627b3d3
docs(tests): update testing guidelines to avoid direct persistence la…
tyler-dane 9be4a32
fix(web): use state-specific labels for Google Calendar command palette
cursoragent 7eae7d4
test(web): update test assertions to match state-specific Google Cale…
cursoragent 9ca5562
fix(web): prioritize reconnect_required over importing state in Googl…
cursoragent 6c46ccf
fix(backend): remove unused driver methods after local refactor
cursoragent 092f48e
fix(husky): run lint-staged in quiet mode during pre-commit hook
tyler-dane 5902341
fix(sync): enhance Google Calendar sync handling and notification pro…
tyler-dane 7c05304
fix(user-metadata): refactor user metadata retrieval and update logic
tyler-dane 03abffa
feat(user-metadata): implement user metadata refresh and loading stat…
tyler-dane 9a3cdc1
test(DayCmdPalette): enhance tests for command palette button states
tyler-dane 960611f
refactor(google-auth): update socket handling on Google revocation
tyler-dane ecd51e1
feat(websocket): enhance Google Calendar import handling with structu…
tyler-dane ca471b7
feat(google-auth): enhance Google sign-in handling with new utility f…
tyler-dane 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
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/bin/sh | ||
| . "$(dirname "$0")/_/husky.sh" | ||
|
|
||
| yarn lint-staged | ||
| yarn lint-staged --quiet |
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
19 changes: 19 additions & 0 deletions
19
packages/backend/src/__tests__/drivers/user-metadata.service.driver.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,19 @@ | ||
| import type { JSONObject } from "supertokens-node/recipe/usermetadata"; | ||
| import { type UserMetadata } from "@core/types/user.types"; | ||
| import userMetadataService from "@backend/user/services/user-metadata.service"; | ||
|
|
||
| export class UserMetadataServiceDriver { | ||
| updateUserMetadata(params: { | ||
| userId: string; | ||
| data: Partial<UserMetadata>; | ||
| }): Promise<UserMetadata> { | ||
| return userMetadataService.updateUserMetadata(params); | ||
| } | ||
|
|
||
| fetchUserMetadata( | ||
| userId: string, | ||
| userContext?: Record<string, JSONObject>, | ||
| ): Promise<UserMetadata> { | ||
| return userMetadataService.fetchUserMetadata(userId, userContext); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import mongoService from "@backend/common/services/mongo.service"; | ||
|
|
||
| /** | ||
| * Test driver for the watch collection. | ||
| * Use this instead of importing mongoService in tests so persistence can be | ||
| * swapped (e.g. away from Mongo) without changing test code. | ||
| */ | ||
| export class WatchDriver { | ||
| static deleteManyByUser( | ||
| userId: string, | ||
| ): ReturnType<typeof mongoService.watch.deleteMany> { | ||
| return mongoService.watch.deleteMany({ user: userId }); | ||
| } | ||
| } |
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
101 changes: 101 additions & 0 deletions
101
packages/backend/src/common/middleware/supertokens.middleware.util.test.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,101 @@ | ||
| import { type TokenPayload } from "google-auth-library"; | ||
| import { faker } from "@faker-js/faker"; | ||
| import { | ||
| createGoogleSignInSuccess, | ||
| resolveGoogleSessionUserId, | ||
| } from "@backend/common/middleware/supertokens.middleware.util"; | ||
|
|
||
| describe("supertokens.middleware.util", () => { | ||
| describe("resolveGoogleSessionUserId", () => { | ||
| it("prefers the current session when one exists", () => { | ||
| const sessionUserId = faker.database.mongodbObjectId(); | ||
| const recipeUserId = faker.database.mongodbObjectId(); | ||
|
|
||
| expect( | ||
| resolveGoogleSessionUserId({ | ||
| sessionUserId, | ||
| googleAuthIntent: "reconnect", | ||
| createdNewRecipeUser: false, | ||
| recipeUserId, | ||
| }), | ||
| ).toBe(sessionUserId); | ||
| }); | ||
|
|
||
| it("uses the recipe user id for reconnects without a session", () => { | ||
| const recipeUserId = faker.database.mongodbObjectId(); | ||
|
|
||
| expect( | ||
| resolveGoogleSessionUserId({ | ||
| sessionUserId: null, | ||
| googleAuthIntent: "reconnect", | ||
| createdNewRecipeUser: false, | ||
| recipeUserId, | ||
| }), | ||
| ).toBe(recipeUserId); | ||
| }); | ||
|
|
||
| it("keeps normal returning users on the sign-in path without reconnect intent", () => { | ||
| expect( | ||
| resolveGoogleSessionUserId({ | ||
| sessionUserId: null, | ||
| createdNewRecipeUser: false, | ||
| recipeUserId: faker.database.mongodbObjectId(), | ||
| }), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("does not force reconnect behavior for new users", () => { | ||
| expect( | ||
| resolveGoogleSessionUserId({ | ||
| sessionUserId: null, | ||
| googleAuthIntent: "reconnect", | ||
| createdNewRecipeUser: true, | ||
| recipeUserId: faker.database.mongodbObjectId(), | ||
| }), | ||
| ).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("createGoogleSignInSuccess", () => { | ||
| it("returns null for non-OK responses", () => { | ||
| expect( | ||
| createGoogleSignInSuccess({ | ||
| status: "SIGN_IN_UP_NOT_ALLOWED", | ||
| } as Parameters<typeof createGoogleSignInSuccess>[0]), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("embeds reconnect fallback user id into the auth success payload", () => { | ||
| const recipeUserId = faker.database.mongodbObjectId(); | ||
| const success = createGoogleSignInSuccess( | ||
| { | ||
| status: "OK", | ||
| rawUserInfoFromProvider: { | ||
| fromIdTokenPayload: { | ||
| sub: faker.string.uuid(), | ||
| email: faker.internet.email(), | ||
| } as TokenPayload, | ||
| }, | ||
| oAuthTokens: { | ||
| refresh_token: faker.string.uuid(), | ||
| access_token: faker.internet.jwt(), | ||
| }, | ||
| createdNewRecipeUser: false, | ||
| user: { | ||
| id: recipeUserId, | ||
| loginMethods: [{}], | ||
| }, | ||
| } as Parameters<typeof createGoogleSignInSuccess>[0], | ||
| "reconnect", | ||
| null, | ||
| ); | ||
|
|
||
| expect(success).toMatchObject({ | ||
| createdNewRecipeUser: false, | ||
| recipeUserId, | ||
| sessionUserId: recipeUserId, | ||
| loginMethodsLength: 1, | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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.