Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/directory-sync/interfaces/directory-user.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface DirectoryUser<
firstName: string | null;
email: string | null;
lastName: string | null;
/** The full name of the user, as provided by the identity provider. */
name: string | null;
state: 'active' | 'suspended' | 'inactive';
role?: RoleResponse;
roles?: RoleResponse[];
Expand All @@ -41,6 +43,7 @@ export interface DirectoryUserResponse<
first_name: string | null;
email: string | null;
last_name: string | null;
name: string | null;
state: 'active' | 'suspended' | 'inactive';
role?: RoleResponse;
roles?: RoleResponse[];
Expand Down
2 changes: 2 additions & 0 deletions src/directory-sync/serializers/directory-user.serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const deserializeDirectoryUser = <
firstName: directoryUser.first_name,
email: directoryUser.email,
lastName: directoryUser.last_name,
name: directoryUser.name ?? null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing names go untested

Both new tests supply a non-null name, so neither checks the new ?? null fallback. Add cases with name omitted and explicitly null for both deserializers, and assert that the returned name is null. Otherwise, removing the fallback would leave these tests passing while older payloads return undefined.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/directory-sync/serializers/directory-user.serializer.ts
Line: 27

Comment:
**Missing names go untested**

Both new tests supply a non-null `name`, so neither checks the new `?? null` fallback. Add cases with `name` omitted and explicitly null for both deserializers, and assert that the returned `name` is null. Otherwise, removing the fallback would leave these tests passing while older payloads return undefined.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

state: directoryUser.state,
...(directoryUser.role !== undefined && { role: directoryUser.role }),
...(directoryUser.roles !== undefined && { roles: directoryUser.roles }),
Expand Down Expand Up @@ -53,6 +54,7 @@ export const deserializeUpdatedEventDirectoryUser = (
firstName: directoryUser.first_name,
email: directoryUser.email,
lastName: directoryUser.last_name,
name: directoryUser.name ?? null,
state: directoryUser.state,
...(directoryUser.role !== undefined && { role: directoryUser.role }),
...(directoryUser.roles !== undefined && { roles: directoryUser.roles }),
Expand Down
2 changes: 2 additions & 0 deletions src/events/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@ describe('Event', () => {
organizationId: 'org_123',
email: 'jonsnow@workos.com',
firstName: 'Jon',
name: 'Jon Snow',
idpId: 'idp_foo',
lastName: 'Snow',
rawAttributes: {},
Expand Down Expand Up @@ -1564,6 +1565,7 @@ describe('Event', () => {
organization_id: 'org_123',
email: 'jonsnow@workos.com',
first_name: 'Jon',
name: 'Jon Snow',
idp_id: 'idp_foo',
last_name: 'Snow',
raw_attributes: {},
Expand Down
1 change: 1 addition & 0 deletions src/webhooks/fixtures/webhook.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"object": "directory_user",
"last_name": "Lunchford",
"first_name": "Blair",
"name": "Blair Lunchford",
"directory_id": "directory_01F9M7F68PZP8QXP8G7X5QRHS7",
"created_at": "2021-06-25T19:07:33.155Z",
"updated_at": "2021-06-25T19:07:33.155Z",
Expand Down
1 change: 1 addition & 0 deletions src/webhooks/webhooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('Webhook signatures', () => {
object: 'directory_user',
lastName: 'Lunchford',
firstName: 'Blair',
name: 'Blair Lunchford',
directoryId: 'directory_01F9M7F68PZP8QXP8G7X5QRHS7',
createdAt: new Date('2021-06-25T19:07:33.155Z'),
updatedAt: new Date('2021-06-25T19:07:33.155Z'),
Expand Down
Loading