Skip to content

Commit

Permalink
DE-571 added e2e for product-families (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: Alberto Blacutt <[email protected]>
  • Loading branch information
alberto-blacutt-maxio and Alberto Blacutt authored Nov 7, 2023
1 parent e7e3014 commit 676acba
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions e2e/productsFamiliesController.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { createClient } from './config';
import { ProductFamiliesController } from '../src/controllers/productFamiliesController';

import { cleanSite } from './utils';

describe('ProductsFamilies Controller', () => {
afterAll(() => {
cleanSite();
});
test('should create a product family with the correct params', async () => {
const client = createClient();
const productFamiliesController = new ProductFamiliesController(client);
const payload = {
productFamily: {
name: 'Acme Projects',
description: 'Amazing project management tool',
},
};
const response =
await productFamiliesController.createProductFamily(payload);

const { productFamily } = response.result;

expect(response.statusCode).toBe(201);
expect(productFamily).toEqual(
expect.objectContaining(payload.productFamily)
);
});

test('should throw an error when the user fill invalid values on product families controller', async () => {
const client = createClient();
const productFamiliesController = new ProductFamiliesController(client);
const payload = {
productFamily: {
name: '',
description: '',
},
};
const promise = productFamiliesController.createProductFamily(payload);

expect(promise).rejects.toThrow();
promise.catch((error) => {
expect(error.statusCode).toBe(422);
expect(error.result.errors).toEqual(['Name: cannot be blank.']);
});
});

test('should read a product family already created', async () => {
const client = createClient();
const productFamiliesController = new ProductFamiliesController(client);
const payload = {
productFamily: {
name: 'productFamily',
description: 'product description',
},
};
const response =
await productFamiliesController.createProductFamily(payload);

const { productFamily } = response.result;

const readResponse = await productFamiliesController.readProductFamily(
productFamily?.id as number
);

expect(readResponse.statusCode).toBe(200);
expect(readResponse.result.productFamily).toEqual(productFamily);
});

test('should list all the products created', async () => {
const client = createClient();
const productFamiliesController = new ProductFamiliesController(client);
const readResponse = await productFamiliesController.listProductFamilies();
expect(readResponse.statusCode).toBe(200);
expect(readResponse.result.length).toBe(2);
expect(readResponse.result.map((item) => item.productFamily?.name)).toEqual(
['Acme Projects', 'productFamily']
);
});

test('should list the products from already created product family without products', async () => {
const client = createClient();
const productFamiliesController = new ProductFamiliesController(client);
const productsFamiliesResponse =
await productFamiliesController.listProductFamilies();
const [productFamilyResponse] = productsFamiliesResponse.result;
const productFamilyId = productFamilyResponse.productFamily?.id || 0;
const readResponse =
await productFamiliesController.listProductsForProductFamily(
productFamilyId
);
expect(readResponse.statusCode).toBe(200);
expect(readResponse.result.length).toBe(0);
});
});

0 comments on commit 676acba

Please sign in to comment.