Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:80',
supportFile: 'cypress/support/e2e.js',
specPattern: 'cypress/e2e/**/*.cy.js',

env: {
apiUrl: 'http://localhost:80/api',
},
},
});
18 changes: 18 additions & 0 deletions cypress/e2e/sharedFlows/auth.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe('Shared Auth Flow', () => {
it('logs in successfully', () => {
cy.request({
method: 'POST',
url: '/api/auth/login',
body: {
email: 'weeramann@gmail.com',
password: 'Pass1234@',
},
}).then((response) => {
expect(response.status).to.eq(200);

expect(response.headers).to.have.property('x-request-id');

cy.captureRequestId(response);
});
});
});
15 changes: 15 additions & 0 deletions cypress/e2e/sharedFlows/errorhandling.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe('Error Handling', () => {
it('returns request ID on failures', () => {
cy.request({
method: 'GET',
url: '/api/auth/profile',
failOnStatusCode: false,
}).then(response => {
expect(response.status).to.eq(401);

expect(response.headers).to.have.property('x-request-id');

cy.captureRequestId(response);
});
});
});
17 changes: 17 additions & 0 deletions cypress/e2e/sharedFlows/mealplan.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe('Mealplan Flow', () => {
beforeEach(() => {
cy.login();
});

it('fetches recommendations', () => {
cy.request({
method: 'GET',
url: '/api/fooddata/mealplan',
headers: {
Authorization: `Bearer ${window.localStorage.getItem('token')}`,
},
}).then((response) => {
cy.log(JSON.stringify(res.body));
});
});
});
28 changes: 28 additions & 0 deletions cypress/e2e/sharedFlows/preferences.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe('Preferences Flow', () => {
beforeEach(() => {
cy.login();
});

it('updates preferences safely', () => {
cy.request({
method: 'POST',
url: '/api/user/preferences',
headers: {
Authorization: `Bearer ${window.localStorage.getItem('token')}`,
},
body: {
dietary_requirements: [1, 2, 4],
allergies: [1],
cuisines: [2, 5],
dislikes: [4],
health_conditions: [],
spice_levels: [1, 2],
cooking_methods: [1, 4, 5],
},
}).then((response) => {
expect(response.status).to.eq(200);

cy.captureRequestId(response);
});
});
});
19 changes: 19 additions & 0 deletions cypress/e2e/sharedFlows/session.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe('Protected Session Flow', () => {
beforeEach(() => {
cy.login();
});

it('loads authenticated profile', () => {
cy.request({
method: 'GET',
url: '/api/account',
headers: {
Authorization: `Bearer ${window.localStorage.getItem('token')}`,
},
}).then((response) => {
expect(response.status).to.eq(200);

cy.captureRequestId(response);
});
});
});
27 changes: 27 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Cypress.Commands.add('login', () => {
cy.request({
method: 'POST',
url: '/api/auth/login',
body: {
email: 'weeramann@gmail.com',
password: 'Pass1234@',
},
}).then((response) => {
expect(response.status).to.eq(200);

// Save token if backend returns one
const token = response.body?.token || response.body?.accessToken;

if (token) {
window.localStorage.setItem('token', token);
}

// Save request ID for tracing/debugging
const requestId = response.headers['x-request-id'];

if (requestId) {
Cypress.env('requestId', requestId);
cy.log(`Request ID: ${requestId}`);
}
});
});
11 changes: 11 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import './commands';

Cypress.Commands.add('captureRequestId', (response) => {
const requestId = response.headers['x-request-id'];

if (requestId) {
cy.log(`Request ID: ${requestId}`);

Cypress.env('lastRequestId', requestId);
}
});
9 changes: 9 additions & 0 deletions cypress/support/failureReporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Cypress.on('fail', error => {
const requestId = Cypress.env('lastRequestId');

if (requestId) {
error.message += `\n\nRequest ID: ${requestId}`;
}

throw error;
});
Loading