add api-testing to cypress tests

This commit is contained in:
Francis Cao 2025-03-12 10:32:54 -07:00
parent abde966647
commit a407ff4693
13 changed files with 598 additions and 46 deletions

View file

@ -61,3 +61,63 @@ Cypress.Commands.add('deleteWebsite', (websiteId: string) => {
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);
});
});

View file

@ -24,9 +24,33 @@ declare namespace Cypress {
*/
addWebsite(name: string, domain: string): Chainable<JQuery<HTMLElement>>;
/**
* Custom command to create a website
* 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>>;
}
}