Name and its fields are optional
This commit is contained in:
parent
2e60ca7526
commit
f882993091
|
@ -1,23 +1,31 @@
|
|||
import { ScimCreateGroupRequest, ScimCreateUserRequest } from "@budibase/types"
|
||||
import { uuid } from "./common"
|
||||
import { generator } from "./generator"
|
||||
import _ from "lodash"
|
||||
|
||||
export function createUserRequest(userData?: {
|
||||
externalId?: string
|
||||
email?: string
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
username?: string
|
||||
}) {
|
||||
const {
|
||||
externalId = uuid(),
|
||||
email = generator.email(),
|
||||
firstName = generator.first(),
|
||||
lastName = generator.last(),
|
||||
username = generator.name(),
|
||||
} = userData || {}
|
||||
interface CreateUserRequestFields {
|
||||
externalId: string
|
||||
email: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
username: string
|
||||
}
|
||||
|
||||
const user: ScimCreateUserRequest = {
|
||||
export function createUserRequest(userData?: Partial<CreateUserRequestFields>) {
|
||||
const defaultValues = {
|
||||
externalId: uuid(),
|
||||
email: generator.email(),
|
||||
firstName: generator.first(),
|
||||
lastName: generator.last(),
|
||||
username: generator.name(),
|
||||
}
|
||||
|
||||
const { externalId, email, firstName, lastName, username } = _.assign(
|
||||
defaultValues,
|
||||
userData
|
||||
)
|
||||
|
||||
let user: ScimCreateUserRequest = {
|
||||
schemas: [
|
||||
"urn:ietf:params:scim:schemas:core:2.0:User",
|
||||
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
|
||||
|
@ -35,13 +43,17 @@ export function createUserRequest(userData?: {
|
|||
meta: {
|
||||
resourceType: "User",
|
||||
},
|
||||
name: {
|
||||
formatted: generator.name(),
|
||||
familyName: lastName,
|
||||
givenName: firstName,
|
||||
},
|
||||
roles: [],
|
||||
}
|
||||
|
||||
if (firstName || lastName) {
|
||||
user.name = {
|
||||
formatted: [firstName, lastName].filter(s => s).join(" "),
|
||||
familyName: lastName,
|
||||
givenName: firstName,
|
||||
}
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@ export interface ScimUserResponse extends ScimResource {
|
|||
}
|
||||
userName: string
|
||||
displayName?: string
|
||||
name: {
|
||||
formatted: string
|
||||
familyName: string
|
||||
givenName: string
|
||||
name?: {
|
||||
formatted?: string
|
||||
familyName?: string
|
||||
givenName?: string
|
||||
}
|
||||
active: BooleanString
|
||||
emails?: Emails
|
||||
|
@ -41,7 +41,7 @@ export interface ScimCreateUserRequest {
|
|||
resourceType: "User"
|
||||
}
|
||||
displayName?: string
|
||||
name: {
|
||||
name?: {
|
||||
formatted: string
|
||||
familyName: string
|
||||
givenName: string
|
||||
|
|
|
@ -255,6 +255,45 @@ describe("scim", () => {
|
|||
)
|
||||
})
|
||||
|
||||
it("a new user can minim information", async () => {
|
||||
const userData = {
|
||||
externalId: structures.uuid(),
|
||||
email: structures.generator.email(),
|
||||
username: structures.generator.name(),
|
||||
firstName: undefined,
|
||||
lastName: undefined,
|
||||
}
|
||||
const body = structures.scim.createUserRequest(userData)
|
||||
|
||||
const response = await postScimUser({ body })
|
||||
|
||||
const expectedScimUser = {
|
||||
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
|
||||
id: expect.any(String),
|
||||
externalId: userData.externalId,
|
||||
meta: {
|
||||
resourceType: "User",
|
||||
created: mocks.date.MOCK_DATE.toISOString(),
|
||||
lastModified: mocks.date.MOCK_DATE.toISOString(),
|
||||
},
|
||||
userName: userData.username,
|
||||
active: true,
|
||||
emails: [
|
||||
{
|
||||
value: userData.email,
|
||||
type: "work",
|
||||
primary: true,
|
||||
},
|
||||
],
|
||||
}
|
||||
expect(response).toEqual(expectedScimUser)
|
||||
|
||||
const persistedUsers = await config.api.scimUsersAPI.get()
|
||||
expect(persistedUsers.Resources).toEqual(
|
||||
expect.arrayContaining([expectedScimUser])
|
||||
)
|
||||
})
|
||||
|
||||
it("an event is dispatched", async () => {
|
||||
const body = structures.scim.createUserRequest()
|
||||
|
||||
|
@ -398,7 +437,7 @@ describe("scim", () => {
|
|||
name: {
|
||||
...user.name,
|
||||
familyName: newFamilyName,
|
||||
formatted: `${user.name.givenName} ${newFamilyName}`,
|
||||
formatted: `${user.name!.givenName} ${newFamilyName}`,
|
||||
},
|
||||
}
|
||||
expect(response).toEqual(expectedScimUser)
|
||||
|
|
Loading…
Reference in New Issue