-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DE-571 added e2e for product-families (#8)
Co-authored-by: Alberto Blacutt <[email protected]>
- Loading branch information
1 parent
e7e3014
commit 676acba
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |