Add Cypress E2E tests with fixture-based API mocking for UI regression protection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
119
cypress/support/intercept.js
Normal file
119
cypress/support/intercept.js
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Sets up cy.intercept for all API endpoints using fixture files.
|
||||
* Call setupApiIntercepts() in beforeEach to mock the entire backend.
|
||||
*/
|
||||
export function setupApiIntercepts() {
|
||||
// Auth
|
||||
cy.intercept('POST', '/api/oauth/token', {
|
||||
fixture: 'api/token.json',
|
||||
}).as('postToken');
|
||||
|
||||
// User account
|
||||
cy.intercept('GET', '/api/my-account', {
|
||||
fixture: 'api/my-account.json',
|
||||
}).as('getMyAccount');
|
||||
|
||||
cy.intercept('PUT', '/api/my-account', {
|
||||
statusCode: 200,
|
||||
body: { success: true },
|
||||
}).as('putMyAccount');
|
||||
|
||||
// Files
|
||||
cy.intercept('GET', '/api/files', {
|
||||
fixture: 'api/files.json',
|
||||
}).as('getFiles');
|
||||
|
||||
// Users (account management)
|
||||
cy.intercept('GET', '/api/users', {
|
||||
fixture: 'api/users.json',
|
||||
}).as('getUsers');
|
||||
|
||||
cy.intercept('POST', '/api/users', {
|
||||
statusCode: 200,
|
||||
body: { success: true },
|
||||
}).as('postUser');
|
||||
|
||||
cy.intercept('DELETE', '/api/users/*', {
|
||||
statusCode: 200,
|
||||
body: { success: true },
|
||||
}).as('deleteUser');
|
||||
|
||||
cy.intercept('PUT', '/api/users/*', {
|
||||
statusCode: 200,
|
||||
body: { success: true },
|
||||
}).as('putUser');
|
||||
|
||||
// Discover (map data)
|
||||
cy.intercept('GET', '/api/logs/*/discover', {
|
||||
fixture: 'api/discover.json',
|
||||
}).as('getDiscover');
|
||||
|
||||
cy.intercept('GET', '/api/filters/*/discover', {
|
||||
fixture: 'api/discover.json',
|
||||
}).as('getFilterDiscover');
|
||||
|
||||
// Performance
|
||||
cy.intercept('GET', '/api/logs/*/performance', {
|
||||
fixture: 'api/performance.json',
|
||||
}).as('getPerformance');
|
||||
|
||||
cy.intercept('GET', '/api/filters/*/performance', {
|
||||
fixture: 'api/performance.json',
|
||||
}).as('getFilterPerformance');
|
||||
|
||||
// Traces
|
||||
cy.intercept('GET', '/api/logs/*/traces', {
|
||||
fixture: 'api/traces.json',
|
||||
}).as('getTraces');
|
||||
|
||||
cy.intercept('GET', '/api/filters/*/traces', {
|
||||
fixture: 'api/traces.json',
|
||||
}).as('getFilterTraces');
|
||||
|
||||
// Temp filters
|
||||
cy.intercept('GET', '/api/temp-filters/*/discover', {
|
||||
fixture: 'api/discover.json',
|
||||
}).as('getTempFilterDiscover');
|
||||
|
||||
cy.intercept('GET', '/api/temp-filters/*/traces', {
|
||||
fixture: 'api/traces.json',
|
||||
}).as('getTempFilterTraces');
|
||||
|
||||
// Filter params
|
||||
cy.intercept('GET', '/api/filters/params*', {
|
||||
statusCode: 200,
|
||||
body: {},
|
||||
}).as('getFilterParams');
|
||||
|
||||
cy.intercept('GET', '/api/filters/has-result*', {
|
||||
statusCode: 200,
|
||||
body: false,
|
||||
}).as('getFilterHasResult');
|
||||
|
||||
// Conformance check params
|
||||
cy.intercept('GET', '/api/log-checks/params*', {
|
||||
statusCode: 200,
|
||||
body: {},
|
||||
}).as('getLogCheckParams');
|
||||
|
||||
cy.intercept('GET', '/api/filter-checks/params*', {
|
||||
statusCode: 200,
|
||||
body: {},
|
||||
}).as('getFilterCheckParams');
|
||||
|
||||
// Deletion
|
||||
cy.intercept('DELETE', '/api/deletion/*', {
|
||||
statusCode: 200,
|
||||
body: { success: true },
|
||||
}).as('deleteDeletion');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the luciaToken cookie and isLuciaLoggedIn cookie to simulate
|
||||
* a logged-in state, then sets up all API intercepts.
|
||||
*/
|
||||
export function loginWithFixtures() {
|
||||
setupApiIntercepts();
|
||||
cy.setCookie('luciaToken', 'fake-access-token-for-testing');
|
||||
cy.setCookie('isLuciaLoggedIn', 'true');
|
||||
}
|
||||
Reference in New Issue
Block a user