-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Introduce roles to directory sync users for a beta release. ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [ ] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
- Loading branch information
Showing
10 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -126,6 +126,62 @@ describe('DirectorySync', () => { | |
updated_at: '2021-12-13 12:15:45.531847', | ||
}; | ||
|
||
const userWithRole: DirectoryUserWithGroups = { | ||
object: 'directory_user', | ||
id: 'directory_user_456', | ||
customAttributes: { | ||
custom: true, | ||
}, | ||
directoryId: 'dir_123', | ||
organizationId: 'org_123', | ||
emails: [ | ||
{ | ||
primary: true, | ||
type: 'type', | ||
value: '[email protected]', | ||
}, | ||
], | ||
firstName: 'Jon', | ||
groups: [group], | ||
idpId: 'idp_foo', | ||
lastName: 'Snow', | ||
jobTitle: 'Knight of the Watch', | ||
rawAttributes: {}, | ||
state: 'active', | ||
username: 'jonsnow', | ||
role: { slug: 'super_admin' }, | ||
createdAt: '2021-10-27 15:21:50.640959', | ||
updatedAt: '2021-12-13 12:15:45.531847', | ||
}; | ||
|
||
const userWithRoleResponse: DirectoryUserWithGroupsResponse = { | ||
object: 'directory_user', | ||
id: 'directory_user_456', | ||
custom_attributes: { | ||
custom: true, | ||
}, | ||
directory_id: 'dir_123', | ||
organization_id: 'org_123', | ||
emails: [ | ||
{ | ||
primary: true, | ||
type: 'type', | ||
value: '[email protected]', | ||
}, | ||
], | ||
first_name: 'Jon', | ||
groups: [groupResponse], | ||
idp_id: 'idp_foo', | ||
last_name: 'Snow', | ||
job_title: 'Knight of the Watch', | ||
raw_attributes: {}, | ||
state: 'active', | ||
username: 'jonsnow', | ||
role: { slug: 'super_admin' }, | ||
created_at: '2021-10-27 15:21:50.640959', | ||
updated_at: '2021-12-13 12:15:45.531847', | ||
}; | ||
|
||
describe('listDirectories', () => { | ||
describe('with options', () => { | ||
it('requests Directories with query parameters', async () => { | ||
|
@@ -404,5 +460,17 @@ describe('DirectorySync', () => { | |
|
||
expect(subject).toEqual(userWithGroup); | ||
}); | ||
|
||
describe('with a Role', () => { | ||
it(`requests a Directory User`, async () => { | ||
fetchOnce(userWithRoleResponse); | ||
|
||
const subject = await workos.directorySync.getUser( | ||
'directory_user_456', | ||
); | ||
|
||
expect(subject).toEqual(userWithRole); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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,6 +1,12 @@ | ||
import fetch from 'jest-fetch-mock'; | ||
import { fetchOnce, fetchSearchParams } from '../common/utils/test-utils'; | ||
import { Event, EventResponse, ListResponse } from '../common/interfaces'; | ||
import { | ||
DsyncUserUpdatedEvent, | ||
DsyncUserUpdatedEventResponse, | ||
Event, | ||
EventResponse, | ||
ListResponse, | ||
} from '../common/interfaces'; | ||
import { WorkOS } from '../workos'; | ||
import { ConnectionType } from '../sso/interfaces'; | ||
|
||
|
@@ -108,5 +114,97 @@ describe('Event', () => { | |
listMetadata: {}, | ||
}); | ||
}); | ||
|
||
describe('directory user updated events', () => { | ||
describe('with a role', () => { | ||
const directoryUserUpdated: DsyncUserUpdatedEvent = { | ||
id: 'event_01234ABCD', | ||
createdAt: '2020-05-06 04:21:48.649164', | ||
event: 'dsync.user.updated', | ||
data: { | ||
object: 'directory_user', | ||
id: 'directory_user_456', | ||
customAttributes: { | ||
custom: true, | ||
}, | ||
directoryId: 'dir_123', | ||
organizationId: 'org_123', | ||
emails: [ | ||
{ | ||
primary: true, | ||
type: 'type', | ||
value: '[email protected]', | ||
}, | ||
], | ||
firstName: 'Jon', | ||
idpId: 'idp_foo', | ||
lastName: 'Snow', | ||
jobTitle: 'Knight of the Watch', | ||
rawAttributes: {}, | ||
state: 'active', | ||
username: 'jonsnow', | ||
role: { slug: 'super_admin' }, | ||
previousAttributes: { | ||
role: { slug: 'member' }, | ||
}, | ||
createdAt: '2021-10-27 15:21:50.640959', | ||
updatedAt: '2021-12-13 12:15:45.531847', | ||
}, | ||
}; | ||
|
||
const directoryUserUpdatedResponse: DsyncUserUpdatedEventResponse = { | ||
id: 'event_01234ABCD', | ||
created_at: '2020-05-06 04:21:48.649164', | ||
event: 'dsync.user.updated', | ||
data: { | ||
object: 'directory_user', | ||
id: 'directory_user_456', | ||
custom_attributes: { | ||
custom: true, | ||
}, | ||
directory_id: 'dir_123', | ||
organization_id: 'org_123', | ||
emails: [ | ||
{ | ||
primary: true, | ||
type: 'type', | ||
value: '[email protected]', | ||
}, | ||
], | ||
first_name: 'Jon', | ||
idp_id: 'idp_foo', | ||
last_name: 'Snow', | ||
job_title: 'Knight of the Watch', | ||
raw_attributes: {}, | ||
state: 'active', | ||
username: 'jonsnow', | ||
role: { slug: 'super_admin' }, | ||
previous_attributes: { | ||
role: { slug: 'member' }, | ||
}, | ||
created_at: '2021-10-27 15:21:50.640959', | ||
updated_at: '2021-12-13 12:15:45.531847', | ||
}, | ||
}; | ||
const directoryUserEventsListResponse: ListResponse<EventResponse> = { | ||
object: 'list', | ||
data: [directoryUserUpdatedResponse], | ||
list_metadata: {}, | ||
}; | ||
it(`returns the role`, async () => { | ||
fetchOnce(directoryUserEventsListResponse); | ||
|
||
const list = await workos.events.listEvents({ | ||
events: ['dsync.user.updated'], | ||
}); | ||
|
||
expect(list).toEqual({ | ||
object: 'list', | ||
data: [directoryUserUpdated], | ||
listMetadata: {}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains 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 @@ | ||
export * from './role.interface'; |
File renamed without changes.
This file contains 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
2 changes: 1 addition & 1 deletion
2
src/user-management/interfaces/organization-membership.interface.ts
This file contains 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 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