2023-04-04 10:46:28 +02:00
|
|
|
///<reference path="../global.d.ts" />
|
|
|
|
|
|
|
|
import Chainable = Cypress.Chainable;
|
|
|
|
const baseUrl = Cypress.config().baseUrl;
|
2023-10-02 14:25:46 +02:00
|
|
|
const password = `${Cypress.env(`AUTH_PASSWORD`)}_A`;
|
2023-04-04 10:46:28 +02:00
|
|
|
const PROJECT_MEMBER = 5;
|
|
|
|
export const createFeature_API = (
|
|
|
|
featureName: string,
|
2023-05-08 10:16:18 +02:00
|
|
|
projectName?: string,
|
2023-10-02 14:25:46 +02:00
|
|
|
options?: Partial<Cypress.RequestOptions>,
|
2023-04-04 10:46:28 +02:00
|
|
|
): Chainable<any> => {
|
|
|
|
const project = projectName || 'default';
|
|
|
|
return cy.request({
|
2023-05-08 10:16:18 +02:00
|
|
|
url: `${baseUrl}/api/admin/projects/${project}/features`,
|
2023-04-04 10:46:28 +02:00
|
|
|
method: 'POST',
|
|
|
|
body: {
|
|
|
|
name: `${featureName}`,
|
|
|
|
description: 'hello-world',
|
|
|
|
type: 'release',
|
|
|
|
impressionData: false,
|
|
|
|
},
|
2023-05-08 10:16:18 +02:00
|
|
|
...options,
|
2023-04-04 10:46:28 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteFeature_API = (name: string): Chainable<any> => {
|
|
|
|
cy.request({
|
|
|
|
method: 'DELETE',
|
2023-04-27 10:49:55 +02:00
|
|
|
url: `${baseUrl}/api/admin/projects/default/features/${name}`,
|
2023-04-04 10:46:28 +02:00
|
|
|
});
|
|
|
|
return cy.request({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `${baseUrl}/api/admin/archive/${name}`,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-05-08 10:16:18 +02:00
|
|
|
export const createProject_API = (
|
|
|
|
project: string,
|
2023-10-02 14:25:46 +02:00
|
|
|
options?: Partial<Cypress.RequestOptions>,
|
2023-05-08 10:16:18 +02:00
|
|
|
): Chainable<any> => {
|
2023-04-04 10:46:28 +02:00
|
|
|
return cy.request({
|
2023-05-08 10:16:18 +02:00
|
|
|
url: `${baseUrl}/api/admin/projects`,
|
2023-04-04 10:46:28 +02:00
|
|
|
method: 'POST',
|
|
|
|
body: {
|
|
|
|
id: project,
|
|
|
|
name: project,
|
|
|
|
description: project,
|
|
|
|
impressionData: false,
|
|
|
|
},
|
2023-05-08 10:16:18 +02:00
|
|
|
...options,
|
2023-04-04 10:46:28 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteProject_API = (name: string): Chainable<any> => {
|
|
|
|
return cy.request({
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `${baseUrl}/api/admin/projects/${name}`,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createUser_API = (userName: string, role: number) => {
|
|
|
|
const name = `${userName}`;
|
|
|
|
const email = `${name}@test.com`;
|
|
|
|
const userIds: number[] = [];
|
|
|
|
const userCredentials: Cypress.UserCredentials[] = [];
|
|
|
|
cy.request('POST', `${baseUrl}/api/admin/user-admin`, {
|
|
|
|
name: name,
|
|
|
|
email: `${name}@test.com`,
|
|
|
|
username: `${name}@test.com`,
|
|
|
|
sendEmail: false,
|
|
|
|
rootRole: role,
|
|
|
|
})
|
|
|
|
.as(name)
|
2023-10-02 14:25:46 +02:00
|
|
|
.then((response) => {
|
2023-04-04 10:46:28 +02:00
|
|
|
const id = response.body.id;
|
|
|
|
updateUserPassword_API(id).then(() => {
|
2023-10-02 14:25:46 +02:00
|
|
|
addUserToProject_API(id, PROJECT_MEMBER).then((value) => {
|
2023-04-04 10:46:28 +02:00
|
|
|
userIds.push(id);
|
|
|
|
userCredentials.push({ email, password });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return cy.wrap({ userIds, userCredentials });
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateUserPassword_API = (id: number, pass?: string): Chainable =>
|
|
|
|
cy.request(
|
|
|
|
'POST',
|
|
|
|
`${baseUrl}/api/admin/user-admin/${id}/change-password`,
|
|
|
|
{
|
|
|
|
password: pass || password,
|
2023-10-02 14:25:46 +02:00
|
|
|
},
|
2023-04-04 10:46:28 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
export const addUserToProject_API = (
|
|
|
|
id: number,
|
|
|
|
role: number,
|
2023-10-02 14:25:46 +02:00
|
|
|
projectName?: string,
|
2023-04-04 10:46:28 +02:00
|
|
|
): Chainable => {
|
|
|
|
const project = projectName || 'default';
|
|
|
|
return cy.request(
|
|
|
|
'POST',
|
|
|
|
`${baseUrl}/api/admin/projects/${project}/role/${role}/access`,
|
|
|
|
{
|
|
|
|
groups: [],
|
|
|
|
users: [{ id }],
|
2023-10-02 14:25:46 +02:00
|
|
|
},
|
2023-04-04 10:46:28 +02:00
|
|
|
);
|
|
|
|
};
|
2023-05-08 10:16:18 +02:00
|
|
|
|
|
|
|
interface IEnvironment {
|
|
|
|
name: string;
|
|
|
|
type: 'development' | 'preproduction' | 'test' | 'production';
|
|
|
|
}
|
|
|
|
|
|
|
|
export const createEnvironment_API = (
|
|
|
|
environment: IEnvironment,
|
2023-10-02 14:25:46 +02:00
|
|
|
options?: Partial<Cypress.RequestOptions>,
|
2023-05-08 10:16:18 +02:00
|
|
|
): Chainable<any> => {
|
|
|
|
return cy.request({
|
|
|
|
url: `${baseUrl}/api/admin/environments`,
|
|
|
|
method: 'POST',
|
|
|
|
body: environment,
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|