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';
|
2023-02-14 08:31:32 +00:00
|
|
|
import { requestHeaders } from './apiauth';
|
2023-02-15 01:52:11 +00:00
|
|
|
import { Context } from 'support/commands';
|
2022-10-11 13:29:23 +00:00
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function ensureOrgExists(ctx: Context, name: string) {
|
2022-10-11 13:29:23 +00:00
|
|
|
return ensureSomething(
|
2023-02-15 01:52:11 +00:00
|
|
|
ctx.api,
|
2022-10-11 13:29:23 +00:00
|
|
|
() =>
|
|
|
|
searchSomething(
|
2023-02-15 01:52:11 +00:00
|
|
|
ctx.api,
|
|
|
|
encodeURI(`${ctx.api.mgmtBaseURL}/global/orgs/_by_domain?domain=${name}.${host(Cypress.config('baseUrl'))}`),
|
2022-10-11 13:29:23 +00:00
|
|
|
'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
|
|
|
},
|
|
|
|
),
|
2023-02-15 01:52:11 +00:00
|
|
|
() => `${ctx.api.mgmtBaseURL}/orgs`,
|
2022-10-11 13:29:23 +00:00
|
|
|
'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,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function isDefaultOrg(ctx: Context, orgId: string): Cypress.Chainable<boolean> {
|
2023-02-14 08:31:32 +00:00
|
|
|
console.log('huhu', orgId);
|
|
|
|
return cy
|
|
|
|
.request({
|
|
|
|
method: 'GET',
|
2023-02-15 01:52:11 +00:00
|
|
|
url: encodeURI(`${ctx.api.mgmtBaseURL}/iam`),
|
|
|
|
headers: requestHeaders(ctx.api, orgId),
|
2023-02-14 08:31:32 +00:00
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
const { defaultOrgId } = res.body;
|
|
|
|
expect(defaultOrgId).to.equal(orgId);
|
|
|
|
return defaultOrgId === orgId;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function ensureOrgIsDefault(ctx: Context, orgId: string): Cypress.Chainable<boolean> {
|
2023-02-14 08:31:32 +00:00
|
|
|
return cy
|
|
|
|
.request({
|
|
|
|
method: 'GET',
|
2023-02-15 01:52:11 +00:00
|
|
|
url: encodeURI(`${ctx.api.mgmtBaseURL}/iam`),
|
|
|
|
headers: requestHeaders(ctx.api, orgId),
|
2023-02-14 08:31:32 +00:00
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
return res.body;
|
|
|
|
})
|
|
|
|
.then(({ defaultOrgId }) => {
|
|
|
|
if (defaultOrgId === orgId) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return cy
|
|
|
|
.request({
|
|
|
|
method: 'PUT',
|
2023-02-15 01:52:11 +00:00
|
|
|
url: `${ctx.api.adminBaseURL}/orgs/default/${orgId}`,
|
|
|
|
headers: requestHeaders(ctx.api, orgId),
|
2023-02-14 08:31:32 +00:00
|
|
|
failOnStatusCode: true,
|
|
|
|
followRedirect: false,
|
|
|
|
})
|
|
|
|
.then((cRes) => {
|
|
|
|
expect(cRes.status).to.equal(200);
|
|
|
|
return !!cRes.body;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function getOrgUnderTest(ctx: Context): Cypress.Chainable<number> {
|
|
|
|
return searchSomething(ctx.api, `${ctx.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);
|
|
|
|
}
|