Implement patch tests
This commit is contained in:
parent
40a1921f02
commit
24d2937d0b
|
@ -54,6 +54,7 @@ export interface User extends Document {
|
||||||
userGroups?: string[]
|
userGroups?: string[]
|
||||||
onboardedAt?: string
|
onboardedAt?: string
|
||||||
scimInfo?: {
|
scimInfo?: {
|
||||||
|
username: string
|
||||||
externalId: string
|
externalId: string
|
||||||
isSync: boolean
|
isSync: boolean
|
||||||
firstSync: number
|
firstSync: number
|
||||||
|
|
|
@ -8,12 +8,14 @@ function createScimCreateUserRequest(userData?: {
|
||||||
email?: string
|
email?: string
|
||||||
firstName?: string
|
firstName?: string
|
||||||
lastName?: string
|
lastName?: string
|
||||||
|
username?: string
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
externalId = structures.uuid(),
|
externalId = structures.uuid(),
|
||||||
email = structures.generator.email(),
|
email = structures.generator.email(),
|
||||||
firstName = structures.generator.first(),
|
firstName = structures.generator.first(),
|
||||||
lastName = structures.generator.last(),
|
lastName = structures.generator.last(),
|
||||||
|
username = structures.generator.name(),
|
||||||
} = userData || {}
|
} = userData || {}
|
||||||
|
|
||||||
const user: ScimCreateUserRequest = {
|
const user: ScimCreateUserRequest = {
|
||||||
|
@ -22,7 +24,7 @@ function createScimCreateUserRequest(userData?: {
|
||||||
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
|
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
|
||||||
],
|
],
|
||||||
externalId,
|
externalId,
|
||||||
userName: structures.generator.name(),
|
userName: username,
|
||||||
active: true,
|
active: true,
|
||||||
emails: [
|
emails: [
|
||||||
{
|
{
|
||||||
|
@ -142,6 +144,7 @@ describe("/api/global/scim/v2/users", () => {
|
||||||
email: structures.generator.email(),
|
email: structures.generator.email(),
|
||||||
firstName: structures.generator.first(),
|
firstName: structures.generator.first(),
|
||||||
lastName: structures.generator.last(),
|
lastName: structures.generator.last(),
|
||||||
|
username: structures.generator.name(),
|
||||||
}
|
}
|
||||||
const body = createScimCreateUserRequest(userData)
|
const body = createScimCreateUserRequest(userData)
|
||||||
|
|
||||||
|
@ -156,7 +159,7 @@ describe("/api/global/scim/v2/users", () => {
|
||||||
created: mockedTime.toISOString(),
|
created: mockedTime.toISOString(),
|
||||||
lastModified: mockedTime.toISOString(),
|
lastModified: mockedTime.toISOString(),
|
||||||
},
|
},
|
||||||
userName: `${userData.firstName} ${userData.lastName}`,
|
userName: userData.username,
|
||||||
name: {
|
name: {
|
||||||
formatted: `${userData.firstName} ${userData.lastName}`,
|
formatted: `${userData.firstName} ${userData.lastName}`,
|
||||||
familyName: userData.lastName,
|
familyName: userData.lastName,
|
||||||
|
@ -255,20 +258,35 @@ describe("/api/global/scim/v2/users", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("an existing user can be updated", async () => {
|
it("an existing user can be updated", async () => {
|
||||||
|
const newUserName = structures.generator.name()
|
||||||
|
const newFamilyName = structures.generator.last()
|
||||||
const body: ScimUpdateRequest = {
|
const body: ScimUpdateRequest = {
|
||||||
schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
|
schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
|
||||||
Operations: [
|
Operations: [
|
||||||
{
|
{
|
||||||
op: "add",
|
op: "Replace",
|
||||||
path: "string",
|
path: "userName",
|
||||||
value: "string",
|
value: newUserName,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Replace",
|
||||||
|
path: "name.familyName",
|
||||||
|
value: newFamilyName,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await patchScimUser({ id: user.id, body })
|
const response = await patchScimUser({ id: user.id, body })
|
||||||
|
|
||||||
const expectedScimUser = { ...user }
|
const expectedScimUser: ScimUser = {
|
||||||
|
...user,
|
||||||
|
userName: newUserName,
|
||||||
|
name: {
|
||||||
|
...user.name,
|
||||||
|
familyName: newFamilyName,
|
||||||
|
formatted: `${user.name.givenName} ${newFamilyName}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
expect(response).toEqual(expectedScimUser)
|
expect(response).toEqual(expectedScimUser)
|
||||||
|
|
||||||
const persistedUser = await config.api.scimUsersAPI.find(user.id)
|
const persistedUser = await config.api.scimUsersAPI.find(user.id)
|
||||||
|
|
Loading…
Reference in New Issue