mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
068c55a925
<!-- 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 # [1-743](https://linear.app/unleash/issue/1-743/add-cypress-test-for-notifications-happy-path) <!-- (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>
138 lines
4.0 KiB
TypeScript
138 lines
4.0 KiB
TypeScript
/// <reference types="cypress" />
|
|
|
|
type UserCredentials = { email: string; password: string };
|
|
const ENTERPRISE = Boolean(Cypress.env('ENTERPRISE'));
|
|
const randomId = String(Math.random()).split('.')[1];
|
|
const featureToggleName = `notifications_test-${randomId}`;
|
|
const baseUrl = Cypress.config().baseUrl;
|
|
let strategyId = '';
|
|
const userIds: number[] = [];
|
|
const userCredentials: UserCredentials[] = [];
|
|
const userName = `notifications_user-${randomId}`;
|
|
const projectName = `default`;
|
|
const password = Cypress.env(`AUTH_PASSWORD`) + '_A';
|
|
const EDITOR = 2;
|
|
const PROJECT_MEMBER = 5;
|
|
|
|
// Disable all active splash pages by visiting them.
|
|
const disableActiveSplashScreens = () => {
|
|
cy.visit(`/splash/operators`);
|
|
};
|
|
|
|
const createUser = () => {
|
|
const name = `${userName}`;
|
|
const email = `${name}@test.com`;
|
|
cy.request('POST', `${baseUrl}/api/admin/user-admin`, {
|
|
name: name,
|
|
email: `${name}@test.com`,
|
|
username: `${name}@test.com`,
|
|
sendEmail: false,
|
|
rootRole: EDITOR,
|
|
})
|
|
.as(name)
|
|
.then(response => {
|
|
const id = response.body.id;
|
|
updateUserPassword(id).then(() => {
|
|
addUserToProject(id).then(() => {
|
|
userIds.push(id);
|
|
userCredentials.push({ email, password });
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
const updateUserPassword = async (id: number) => {
|
|
cy.request(
|
|
'POST',
|
|
`${baseUrl}/api/admin/user-admin/${id}/change-password`,
|
|
{
|
|
password,
|
|
}
|
|
);
|
|
};
|
|
|
|
const addUserToProject = async (id: number) => {
|
|
cy.request(
|
|
'POST',
|
|
`${baseUrl}/api/admin/projects/${projectName}/role/${PROJECT_MEMBER}/access`,
|
|
{
|
|
groups: [],
|
|
users: [{ id }],
|
|
}
|
|
);
|
|
};
|
|
|
|
describe('notifications', () => {
|
|
before(() => {
|
|
disableActiveSplashScreens();
|
|
cy.login();
|
|
createUser();
|
|
});
|
|
|
|
after(() => {
|
|
// We need to login as admin for cleanup
|
|
cy.login();
|
|
userIds.forEach(id =>
|
|
cy.request('DELETE', `${baseUrl}/api/admin/user-admin/${id}`)
|
|
);
|
|
|
|
cy.request(
|
|
'DELETE',
|
|
`${baseUrl}/api/admin/features/${featureToggleName}`
|
|
);
|
|
});
|
|
|
|
beforeEach(() => {
|
|
cy.login();
|
|
cy.visit(`/projects/${projectName}`);
|
|
if (document.querySelector("[data-testid='CLOSE_SPLASH']")) {
|
|
cy.get("[data-testid='CLOSE_SPLASH']").click();
|
|
}
|
|
});
|
|
|
|
afterEach(() => {
|
|
cy.logout();
|
|
});
|
|
|
|
const createFeature = () => {
|
|
cy.get('[data-testid=NAVIGATE_TO_CREATE_FEATURE').click();
|
|
|
|
cy.intercept('POST', `/api/admin/projects/${projectName}/features`).as(
|
|
'createFeature'
|
|
);
|
|
|
|
cy.get("[data-testid='CF_NAME_ID'").type(featureToggleName);
|
|
cy.get("[data-testid='CF_DESC_ID'").type('hello-world');
|
|
cy.get("[data-testid='CF_CREATE_BTN_ID']").click();
|
|
cy.wait('@createFeature');
|
|
};
|
|
|
|
it('should create a notification when a feature is created in a project', () => {
|
|
createFeature();
|
|
|
|
//Should not show own notifications
|
|
cy.get("[data-testid='NOTIFICATIONS_BUTTON']").click();
|
|
|
|
//then
|
|
cy.get("[data-testid='NOTIFICATIONS_MODAL']").should('exist');
|
|
cy.get("[data-testid='UNREAD_NOTIFICATIONS']").should('not.exist');
|
|
|
|
const credentials = userCredentials[0];
|
|
|
|
//Sign in as a different user
|
|
cy.login(credentials.email, credentials.password);
|
|
cy.visit(`/projects/${projectName}`);
|
|
if (document.querySelector("[data-testid='CLOSE_SPLASH']")) {
|
|
cy.get("[data-testid='CLOSE_SPLASH']").click();
|
|
}
|
|
cy.get("[data-testid='NOTIFICATIONS_BUTTON']").click();
|
|
|
|
//then
|
|
cy.get("[data-testid='UNREAD_NOTIFICATIONS']").should('exist');
|
|
cy.get("[data-testid='NOTIFICATIONS_LIST']")
|
|
.should('have.length', 1)
|
|
.eq(0)
|
|
.should('contain.text', 'New feature');
|
|
});
|
|
});
|