Added update and retrieve shipping zone tests

This commit is contained in:
Rodel 2021-11-11 19:47:40 +08:00
parent 32d0a43a74
commit 8c54bcb748
2 changed files with 38 additions and 2 deletions

View File

@ -4,6 +4,7 @@
const {
getRequest,
postRequest,
putRequest,
deleteRequest,
} = require( '../utils/request' );
@ -37,6 +38,17 @@ const shippingZonesApi = {
responseCode: 200,
shippingZone: async () => getRequest( `shipping/zones` ),
},
update: {
name: 'Update a shipping zone',
method: 'PUT',
path: 'shipping/zones/<id>',
responseCode: 200,
shippingZone: async ( shippingZoneId, updatedShippingZone ) =>
putRequest(
`shipping/zones/${ shippingZoneId }`,
updatedShippingZone
),
},
delete: {
name: 'Delete a shipping zone',
method: 'DELETE',

View File

@ -2,7 +2,7 @@ const { shippingZonesApi } = require( '../../endpoints' );
const { getShippingZoneExample } = require( '../../data' );
/**
* Shipping zone to be created.
* Shipping zone to be created, retrieved, updated, and deleted by the tests.
*/
const shippingZone = getShippingZoneExample();
@ -23,10 +23,34 @@ describe( 'Shipping zones API tests', () => {
expect( typeof body.id ).toEqual( 'number' );
expect( body.name ).toEqual( shippingZone.name );
// Save the shipping zone ID
// Save the shipping zone ID. It will be used by other tests.
shippingZone.id = body.id;
} );
it( 'can retrieve a shipping zone', async () => {
const { status, body } = await shippingZonesApi.retrieve.shippingZone(
shippingZone.id
);
expect( status ).toEqual( shippingZonesApi.retrieve.responseCode );
expect( body.id ).toEqual( shippingZone.id );
} );
it( 'can update a shipping zone', async () => {
const updatedShippingZone = {
name: 'United States (Domestic)',
};
const { status, body } = await shippingZonesApi.update.shippingZone(
shippingZone.id,
updatedShippingZone
);
expect( status ).toEqual( shippingZonesApi.retrieve.responseCode );
expect( body.id ).toEqual( shippingZone.id );
expect( body.name ).toEqual( updatedShippingZone.name );
} );
it( 'can delete a shipping zone', async () => {
const { status, body } = await shippingZonesApi.delete.shippingZone(
shippingZone.id,