supplier_central_frontend/cypress/e2e/api.cy.ts

62 lines
2.3 KiB
TypeScript

describe('Seller Central Django Backend API E2E Tests', () => {
const backendUrl = 'http://localhost:8000';
it('verifies product list', () => {
cy.request(`${backendUrl}/api/products/`).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.be.an('array');
});
});
it('creates and deletes a product', () => {
const uniqueSku = `SKU-CY-${Date.now()}`;
cy.request('POST', `${backendUrl}/api/products/`, {
title: 'Cypress Test Silk Scarf',
category: 'Apparel',
price: '55.00',
stock: 20,
sku: uniqueSku
}).then((response) => {
expect(response.status).to.eq(201);
expect(response.body.sku).to.eq(uniqueSku);
const prodId = response.body.id;
// Delete the created product
cy.request('DELETE', `${backendUrl}/api/products/${prodId}/`).then((delRes) => {
expect(delRes.status).to.eq(204); // django rest framework delete returns 204 No Content
});
});
});
it('verifies order list and acceptance', () => {
cy.request(`${backendUrl}/api/orders/`).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.be.an('array');
expect(response.body.length).to.be.greaterThan(0);
const pendingOrder = response.body.find((o: any) => o.status === 'Pending Acceptance');
if (pendingOrder) {
cy.request('POST', `${backendUrl}/api/orders/${pendingOrder.id}/accept/`).then((acceptRes) => {
expect(acceptRes.status).to.eq(200);
expect(acceptRes.body.status).to.eq('Ready to Ship');
});
}
});
});
it('verifies wallet summary and payout withdrawal', () => {
cy.request(`${backendUrl}/api/wallet/`).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.have.property('outstanding');
expect(response.body).to.have.property('withdrawn');
const currentOutstanding = parseFloat(response.body.outstanding);
if (currentOutstanding > 10) {
cy.request('POST', `${backendUrl}/api/wallet/withdraw/`, { amount: '10.00' }).then((withdrawRes) => {
expect(withdrawRes.status).to.eq(200);
expect(parseFloat(withdrawRes.body.outstanding)).to.eq(currentOutstanding - 10);
});
}
});
});
});