2022-10-11 13:29:23 +00:00
|
|
|
import { ensureSomething } from './ensure';
|
|
|
|
import { searchSomething } from './search';
|
|
|
|
import { API } from './types';
|
|
|
|
import { host } from '../login/users';
|
|
|
|
|
|
|
|
export function ensureOrgExists(api: API, name: string): Cypress.Chainable<number> {
|
|
|
|
return ensureSomething(
|
|
|
|
api,
|
|
|
|
() =>
|
|
|
|
searchSomething(
|
|
|
|
api,
|
|
|
|
encodeURI(`${api.mgmtBaseURL}/global/orgs/_by_domain?domain=${name}.${host(Cypress.config('baseUrl'))}`),
|
|
|
|
'GET',
|
|
|
|
(res) => {
|
2022-12-22 11:16:17 +00:00
|
|
|
return { entity: res.org, id: res.org?.id, sequence: parseInt(<string>res.org?.details?.sequence) };
|
2022-10-11 13:29:23 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
() => `${api.mgmtBaseURL}/orgs`,
|
|
|
|
'POST',
|
|
|
|
{ name: name },
|
2022-10-20 12:08:13 +00:00
|
|
|
(org) => org?.name === name,
|
2022-10-11 13:29:23 +00:00
|
|
|
(res) => res.id,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getOrgUnderTest(api: API): Cypress.Chainable<number> {
|
|
|
|
return searchSomething(api, `${api.mgmtBaseURL}/orgs/me`, 'GET', (res) => {
|
2022-12-22 11:16:17 +00:00
|
|
|
return { entity: res.org, id: res.org.id, sequence: parseInt(<string>res.org.details.sequence) };
|
2022-10-11 13:29:23 +00:00
|
|
|
}).then((res) => res.entity.id);
|
|
|
|
}
|