aboutsummaryrefslogtreecommitdiff
path: root/cypress/e2e/api-user.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-user.cy.ts
downloadumami-main.tar.xz
umami-main.zip
Initial commitHEADmain
Created from https://vercel.com/new
Diffstat (limited to 'cypress/e2e/api-user.cy.ts')
-rw-r--r--cypress/e2e/api-user.cy.ts125
1 files changed, 125 insertions, 0 deletions
diff --git a/cypress/e2e/api-user.cy.ts b/cypress/e2e/api-user.cy.ts
new file mode 100644
index 0000000..696cd21
--- /dev/null
+++ b/cypress/e2e/api-user.cy.ts
@@ -0,0 +1,125 @@
+describe('User API tests', () => {
+ Cypress.session.clearAllSavedSessions();
+
+ before(() => {
+ cy.login(Cypress.env('umami_user'), Cypress.env('umami_password'));
+ });
+
+ let userId;
+
+ it('Creates a user.', () => {
+ cy.fixture('users').then(data => {
+ const userCreate = data.userCreate;
+ cy.request({
+ method: 'POST',
+ url: '/api/users',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: userCreate,
+ }).then(response => {
+ userId = response.body.id;
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('username', 'cypress1');
+ expect(response.body).to.have.property('role', 'user');
+ });
+ });
+ });
+
+ it('Returns all users. Admin access is required.', () => {
+ cy.request({
+ method: 'GET',
+ url: '/api/admin/users',
+ 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('username');
+ expect(response.body.data[0]).to.have.property('password');
+ expect(response.body.data[0]).to.have.property('role');
+ });
+ });
+
+ it('Updates a user.', () => {
+ cy.fixture('users').then(data => {
+ const userUpdate = data.userUpdate;
+ cy.request({
+ method: 'POST',
+ url: `/api/users/${userId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: userUpdate,
+ }).then(response => {
+ userId = response.body.id;
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('id', userId);
+ expect(response.body).to.have.property('username', 'cypress1');
+ expect(response.body).to.have.property('role', 'view-only');
+ });
+ });
+ });
+
+ it('Gets a user by ID.', () => {
+ cy.request({
+ method: 'GET',
+ url: `/api/users/${userId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('id', userId);
+ expect(response.body).to.have.property('username', 'cypress1');
+ expect(response.body).to.have.property('role', 'view-only');
+ });
+ });
+
+ it('Deletes a user.', () => {
+ 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);
+ expect(response.body).to.have.property('ok', true);
+ });
+ });
+
+ it('Gets all websites that belong to a user.', () => {
+ cy.request({
+ method: 'GET',
+ url: `/api/users/${userId}/websites`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('data');
+ });
+ });
+
+ it('Gets all teams that belong to a user.', () => {
+ cy.request({
+ method: 'GET',
+ url: `/api/users/${userId}/teams`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('data');
+ });
+ });
+});