- Remove blanket uncaught:exception suppressor (API-only tests)
- Trim smoke test to single infra-verification assertion
- Rewrite health test with strict status/field assertions, no failOnStatusCode
- Add session CRUD tests (create, get, list, delete, 404 cases, cleanup)
- Use Cypress.env('API_URL') instead of baseUrl to avoid blocking smoke tests
- Remove unused main and type fields from package.json
98 lines
3.3 KiB
JavaScript
98 lines
3.3 KiB
JavaScript
/// <reference types="cypress" />
|
|
|
|
const api = () => Cypress.env('API_URL');
|
|
|
|
describe('Sessions API', () => {
|
|
const createdSessions = [];
|
|
|
|
afterEach(() => {
|
|
createdSessions.splice(0).forEach((id) => {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `${api()}/api/sessions/${id}`,
|
|
failOnStatusCode: false,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('GET /api/sessions', () => {
|
|
it('returns 200 with an array', () => {
|
|
cy.request(`${api()}/api/sessions`).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body).to.be.an('array');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('POST /api/sessions', () => {
|
|
it('creates a session with expected fields', () => {
|
|
cy.request('POST', `${api()}/api/sessions`).then((response) => {
|
|
expect(response.status).to.be.oneOf([200, 201]);
|
|
expect(response.body).to.have.property('session_id');
|
|
expect(response.body).to.have.property('auth_token');
|
|
expect(response.body).to.have.property('status');
|
|
createdSessions.push(response.body.session_id);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('GET /api/sessions/:id', () => {
|
|
it('returns the created session', () => {
|
|
cy.request('POST', `${api()}/api/sessions`).then((createRes) => {
|
|
createdSessions.push(createRes.body.session_id);
|
|
const id = createRes.body.session_id;
|
|
|
|
cy.request(`${api()}/api/sessions/${id}`).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body).to.have.property('session_id', id);
|
|
});
|
|
});
|
|
});
|
|
|
|
it('returns 404 for nonexistent session', () => {
|
|
cy.request({
|
|
url: `${api()}/api/sessions/nonexistent-id-000`,
|
|
failOnStatusCode: false,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(404);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('DELETE /api/sessions/:id', () => {
|
|
it('deletes a session', () => {
|
|
cy.request('POST', `${api()}/api/sessions`).then((createRes) => {
|
|
const id = createRes.body.session_id;
|
|
|
|
cy.request('DELETE', `${api()}/api/sessions/${id}`).then(
|
|
(response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body).to.have.property('message');
|
|
}
|
|
);
|
|
});
|
|
});
|
|
|
|
it('returns 404 for nonexistent session', () => {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `${api()}/api/sessions/nonexistent-id-000`,
|
|
failOnStatusCode: false,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(404);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('POST /api/cleanup', () => {
|
|
it('returns 200 with cleanup message', () => {
|
|
cy.request('POST', `${api()}/api/cleanup`).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body)
|
|
.to.have.property('message')
|
|
.that.includes('Cleanup completed');
|
|
});
|
|
});
|
|
});
|
|
});
|