Add test case for parent parameters.

This commit is contained in:
Jeff Stieler 2021-09-30 09:38:34 -04:00
parent b9386f3224
commit 27155e20df
2 changed files with 39 additions and 0 deletions

View File

@ -1482,6 +1482,22 @@ const createSampleVariableProducts = async ( categories, attributes ) => {
] ); ] );
}; };
const createSampleHierarchicalProducts = async () => {
const { body: parent } = await createProduct( {
name: 'Parent Product',
} );
const { body: child } = await createProduct( {
name: 'Child Product',
parent_id: parent.id,
} );
return {
parent,
child,
}
};
const createSampleProducts = async () => { const createSampleProducts = async () => {
const categories = await createSampleCategories(); const categories = await createSampleCategories();
const attributes = await createSampleAttributes(); const attributes = await createSampleAttributes();
@ -1494,6 +1510,7 @@ const createSampleProducts = async () => {
await createSampleExternalProducts( categories ); await createSampleExternalProducts( categories );
await createSampleGroupedProduct( categories ); await createSampleGroupedProduct( categories );
await createSampleVariableProducts( categories, attributes ); await createSampleVariableProducts( categories, attributes );
await createSampleHierarchicalProducts();
}; };
module.exports = { module.exports = {

View File

@ -446,5 +446,27 @@ const { getRequest } = require( '../../utils/request' );
expect( result.body ).toHaveLength( coolProducts.length ); expect( result.body ).toHaveLength( coolProducts.length );
expect( result.body ).toEqual( expect.arrayContaining( coolProducts ) ); expect( result.body ).toEqual( expect.arrayContaining( coolProducts ) );
} ); } );
it( 'parent', async () => {
const result1 = await productsApi.listAll.products( {
search: 'Parent Product'
} );
expect( result1.body ).toHaveLength( 1 );
const result2 = await productsApi.listAll.products( {
parent: result1.body[0].id,
} );
expect( result2.statusCode ).toEqual( 200 );
expect( result2.body ).toHaveLength( 1 );
expect( result2.body[0].name ).toBe( 'Child Product' );
const result3 = await productsApi.listAll.products( {
parent_exclude: result1.body[0].id,
} );
expect( result3.statusCode ).toEqual( 200 );
expect( result3.body ).toEqual( expect.not.arrayContaining( [
expect.objectContaining( { name: 'Child Product' } ),
] ) );
} );
} ); } );
} ); } );