Skip tax rates test if CI
This commit is contained in:
parent
2c75de6648
commit
296f2aa382
|
@ -1,11 +1,21 @@
|
|||
const {
|
||||
test,
|
||||
expect
|
||||
} = require('@playwright/test');
|
||||
const { test, expect } = require( '@playwright/test' );
|
||||
|
||||
const {
|
||||
allUSTaxesExample
|
||||
} = require('../../data');
|
||||
const { allUSTaxesExample } = require( '../../data' );
|
||||
const { API_BASE_URL } = process.env;
|
||||
|
||||
const skipTestIfCI = () => {
|
||||
const skipMessage = 'Skipping this test because running on CI';
|
||||
// !FIXME This test fails on CI because of differences in environment.
|
||||
test.skip( () => {
|
||||
const shouldSkip = API_BASE_URL != undefined;
|
||||
|
||||
if ( shouldSkip ) {
|
||||
console.log( skipMessage );
|
||||
}
|
||||
|
||||
return shouldSkip;
|
||||
}, skipMessage );
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests for the WooCommerce API.
|
||||
|
@ -14,24 +24,24 @@ const {
|
|||
* @group taxes
|
||||
*
|
||||
*/
|
||||
skipTestIfCI();
|
||||
|
||||
test.describe( 'Tax Rates API tests: CRUD', () => {
|
||||
let taxRateId;
|
||||
|
||||
test.describe( 'Create a tax rate', () => {
|
||||
test('can create a tax rate', async ({
|
||||
request,
|
||||
}) => {
|
||||
test( 'can create a tax rate', async ( { request } ) => {
|
||||
// call API to create a tax rate
|
||||
const response = await request.post( '/wp-json/wc/v3/taxes', {
|
||||
data: {
|
||||
country: "US",
|
||||
state: "AL",
|
||||
cities: ["Alpine", "Brookside", "Cardiff"],
|
||||
postcodes: ["35014", "35036", "35041"],
|
||||
rate: "4",
|
||||
name: "State Tax",
|
||||
shipping: false
|
||||
}
|
||||
country: 'US',
|
||||
state: 'AL',
|
||||
cities: [ 'Alpine', 'Brookside', 'Cardiff' ],
|
||||
postcodes: [ '35014', '35036', '35041' ],
|
||||
rate: '4',
|
||||
name: 'State Tax',
|
||||
shipping: false,
|
||||
},
|
||||
} );
|
||||
const responseJSON = await response.json();
|
||||
|
||||
|
@ -42,11 +52,15 @@ test.describe('Tax Rates API tests: CRUD', () => {
|
|||
expect( typeof responseJSON.id ).toEqual( 'number' );
|
||||
// Verify that the tax rate class is 'standard'
|
||||
expect( responseJSON.class ).toEqual( 'standard' );
|
||||
expect(responseJSON.country).toEqual("US");
|
||||
expect(responseJSON.state).toEqual("AL");
|
||||
expect(responseJSON.city).toEqual(expect.stringMatching(/ALPINE|BROOKSIDE|CARDIFF/));
|
||||
expect(responseJSON.postcode).toEqual(expect.stringMatching(/35014|35036|35041/));
|
||||
expect(responseJSON.name).toEqual("State Tax");
|
||||
expect( responseJSON.country ).toEqual( 'US' );
|
||||
expect( responseJSON.state ).toEqual( 'AL' );
|
||||
expect( responseJSON.city ).toEqual(
|
||||
expect.stringMatching( /ALPINE|BROOKSIDE|CARDIFF/ )
|
||||
);
|
||||
expect( responseJSON.postcode ).toEqual(
|
||||
expect.stringMatching( /35014|35036|35041/ )
|
||||
);
|
||||
expect( responseJSON.name ).toEqual( 'State Tax' );
|
||||
expect( responseJSON.priority ).toEqual( 1 );
|
||||
expect( responseJSON.compound ).toEqual( false );
|
||||
expect( responseJSON.shipping ).toEqual( false );
|
||||
|
@ -56,9 +70,7 @@ test.describe('Tax Rates API tests: CRUD', () => {
|
|||
} );
|
||||
|
||||
test.describe( 'Retrieve after create', () => {
|
||||
test('can retrieve a tax rate', async ({
|
||||
request
|
||||
}) => {
|
||||
test( 'can retrieve a tax rate', async ( { request } ) => {
|
||||
// call API to retrieve the previously saved tax rates
|
||||
const response = await request.get(
|
||||
`/wp-json/wc/v3/taxes/${ taxRateId }`
|
||||
|
@ -69,22 +81,23 @@ test.describe('Tax Rates API tests: CRUD', () => {
|
|||
expect( typeof responseJSON.id ).toEqual( 'number' );
|
||||
// Verify that the tax rate class is 'standard'
|
||||
expect( responseJSON.class ).toEqual( 'standard' );
|
||||
expect(responseJSON.country).toEqual("US");
|
||||
expect(responseJSON.state).toEqual("AL");
|
||||
expect(responseJSON.city).toEqual(expect.stringMatching(/ALPINE|BROOKSIDE|CARDIFF/));
|
||||
expect(responseJSON.postcode).toEqual(expect.stringMatching(/35014|35036|35041/));
|
||||
expect(responseJSON.name).toEqual("State Tax");
|
||||
expect( responseJSON.country ).toEqual( 'US' );
|
||||
expect( responseJSON.state ).toEqual( 'AL' );
|
||||
expect( responseJSON.city ).toEqual(
|
||||
expect.stringMatching( /ALPINE|BROOKSIDE|CARDIFF/ )
|
||||
);
|
||||
expect( responseJSON.postcode ).toEqual(
|
||||
expect.stringMatching( /35014|35036|35041/ )
|
||||
);
|
||||
expect( responseJSON.name ).toEqual( 'State Tax' );
|
||||
expect( responseJSON.priority ).toEqual( 1 );
|
||||
expect( responseJSON.compound ).toEqual( false );
|
||||
expect( responseJSON.shipping ).toEqual( false );
|
||||
expect( responseJSON.order ).toEqual( 0 );
|
||||
expect( responseJSON.rate ).toEqual( '4.0000' );
|
||||
|
||||
} );
|
||||
|
||||
test('can retrieve all tax rates', async ({
|
||||
request
|
||||
}) => {
|
||||
test( 'can retrieve all tax rates', async ( { request } ) => {
|
||||
// call API to retrieve all tax rates
|
||||
const response = await request.get( '/wp-json/wc/v3/taxes' );
|
||||
const responseJSON = await response.json();
|
||||
|
@ -95,49 +108,45 @@ test.describe('Tax Rates API tests: CRUD', () => {
|
|||
} );
|
||||
|
||||
test.describe( 'Update a tax rate', () => {
|
||||
test(`can update a tax rate`, async ({
|
||||
request,
|
||||
}) => {
|
||||
test( `can update a tax rate`, async ( { request } ) => {
|
||||
// update tax rate name
|
||||
const response = await request.put(
|
||||
`/wp-json/wc/v3/taxes/${ taxRateId }`, {
|
||||
`/wp-json/wc/v3/taxes/${ taxRateId }`,
|
||||
{
|
||||
data: {
|
||||
name: "Not State Tax"
|
||||
}
|
||||
name: 'Not State Tax',
|
||||
},
|
||||
}
|
||||
);
|
||||
const responseJSON = await response.json();
|
||||
expect( response.status() ).toEqual( 200 );
|
||||
expect( responseJSON.id ).toEqual( taxRateId );
|
||||
expect(responseJSON.name).toEqual("Not State Tax");
|
||||
expect( responseJSON.name ).toEqual( 'Not State Tax' );
|
||||
expect( responseJSON.priority ).toEqual( 1 );
|
||||
expect( responseJSON.compound ).toEqual( false );
|
||||
expect( responseJSON.shipping ).toEqual( false );
|
||||
expect( responseJSON.order ).toEqual( 0 );
|
||||
expect(responseJSON.rate).toEqual('4.0000')
|
||||
|
||||
expect( responseJSON.rate ).toEqual( '4.0000' );
|
||||
} );
|
||||
|
||||
test('retrieve after update tax rate', async ({
|
||||
request
|
||||
}) => {
|
||||
test( 'retrieve after update tax rate', async ( { request } ) => {
|
||||
// call API to retrieve all tax rates
|
||||
const response = await request.get(`/wp-json/wc/v3/taxes/${ taxRateId }`);
|
||||
const response = await request.get(
|
||||
`/wp-json/wc/v3/taxes/${ taxRateId }`
|
||||
);
|
||||
const responseJSON = await response.json();
|
||||
expect( response.status() ).toEqual( 200 );
|
||||
expect( responseJSON.id ).toEqual( taxRateId );
|
||||
expect( responseJSON.name ).toEqual( 'Not State Tax' );
|
||||
|
||||
} );
|
||||
} );
|
||||
|
||||
test.describe( 'Delete a tax rate', () => {
|
||||
test('can permanently delete a tax rate', async ({
|
||||
request
|
||||
}) => {
|
||||
test( 'can permanently delete a tax rate', async ( { request } ) => {
|
||||
// Delete the tax rate.
|
||||
const response = await request.delete(
|
||||
`/wp-json/wc/v3/taxes/${ taxRateId }`, {
|
||||
`/wp-json/wc/v3/taxes/${ taxRateId }`,
|
||||
{
|
||||
data: {
|
||||
force: true,
|
||||
},
|
||||
|
@ -153,20 +162,16 @@ test.describe('Tax Rates API tests: CRUD', () => {
|
|||
} );
|
||||
} );
|
||||
|
||||
|
||||
/**
|
||||
* 48 tax rates to be created in one batch.
|
||||
*/
|
||||
test.describe( 'Batch tax rate operations', () => {
|
||||
|
||||
// set payload to use batch create: action
|
||||
const batchCreate48TaxRatesPayload = {
|
||||
create: allUSTaxesExample
|
||||
create: allUSTaxesExample,
|
||||
};
|
||||
|
||||
test('can batch create tax rates', async ({
|
||||
request
|
||||
}) => {
|
||||
test( 'can batch create tax rates', async ( { request } ) => {
|
||||
// Batch create tax rates.
|
||||
// call API to batch create tax rates
|
||||
const response = await request.post( 'wp-json/wc/v3/taxes/batch', {
|
||||
|
@ -180,10 +185,7 @@ test.describe('Tax Rates API tests: CRUD', () => {
|
|||
expect( actualTaxRates ).toHaveLength( allUSTaxesExample.length );
|
||||
|
||||
for ( let i = 0; i < actualTaxRates.length; i++ ) {
|
||||
const {
|
||||
id,
|
||||
rate
|
||||
} = actualTaxRates[i];
|
||||
const { id, rate } = actualTaxRates[ i ];
|
||||
|
||||
expect( id ).toBeDefined();
|
||||
expect( rate ).toEqual( allUSTaxesExample[ i ].rate );
|
||||
|
@ -193,29 +195,26 @@ test.describe('Tax Rates API tests: CRUD', () => {
|
|||
}
|
||||
} );
|
||||
|
||||
test('can batch update tax rates', async ({
|
||||
request
|
||||
}) => {
|
||||
test( 'can batch update tax rates', async ( { request } ) => {
|
||||
// set payload to use batch update: action
|
||||
const batchUpdatePayload = {
|
||||
update: [{
|
||||
update: [
|
||||
{
|
||||
id: allUSTaxesExample[ 0 ].id,
|
||||
rate: '4.1111',
|
||||
},
|
||||
{
|
||||
id: allUSTaxesExample[ 1 ].id,
|
||||
order: 49,
|
||||
rate: '5.6111'
|
||||
rate: '5.6111',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// Call API to batch update the tax rates
|
||||
const response = await request.post(
|
||||
'wp-json/wc/v3/taxes/batch', {
|
||||
const response = await request.post( 'wp-json/wc/v3/taxes/batch', {
|
||||
data: batchUpdatePayload,
|
||||
}
|
||||
);
|
||||
} );
|
||||
const responseJSON = await response.json();
|
||||
|
||||
// Verify the response code and the number of tax ratess that were updated.
|
||||
|
@ -224,39 +223,38 @@ test.describe('Tax Rates API tests: CRUD', () => {
|
|||
expect( updatedTaxRates ).toHaveLength( 2 );
|
||||
|
||||
// Verify that the 1st tax rate was updated to have a new rate.
|
||||
expect(updatedTaxRates[0].id).toEqual(allUSTaxesExample[0].id);
|
||||
expect( updatedTaxRates[ 0 ].id ).toEqual(
|
||||
allUSTaxesExample[ 0 ].id
|
||||
);
|
||||
expect( updatedTaxRates[ 0 ].rate ).toEqual( '4.1111' );
|
||||
|
||||
// Verify that the 2nd tax rate has had the order and the rate updated
|
||||
expect(updatedTaxRates[1].id).toEqual(allUSTaxesExample[1].id);
|
||||
expect( updatedTaxRates[ 1 ].id ).toEqual(
|
||||
allUSTaxesExample[ 1 ].id
|
||||
);
|
||||
expect( updatedTaxRates[ 1 ].order ).toEqual( 49 );
|
||||
expect( updatedTaxRates[ 1 ].rate ).toEqual( '5.6111' );
|
||||
} );
|
||||
|
||||
test('can batch delete tax rates', async ({
|
||||
request
|
||||
}) => {
|
||||
test( 'can batch delete tax rates', async ( { request } ) => {
|
||||
// Batch delete the 48 tax rates
|
||||
const taxRateIdsToDelete = allUSTaxesExample.map(({
|
||||
id
|
||||
}) => id);
|
||||
const taxRateIdsToDelete = allUSTaxesExample.map(
|
||||
( { id } ) => id
|
||||
);
|
||||
const batchDeletePayload = {
|
||||
delete: taxRateIdsToDelete,
|
||||
};
|
||||
|
||||
//Call API to batch delete the tax rates
|
||||
const response = await request.post(
|
||||
'wp-json/wc/v3/taxes/batch', {
|
||||
const response = await request.post( 'wp-json/wc/v3/taxes/batch', {
|
||||
data: batchDeletePayload,
|
||||
}
|
||||
);
|
||||
} );
|
||||
const responseJSON = await response.json();
|
||||
|
||||
// Verify that the response shows the 48 tax rates.
|
||||
const deletedTaxRateIds = responseJSON.delete.map(
|
||||
({
|
||||
id
|
||||
}) => id);
|
||||
( { id } ) => id
|
||||
);
|
||||
expect( response.status() ).toEqual( 200 );
|
||||
expect( deletedTaxRateIds ).toEqual( taxRateIdsToDelete );
|
||||
|
||||
|
|
Loading…
Reference in New Issue