aboutsummaryrefslogtreecommitdiff
path: root/cypress/e2e/api-website.cy.ts
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/e2e/api-website.cy.ts
downloadumami-main.tar.xz
umami-main.zip
Initial commitHEADmain
Created from https://vercel.com/new
Diffstat (limited to 'cypress/e2e/api-website.cy.ts')
-rw-r--r--cypress/e2e/api-website.cy.ts198
1 files changed, 198 insertions, 0 deletions
diff --git a/cypress/e2e/api-website.cy.ts b/cypress/e2e/api-website.cy.ts
new file mode 100644
index 0000000..cd336bd
--- /dev/null
+++ b/cypress/e2e/api-website.cy.ts
@@ -0,0 +1,198 @@
+import { uuid } from '../../src/lib/crypto';
+
+describe('Website API tests', () => {
+ Cypress.session.clearAllSavedSessions();
+
+ let websiteId;
+ let teamId;
+
+ before(() => {
+ cy.login(Cypress.env('umami_user'), Cypress.env('umami_password'));
+ cy.fixture('teams').then(data => {
+ const teamCreate = data.teamCreate;
+ cy.request({
+ method: 'POST',
+ url: '/api/teams',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: teamCreate,
+ }).then(response => {
+ teamId = response.body[0].id;
+ expect(response.status).to.eq(200);
+ expect(response.body[0]).to.have.property('name', 'cypress');
+ expect(response.body[1]).to.have.property('role', 'team-owner');
+ });
+ });
+ });
+
+ it('Creates a website for user.', () => {
+ cy.fixture('websites').then(data => {
+ const websiteCreate = data.websiteCreate;
+ cy.request({
+ method: 'POST',
+ url: '/api/websites',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: websiteCreate,
+ }).then(response => {
+ websiteId = response.body.id;
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('name', 'Cypress Website');
+ expect(response.body).to.have.property('domain', 'cypress.com');
+ });
+ });
+ });
+
+ it('Creates a website for team.', () => {
+ cy.request({
+ method: 'POST',
+ url: '/api/websites',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: {
+ name: 'Team Website',
+ domain: 'teamwebsite.com',
+ teamId: teamId,
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('name', 'Team Website');
+ expect(response.body).to.have.property('domain', 'teamwebsite.com');
+ });
+ });
+
+ it('Creates a website with a fixed ID.', () => {
+ cy.fixture('websites').then(data => {
+ const websiteCreate = data.websiteCreate;
+ const fixedId = uuid();
+ cy.request({
+ method: 'POST',
+ url: '/api/websites',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: { ...websiteCreate, id: fixedId },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('id', fixedId);
+ expect(response.body).to.have.property('name', 'Cypress Website');
+ expect(response.body).to.have.property('domain', 'cypress.com');
+
+ // cleanup
+ cy.request({
+ method: 'DELETE',
+ url: `/api/websites/${fixedId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ });
+ });
+ });
+ });
+
+ it('Returns all tracked websites.', () => {
+ cy.request({
+ method: 'GET',
+ url: '/api/websites',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body.data[0]).to.have.property('id');
+ expect(response.body.data[0]).to.have.property('name');
+ expect(response.body.data[0]).to.have.property('domain');
+ });
+ });
+
+ it('Gets a website by ID.', () => {
+ cy.request({
+ method: 'GET',
+ url: `/api/websites/${websiteId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('name', 'Cypress Website');
+ expect(response.body).to.have.property('domain', 'cypress.com');
+ });
+ });
+
+ it('Updates a website.', () => {
+ cy.fixture('websites').then(data => {
+ const websiteUpdate = data.websiteUpdate;
+ cy.request({
+ method: 'POST',
+ url: `/api/websites/${websiteId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: websiteUpdate,
+ }).then(response => {
+ websiteId = response.body.id;
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('name', 'Cypress Website Updated');
+ expect(response.body).to.have.property('domain', 'cypressupdated.com');
+ });
+ });
+ });
+
+ it('Updates a website with only shareId.', () => {
+ cy.request({
+ method: 'POST',
+ url: `/api/websites/${websiteId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: { shareId: 'ABCDEF' },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('shareId', 'ABCDEF');
+ });
+ });
+
+ it('Resets a website by removing all data related to the website.', () => {
+ cy.request({
+ method: 'POST',
+ url: `/api/websites/${websiteId}/reset`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('ok', true);
+ });
+ });
+
+ it('Deletes a website.', () => {
+ 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);
+ expect(response.body).to.have.property('ok', true);
+ });
+ });
+
+ after(() => {
+ cy.deleteTeam(teamId);
+ });
+});