supplier_central_frontend/cypress/e2e/api.cy.ts
vickytechkey b54a897b88
Some checks failed
Production CI/CD Pipeline / build-and-test (push) Failing after 3s
Production CI/CD Pipeline / deploy-prod (push) Has been skipped
adding beta stage implementation
2026-08-09 12:29:56 +05:30

80 lines
2.3 KiB
TypeScript

describe('Seller Central Django Backend API E2E Tests', () => {
const backendUrl = 'http://localhost:8000/api';
it('verifies product list', () => {
cy.request({
method: 'GET',
url: `${backendUrl}/products/`
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.be.an('array');
});
});
it('creates and deletes a product', () => {
const testSku = `CY-SKU-${Date.now()}`;
cy.request({
method: 'POST',
url: `${backendUrl}/products/`,
body: {
title: 'Cypress Test Pot',
category: 'Home Decor',
price: '45.00',
stock: 5,
sku: testSku
}
}).then((response) => {
expect(response.status).to.eq(201);
expect(response.body.sku).to.eq(testSku);
const productId = response.body.id;
// Delete the product
cy.request({
method: 'DELETE',
url: `${backendUrl}/products/${productId}/`
}).then((delResponse) => {
expect(delResponse.status).to.eq(204);
});
});
});
it('verifies order list and acceptance', () => {
cy.request({
method: 'GET',
url: `${backendUrl}/orders/`
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.be.an('array');
const order = response.body.find((o: any) => o.status === 'Pending Acceptance');
if (order) {
cy.request({
method: 'POST',
url: `${backendUrl}/orders/${order.id}/accept/`
}).then((acceptResponse) => {
expect(acceptResponse.status).to.eq(200);
expect(acceptResponse.body.status).to.eq('Ready to Ship');
});
}
});
});
it('verifies wallet summary and payout withdrawal', () => {
cy.request({
method: 'GET',
url: `${backendUrl}/wallet/`
}).then((response) => {
expect(response.status).to.eq(200);
const initialOutstanding = parseFloat(response.body.outstanding);
if (initialOutstanding > 10) {
cy.request({
method: 'POST',
url: `${backendUrl}/wallet/withdraw/`,
body: { amount: '10.00' }
}).then((withdrawResponse) => {
expect(withdrawResponse.status).to.eq(200);
expect(parseFloat(withdrawResponse.body.outstanding)).to.eq(initialOutstanding - 10);
});
}
});
});
});