mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
99c555bf59
Adds proper typescript support. Created reusable commands Added README for cypress test Refactored tests Fixed bugs as I found them. <!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> ## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> <!-- Does it close an issue? Multiple? --> Closes # <!-- (For internal contributors): Does it relate to an issue on public roadmap? --> <!-- Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: # --> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? --> --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
104 lines
2.8 KiB
TypeScript
104 lines
2.8 KiB
TypeScript
///<reference path="../global.d.ts" />
|
|
|
|
import Chainable = Cypress.Chainable;
|
|
const baseUrl = Cypress.config().baseUrl;
|
|
const password = Cypress.env(`AUTH_PASSWORD`) + '_A';
|
|
const PROJECT_MEMBER = 5;
|
|
export const createFeature_API = (
|
|
featureName: string,
|
|
projectName?: string
|
|
): Chainable<any> => {
|
|
const project = projectName || 'default';
|
|
return cy.request({
|
|
url: `/api/admin/projects/${project}/features`,
|
|
method: 'POST',
|
|
body: {
|
|
name: `${featureName}`,
|
|
description: 'hello-world',
|
|
type: 'release',
|
|
impressionData: false,
|
|
},
|
|
});
|
|
};
|
|
|
|
export const deleteFeature_API = (name: string): Chainable<any> => {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `${baseUrl}/api/admin/features/${name}`,
|
|
});
|
|
return cy.request({
|
|
method: 'DELETE',
|
|
url: `${baseUrl}/api/admin/archive/${name}`,
|
|
});
|
|
};
|
|
|
|
export const createProject_API = (project: string): Chainable<any> => {
|
|
return cy.request({
|
|
url: `/api/admin/projects`,
|
|
method: 'POST',
|
|
body: {
|
|
id: project,
|
|
name: project,
|
|
description: project,
|
|
impressionData: false,
|
|
},
|
|
});
|
|
};
|
|
|
|
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)
|
|
.then(response => {
|
|
const id = response.body.id;
|
|
updateUserPassword_API(id).then(() => {
|
|
addUserToProject_API(id, PROJECT_MEMBER).then(value => {
|
|
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,
|
|
}
|
|
);
|
|
|
|
export const addUserToProject_API = (
|
|
id: number,
|
|
role: number,
|
|
projectName?: string
|
|
): Chainable => {
|
|
const project = projectName || 'default';
|
|
return cy.request(
|
|
'POST',
|
|
`${baseUrl}/api/admin/projects/${project}/role/${role}/access`,
|
|
{
|
|
groups: [],
|
|
users: [{ id }],
|
|
}
|
|
);
|
|
};
|