diff --git a/test/unit/__fixtures__/get_service_status.xml b/test/unit/__fixtures__/get_service_status.xml new file mode 100644 index 00000000..55f67a2b --- /dev/null +++ b/test/unit/__fixtures__/get_service_status.xml @@ -0,0 +1,6 @@ + + + GREEN + 2020-05-06T08:22:23.582Z + + \ No newline at end of file diff --git a/test/unit/__fixtures__/orders_list_orders.xml b/test/unit/__fixtures__/orders_list_orders.xml new file mode 100644 index 00000000..896390a5 --- /dev/null +++ b/test/unit/__fixtures__/orders_list_orders.xml @@ -0,0 +1,161 @@ + + + 2YgYW55IGNhcm5hbCBwbGVhc3VyZS4= + 2017-02-25T18%3A10%3A21.687Z + + + 902-3159896-1390916 + 2017-02-20T19:49:35Z + 2017-02-20T19:49:35Z + Unshipped + MFN + Amazon.com + + Buyer name + 1234 Any St. + Seattle + 98103 + US + Commercial + + + USD + 25.00 + + 0 + 1 + Other + + CreditCard + + ATVPDKIKX0DER + 5vlhEXAMPLEh9h5@marketplace.amazon.com + Buyer name + + Company Name + US + + + VATNumber + XXX123 + + + + StandardOrder + 2017-02-20T19:51:16Z + 2017-02-25T19:49:35Z + true + PO12345678 + false + false + false + + + 483-3488972-0896720 + 2017-02-20T19:49:35Z + 2017-02-20T19:49:35Z + Unshipped + MFN + + Buyer name + 1234 Avenida Qualquer + Sao Paulo + 08474-130 + BR + Residential + + + BRL + 100.00 + + 0 + 1 + Other + + CreditCard + + A2Q3Y263D00KWC + 5vlhEXAMPLEh9h5@marketplace.amazon.com.br + John Jones + Vila Olimpia + + BR + + + CSTNumber + XXX123 + + + + 2017-02-20T19:51:16Z + 2017-02-25T19:49:35Z + false + false + false + false + + + 058-1233752-8214740 + 2017-02-05T00%3A06%3A07.000Z + 2017-02-07T12%3A43%3A16.000Z + Unshipped + MFN + Std JP Kanto8 + + Jane Smith + 1-2-10 Akasaka + Tokyo + 107-0053 + JP + + + JPY + 1507.00 + + 0 + 1 + + + + 10.00 + JPY + + PointsAccount + + + + 317.00 + JPY + + GC + + + + 1180.00 + JPY + + COD + + + COD + + COD + + A1VC38T7YXB528 + 5vlhEXAMPLEh9h5@marketplace.amazon.co.jp + Jane Smith + Standard + SourcingOnDemandOrder + false + false + false + false + 2017-08-31T23:58:44Z + true + + + + + 88faca76-b600-46d2-b53c-0c8c4533e43a + + \ No newline at end of file diff --git a/test/unit/__fixtures__/orders_list_orders_nt.xml b/test/unit/__fixtures__/orders_list_orders_nt.xml new file mode 100644 index 00000000..da1569bb --- /dev/null +++ b/test/unit/__fixtures__/orders_list_orders_nt.xml @@ -0,0 +1,10 @@ + + + 2YgYW55IGNhcm5hbCBwbGVhc3VyZS4= + 2017-02-25T18%3A10%3A21.687Z + + + + 88faca76-b600-46d2-b53c-0c8c4533e43a + + \ No newline at end of file diff --git a/test/unit/__fixtures__/sellers_list_marketplace_participations.xml b/test/unit/__fixtures__/sellers_list_marketplace_participations.xml new file mode 100644 index 00000000..e2ddfa12 --- /dev/null +++ b/test/unit/__fixtures__/sellers_list_marketplace_participations.xml @@ -0,0 +1,37 @@ + + + + + A2EUQ1WTGCTBG2 + x + No + + + A6W85IYQ5WB1C + x + No + + + + + A2EUQ1WTGCTBG2 + CA + www.amazon.ca + Amazon.ca + CAD + en_CA + + + A6W85IYQ5WB1C + US + iba.login.amazon.com + IBA + USD + en_US + + + + + bd71c84f-d2a6-4ce0-ae41-6dc8a13ce637 + + \ No newline at end of file diff --git a/test/unit/__fixtures__/sellers_list_marketplace_participations_nt.xml b/test/unit/__fixtures__/sellers_list_marketplace_participations_nt.xml new file mode 100644 index 00000000..b3a7cb0b --- /dev/null +++ b/test/unit/__fixtures__/sellers_list_marketplace_participations_nt.xml @@ -0,0 +1,37 @@ + + + + + A2EUQ1WTGCTBG2 + x + No + + + A6W85IYQ5WB1C + x + No + + + + + A2EUQ1WTGCTBG2 + CA + www.amazon.ca + Amazon.ca + CAD + en_CA + + + A6W85IYQ5WB1C + US + iba.login.amazon.com + IBA + USD + en_US + + + + + bd71c84f-d2a6-4ce0-ae41-6dc8a13ce637 + + \ No newline at end of file diff --git a/test/unit/orders.test.ts b/test/unit/orders.test.ts index 99c3f4e1..f8dce759 100644 --- a/test/unit/orders.test.ts +++ b/test/unit/orders.test.ts @@ -1,7 +1,7 @@ -/* eslint-disable sonarjs/no-duplicate-string */ import { amazonMarketplaces, HttpClient, ParsingError } from '../../src' import { MWS } from '../../src/mws' import { NextToken } from '../../src/parsing' +import { getFixture } from '../utils' const httpConfig = { awsAccessKeyId: '', @@ -14,167 +14,7 @@ const httpConfig = { const mockMwsListOrders = new MWS( new HttpClient(httpConfig, () => Promise.resolve({ - data: ` - - 2YgYW55IGNhcm5hbCBwbGVhc3VyZS4= - 2017-02-25T18%3A10%3A21.687Z - - - 902-3159896-1390916 - 2017-02-20T19:49:35Z - 2017-02-20T19:49:35Z - Unshipped - MFN - Amazon.com - - Buyer name - 1234 Any St. - Seattle - 98103 - US - Commercial - - - USD - 25.00 - - 0 - 1 - Other - - CreditCard - - ATVPDKIKX0DER - 5vlhEXAMPLEh9h5@marketplace.amazon.com - Buyer name - - Company Name - US - - - VATNumber - XXX123 - - - - StandardOrder - 2017-02-20T19:51:16Z - 2017-02-25T19:49:35Z - true - PO12345678 - false - false - false - - - 483-3488972-0896720 - 2017-02-20T19:49:35Z - 2017-02-20T19:49:35Z - Unshipped - MFN - - Buyer name - 1234 Avenida Qualquer - Sao Paulo - 08474-130 - BR - Residential - - - BRL - 100.00 - - 0 - 1 - Other - - CreditCard - - A2Q3Y263D00KWC - 5vlhEXAMPLEh9h5@marketplace.amazon.com.br - John Jones - Vila Olimpia - - BR - - - CSTNumber - XXX123 - - - - 2017-02-20T19:51:16Z - 2017-02-25T19:49:35Z - false - false - false - false - - - 058-1233752-8214740 - 2017-02-05T00%3A06%3A07.000Z - 2017-02-07T12%3A43%3A16.000Z - Unshipped - MFN - Std JP Kanto8 - - Jane Smith - 1-2-10 Akasaka - Tokyo - 107-0053 - JP - - - JPY - 1507.00 - - 0 - 1 - - - - 10.00 - JPY - - PointsAccount - - - - 317.00 - JPY - - GC - - - - 1180.00 - JPY - - COD - - - COD - - COD - - A1VC38T7YXB528 - 5vlhEXAMPLEh9h5@marketplace.amazon.co.jp - Jane Smith - Standard - SourcingOnDemandOrder - false - false - false - false - 2017-08-31T23:58:44Z - true - - - - - 88faca76-b600-46d2-b53c-0c8c4533e43a - - `, + data: getFixture('orders_list_orders'), headers: { 'x-mws-request-id': '0', 'x-mws-timestamp': '2020-05-06T09:22:23.582Z', @@ -189,16 +29,7 @@ const mockMwsListOrders = new MWS( const mockMwsListOrdersNT = new MWS( new HttpClient(httpConfig, () => Promise.resolve({ - data: ` - - 2YgYW55IGNhcm5hbCBwbGVhc3VyZS4= - 2017-02-25T18%3A10%3A21.687Z - - - - 88faca76-b600-46d2-b53c-0c8c4533e43a - - `, + data: getFixture('orders_list_orders_nt'), headers: { 'x-mws-request-id': '0', 'x-mws-timestamp': '2020-05-06T08:22:23.582Z', @@ -213,12 +44,7 @@ const mockMwsListOrdersNT = new MWS( const mockMwsServiceStatus = new MWS( new HttpClient(httpConfig, () => Promise.resolve({ - data: ` - - GREEN - 2020-05-06T08:22:23.582Z - - `, + data: getFixture('get_service_status'), headers: { 'x-mws-request-id': '0', 'x-mws-timestamp': '2020-05-06T08:22:23.582Z', @@ -236,6 +62,8 @@ const mockMwsFail = new MWS( const mockNextToken = new NextToken('ListOrders', '123') +const parsingError = 'Expected an object, but received a string with value ""' + describe('sellers', () => { describe('listMarketplaceParticipations', () => { it('returns a parsed model when the response is valid', async () => { @@ -249,9 +77,7 @@ describe('sellers', () => { await expect(() => mockMwsFail.orders.listOrders({ MarketplaceId: [] }), - ).rejects.toStrictEqual( - new ParsingError('Expected an object, but received a string with value ""'), - ) + ).rejects.toStrictEqual(new ParsingError(parsingError)) }) }) @@ -273,9 +99,7 @@ describe('sellers', () => { mockMwsFail.orders.listOrdersByNextToken(mockNextToken, { MarketplaceId: [], }), - ).rejects.toStrictEqual( - new ParsingError('Expected an object, but received a string with value ""'), - ) + ).rejects.toStrictEqual(new ParsingError(parsingError)) }) }) @@ -290,10 +114,8 @@ describe('sellers', () => { expect.assertions(1) await expect(() => mockMwsFail.orders.getServiceStatus()).rejects.toStrictEqual( - new ParsingError('Expected an object, but received a string with value ""'), + new ParsingError(parsingError), ) }) }) }) - -/* eslint-enable sonarjs/no-duplicate-string */ diff --git a/test/unit/sellers.test.ts b/test/unit/sellers.test.ts index fa285eb4..7cad1bab 100644 --- a/test/unit/sellers.test.ts +++ b/test/unit/sellers.test.ts @@ -1,6 +1,7 @@ import { amazonMarketplaces, HttpClient, ParsingError } from '../../src' import { MWS } from '../../src/mws' import { NextToken } from '../../src/parsing' +import { getFixture } from '../utils' const httpConfig = { awsAccessKeyId: '', @@ -13,43 +14,7 @@ const httpConfig = { const mockMwsMarketplaceParticipations = new MWS( new HttpClient(httpConfig, () => Promise.resolve({ - data: ` - - - - A2EUQ1WTGCTBG2 - x - No - - - A6W85IYQ5WB1C - x - No - - - - - A2EUQ1WTGCTBG2 - CA - www.amazon.ca - Amazon.ca - CAD - en_CA - - - A6W85IYQ5WB1C - US - iba.login.amazon.com - IBA - USD - en_US - - - - - bd71c84f-d2a6-4ce0-ae41-6dc8a13ce637 - - `, + data: getFixture('sellers_list_marketplace_participations'), headers: { 'x-mws-request-id': '0', 'x-mws-timestamp': '2020-05-06T09:22:23.582Z', @@ -64,43 +29,7 @@ const mockMwsMarketplaceParticipations = new MWS( const mockMwsMarketplaceParticipationsNT = new MWS( new HttpClient(httpConfig, () => Promise.resolve({ - data: ` - - - - A2EUQ1WTGCTBG2 - x - No - - - A6W85IYQ5WB1C - x - No - - - - - A2EUQ1WTGCTBG2 - CA - www.amazon.ca - Amazon.ca - CAD - en_CA - - - A6W85IYQ5WB1C - US - iba.login.amazon.com - IBA - USD - en_US - - - - - bd71c84f-d2a6-4ce0-ae41-6dc8a13ce637 - - `, + data: getFixture('sellers_list_marketplace_participations_nt'), headers: { 'x-mws-request-id': '0', 'x-mws-timestamp': '2020-05-06T08:22:23.582Z', @@ -115,12 +44,7 @@ const mockMwsMarketplaceParticipationsNT = new MWS( const mockMwsServiceStatus = new MWS( new HttpClient(httpConfig, () => Promise.resolve({ - data: ` - - GREEN - 2020-05-06T08:22:23.582Z - - `, + data: getFixture('get_service_status'), headers: { 'x-mws-request-id': '0', 'x-mws-timestamp': '2020-05-06T08:22:23.582Z', diff --git a/test/utils.ts b/test/utils.ts new file mode 100644 index 00000000..0a442615 --- /dev/null +++ b/test/utils.ts @@ -0,0 +1,5 @@ +import { readFileSync } from 'fs' +import { join } from 'path' + +export const getFixture = (filename: string): string => + readFileSync(join(__dirname, `unit/__fixtures__/${filename}.xml`), { encoding: 'utf8' })