aboutsummaryrefslogtreecommitdiff
path: root/cypress/support
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-24 13:09:50 +0000
committerFuwn <[email protected]>2026-01-24 13:09:50 +0000
commit396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch)
treeb9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /cypress/support
downloadumami-main.tar.xz
umami-main.zip
Initial commitHEADmain
Created from https://vercel.com/new
Diffstat (limited to 'cypress/support')
-rw-r--r--cypress/support/e2e.ts123
-rw-r--r--cypress/support/index.d.ts56
2 files changed, 179 insertions, 0 deletions
diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts
new file mode 100644
index 0000000..a95035b
--- /dev/null
+++ b/cypress/support/e2e.ts
@@ -0,0 +1,123 @@
+/// <reference types="cypress" />
+import { uuid } from '../../src/lib/crypto';
+
+Cypress.Commands.add('getDataTest', (value: string) => {
+ return cy.get(`[data-test=${value}]`);
+});
+
+Cypress.Commands.add('logout', () => {
+ cy.getDataTest('button-profile').click();
+ cy.getDataTest('item-logout').click();
+ cy.url().should('eq', Cypress.config().baseUrl + '/login');
+});
+
+Cypress.Commands.add('login', (username: string, password: string) => {
+ cy.session([username, password], () => {
+ cy.request({
+ method: 'POST',
+ url: '/api/auth/login',
+ body: {
+ username,
+ password,
+ },
+ })
+ .then(response => {
+ Cypress.env('authorization', `bearer ${response.body.token}`);
+ window.localStorage.setItem('umami.auth', JSON.stringify(response.body.token));
+ })
+ .its('status')
+ .should('eq', 200);
+ });
+});
+
+Cypress.Commands.add('addWebsite', (name: string, domain: string) => {
+ cy.request({
+ method: 'POST',
+ url: '/api/websites',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: {
+ id: uuid(),
+ createdBy: '41e2b680-648e-4b09-bcd7-3e2b10c06264',
+ name: name,
+ domain: domain,
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ });
+});
+
+Cypress.Commands.add('deleteWebsite', (websiteId: string) => {
+ cy.request({
+ method: 'DELETE',
+ url: `/api/websites/${websiteId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ });
+});
+
+Cypress.Commands.add('addUser', (username: string, password: string, role: string) => {
+ cy.request({
+ method: 'POST',
+ url: '/api/users',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: {
+ username: username,
+ password: password,
+ role: role,
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ });
+});
+
+Cypress.Commands.add('deleteUser', (userId: string) => {
+ cy.request({
+ method: 'DELETE',
+ url: `/api/users/${userId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ });
+});
+
+Cypress.Commands.add('addTeam', (name: string) => {
+ cy.request({
+ method: 'POST',
+ url: '/api/teams',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: {
+ name: name,
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ });
+});
+
+Cypress.Commands.add('deleteTeam', (teamId: string) => {
+ cy.request({
+ method: 'DELETE',
+ url: `/api/teams/${teamId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ });
+});
diff --git a/cypress/support/index.d.ts b/cypress/support/index.d.ts
new file mode 100644
index 0000000..b630269
--- /dev/null
+++ b/cypress/support/index.d.ts
@@ -0,0 +1,56 @@
+/// <reference types="cypress" />
+/* global JQuery */
+
+declare namespace Cypress {
+ interface Chainable {
+ /**
+ * Custom command to select DOM element by data-test attribute.
+ * @example cy.getDataTest('greeting')
+ */
+ getDataTest(value: string): Chainable<JQuery<HTMLElement>>;
+ /**
+ * Custom command to logout through UI.
+ * @example cy.logout()
+ */
+ logout(): Chainable<JQuery<HTMLElement>>;
+ /**
+ * Custom command to login user into the app.
+ * @example cy.login('admin', 'password)
+ */
+ login(username: string, password: string): Chainable<JQuery<HTMLElement>>;
+ /**
+ * Custom command to create a website
+ * @example cy.addWebsite('test', 'test.com')
+ */
+ addWebsite(name: string, domain: string): Chainable<JQuery<HTMLElement>>;
+ /**
+ * Custom command to delete a website
+ * @example cy.deleteWebsite('02d89813-7a72-41e1-87f0-8d668f85008b')
+ */
+ deleteWebsite(websiteId: string): Chainable<JQuery<HTMLElement>>;
+ /**
+ * Custom command to create a website
+ * @example cy.deleteWebsite('02d89813-7a72-41e1-87f0-8d668f85008b')
+ */
+ /**
+ * Custom command to create a user
+ * @example cy.addUser('cypress', 'password', 'User')
+ */
+ addUser(username: string, password: string, role: string): Chainable<JQuery<HTMLElement>>;
+ /**
+ * Custom command to delete a user
+ * @example cy.deleteUser('02d89813-7a72-41e1-87f0-8d668f85008b')
+ */
+ deleteUser(userId: string): Chainable<JQuery<HTMLElement>>;
+ /**
+ * Custom command to create a team
+ * @example cy.addTeam('cypressTeam')
+ */
+ addTeam(name: string): Chainable<JQuery<HTMLElement>>;
+ /**
+ * Custom command to create a website
+ * @example cy.deleteTeam('02d89813-7a72-41e1-87f0-8d668f85008b')
+ */
+ deleteTeam(teamId: string): Chainable<JQuery<HTMLElement>>;
+ }
+}