2023-02-15 02:52:11 +01:00
|
|
|
import { requestHeaders } from './apiauth';
|
2022-10-11 15:29:23 +02:00
|
|
|
import { ensureItemDoesntExist, ensureItemExists } from './ensure';
|
|
|
|
import { API } from './types';
|
2022-04-28 12:35:02 +02:00
|
|
|
|
2023-02-15 02:52:11 +01:00
|
|
|
export function ensureHumanUserExists(api: API, username: string) {
|
2022-10-11 15:29:23 +02:00
|
|
|
return ensureItemExists(
|
|
|
|
api,
|
|
|
|
`${api.mgmtBaseURL}/users/_search`,
|
|
|
|
(user: any) => user.userName === username,
|
|
|
|
`${api.mgmtBaseURL}/users/human`,
|
|
|
|
{
|
2023-02-15 02:52:11 +01:00
|
|
|
...defaultHuman,
|
2022-10-11 15:29:23 +02:00
|
|
|
user_name: username,
|
2022-09-19 19:49:46 +02:00
|
|
|
},
|
2022-10-11 15:29:23 +02:00
|
|
|
undefined,
|
|
|
|
'userId',
|
|
|
|
);
|
2022-04-28 12:35:02 +02:00
|
|
|
}
|
|
|
|
|
2023-02-15 02:52:11 +01:00
|
|
|
export function ensureMachineUserExists(api: API, username: string) {
|
2022-10-11 15:29:23 +02:00
|
|
|
return ensureItemExists(
|
|
|
|
api,
|
|
|
|
`${api.mgmtBaseURL}/users/_search`,
|
|
|
|
(user: any) => user.userName === username,
|
|
|
|
`${api.mgmtBaseURL}/users/machine`,
|
|
|
|
{
|
|
|
|
user_name: username,
|
|
|
|
name: 'e2emachinename',
|
|
|
|
description: 'e2emachinedescription',
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
'userId',
|
|
|
|
);
|
2022-04-28 12:35:02 +02:00
|
|
|
}
|
|
|
|
|
2023-02-15 02:52:11 +01:00
|
|
|
export function ensureUserDoesntExist(api: API, username: string) {
|
2022-10-11 15:29:23 +02:00
|
|
|
return ensureItemDoesntExist(
|
2022-09-19 19:49:46 +02:00
|
|
|
api,
|
2022-10-11 15:29:23 +02:00
|
|
|
`${api.mgmtBaseURL}/users/_search`,
|
2022-09-19 19:49:46 +02:00
|
|
|
(user: any) => user.userName === username,
|
2022-10-11 15:29:23 +02:00
|
|
|
(user) => `${api.mgmtBaseURL}/users/${user.id}`,
|
2022-09-19 19:49:46 +02:00
|
|
|
);
|
2022-04-28 12:35:02 +02:00
|
|
|
}
|
2023-02-15 02:52:11 +01:00
|
|
|
|
|
|
|
export function createHumanUser(api: API, username: string, failOnStatusCode = true) {
|
|
|
|
return cy.request({
|
|
|
|
method: 'POST',
|
|
|
|
url: `${api.mgmtBaseURL}/users/human`,
|
|
|
|
body: {
|
|
|
|
...defaultHuman,
|
|
|
|
user_name: username,
|
|
|
|
},
|
|
|
|
auth: {
|
|
|
|
bearer: api.token,
|
|
|
|
},
|
|
|
|
failOnStatusCode: failOnStatusCode,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultHuman = {
|
|
|
|
profile: {
|
|
|
|
first_name: 'e2efirstName',
|
|
|
|
last_name: 'e2elastName',
|
|
|
|
},
|
|
|
|
email: {
|
|
|
|
email: 'e2e@email.ch',
|
|
|
|
},
|
|
|
|
phone: {
|
|
|
|
phone: '+41 123456789',
|
|
|
|
},
|
|
|
|
};
|