initial commit

This commit is contained in:
2021-12-10 12:03:04 +00:00
commit c46c7ddbf0
3643 changed files with 582794 additions and 0 deletions

View File

@ -0,0 +1,24 @@
/**
* External dependencies
*/
import { emptyHiddenAddressFields } from '@woocommerce/base-utils';
describe( 'emptyHiddenAddressFields', () => {
it( "Removes state from an address where the country doesn't use states", () => {
const address = {
first_name: 'Jonny',
last_name: 'Awesome',
company: 'WordPress',
address_1: '123 Address Street',
address_2: 'Address 2',
city: 'Vienna',
postcode: '1120',
country: 'AT',
state: 'CA', // This should be removed.
email: 'jonny.awesome@email.com',
phone: '',
};
const filteredAddress = emptyHiddenAddressFields( address );
expect( filteredAddress ).toHaveProperty( 'state', '' );
} );
} );

View File

@ -0,0 +1,42 @@
/**
* Internal dependencies
*/
import { formatError } from '../errors';
describe( 'formatError', () => {
test( 'should format general errors', async () => {
const error = await formatError( {
message: 'Lorem Ipsum',
} );
const expectedError = {
message: 'Lorem Ipsum',
type: 'general',
};
expect( error ).toEqual( expectedError );
} );
test( 'should format API errors', async () => {
const error = await formatError( {
json: () => Promise.resolve( { message: 'Lorem Ipsum' } ),
} );
const expectedError = {
message: 'Lorem Ipsum',
type: 'api',
};
expect( error ).toEqual( expectedError );
} );
test( 'should format JSON parse errors', async () => {
const error = await formatError( {
json: () => Promise.reject( { message: 'Lorem Ipsum' } ),
} );
const expectedError = {
message: 'Lorem Ipsum',
type: 'general',
};
expect( error ).toEqual( expectedError );
} );
} );