Reto
describe('Test for update product', () => {
it('#update, should update a product', (doneFn) => {
// Arrange
const mockData = generateOneProduct();
const productId = '1';
const dto: UpdateProductDTO = {
title: 'Product edited',
price: 1000,
images: ['img'],
description: 'This is a product edited',
categoryId: 12,
};
// Act
service.update(productId, { ...dto }).subscribe((data) => {
// Assert
expect(data).toEqual(mockData);
doneFn();
});
// Http Config
const url = `${environment.API_URL}/api/v1/products/${productId}`;
const req = httpController.expectOne(`${url}`);
req.flush(mockData);
expect(req.request.body).toEqual(dto);
expect(req.request.method).toEqual('PUT');
});
});
describe('Test for delete product', () => {
it('#Delete, should delete a product', (doneFn) => {
// Arrange
const productId = '1';
// Act
service.delete(productId).subscribe((data) => {
// Assert
expect(data).toBe(true);
doneFn();
});
// Http Config
const url = `${environment.API_URL}/api/v1/products/${productId}`;
const req = httpController.expectOne(`${url}`);
req.flush(true);
expect(req.request.method).toEqual('DELETE');
});
});
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?