From 0d065936182fa022de7159b3016b6a52969be6b7 Mon Sep 17 00:00:00 2001 From: EJ Mercado Date: Mon, 25 May 2020 14:22:19 +0800 Subject: [PATCH] test: add unit tests for get matching product for id --- .../products_get_matching_product_for_id.xml | 239 ++++++++++++++++++ test/unit/products.test.ts | 31 +++ 2 files changed, 270 insertions(+) create mode 100644 test/unit/__fixtures__/products_get_matching_product_for_id.xml diff --git a/test/unit/__fixtures__/products_get_matching_product_for_id.xml b/test/unit/__fixtures__/products_get_matching_product_for_id.xml new file mode 100644 index 00000000..1954b7a6 --- /dev/null +++ b/test/unit/__fixtures__/products_get_matching_product_for_id.xml @@ -0,0 +1,239 @@ + + + + + + + ATVPDKIKX0DER + 1933988665 + + + + + Marmanis, Haralambos + Babenko, Dmitry + Paperback + 1 + + 9.17 + 7.36 + 0.75 + 1.40 + + true + Manning Publications + + + english + Unknown + + + english + Original Language + + + english + Published + + + + 44.99 + USD + + Manning Publications + 1 + 368 + + 0.80 + 9.10 + 7.30 + 1.35 + + Book + ABIS_BOOK + 2009-07-05 + Manning Publications + + + http://ecx.images-amazon.com/images/I/51EEz05N2HL._SL75_.jpg + + 75 + 60 + + Manning Publications + Algorithms of the Intelligent Web + + + + + + book_display_on_website + 59485 + + + 377886011 + 32 + + + 3887 + 66 + + + 3870 + 82 + + + + + + + + + + + ATVPDKIKX0DER + 059035342X + + + + + Rowling, J.K. + Paperback + Scholastic Press + GrandPré, Mary + 1st + Recommended Age: 9 years and up + + 0.80 + 7.50 + 5.20 + 0.50 + + false + false + Scholastic Paperbacks + + + english + Unknown + + + english + Original Language + + + english + Published + + + + 10.99 + USD + + Scholastic Paperbacks + 1 + 320 + + 1.00 + 7.50 + 5.20 + 0.50 + + 1 + 9780590353427 + Book + ABIS_BOOK + 1999-10-01 + Scholastic Paperbacks + 1999-09-08 + + + http://ecx.images-amazon.com/images/I/51MU5VilKpL._SL75_.jpg + + 75 + 51 + + Scholastic Paperbacks + Harry Potter and the Sorcerer's Stone (Book 1) + + + + + + book_display_on_website + 362 + + + 15356791 + 6 + + + 3153 + 9 + + + 3045 + 14 + + + + + + + ATVPDKIKX0DER + 0439708184 + + + + + J.K. Rowling, Mary GrandPré + Paperback + Scholastic Paperbacks + + + english + Unknown + + + english + Published + + + Scholastic Paperbacks + 1 + 784 + + 0.73 + 8.43 + 5.85 + 0.79 + + Book + BOOKS_1973_AND_LATER + 1999-09-08 + Scholastic Paperbacks + + + http://ecx.images-amazon.com/images/I/51STfI7UiCL._SL75_.jpg + + 75 + 52 + + Scholastic Paperbacks + Harry Potter and the Sorcerer's Stone + + + + + + book_display_on_website + 2091024 + + + + + + + 7ba3245e-a213-430a-bea9-EXAMPLE38d76 + + \ No newline at end of file diff --git a/test/unit/products.test.ts b/test/unit/products.test.ts index 7787646a..bd14466b 100644 --- a/test/unit/products.test.ts +++ b/test/unit/products.test.ts @@ -45,6 +45,15 @@ const mockGetMatchingProduct = new MWS( ), ) +const mockGetMatchingProductForId = new MWS( + new HttpClient(httpConfig, () => + Promise.resolve({ + data: getFixture('products_get_matching_product_for_id'), + headers, + }), + ), +) + const mockMwsFail = new MWS( new HttpClient(httpConfig, () => Promise.resolve({ data: '', headers: {} })), ) @@ -52,6 +61,28 @@ const mockMwsFail = new MWS( const parsingError = 'Expected an object, but received a string with value ""' describe('products', () => { + describe('getMatchingProductForId', () => { + it('returns a matching product when the response is valid', async () => { + expect.assertions(1) + + expect( + await mockGetMatchingProductForId.products.getMatchingProductForId({ + MarketplaceId: '', + IdType: '', + IdList: [], + }), + ).toMatchSnapshot() + }) + + it('throws an error when the response is not valid', async () => { + expect.assertions(1) + + await expect(() => + mockMwsFail.products.getMatchingProductForId({ MarketplaceId: '', IdType: '', IdList: [] }), + ).rejects.toStrictEqual(new ParsingError(parsingError)) + }) + }) + describe('getMatchingProduct', () => { it('returns a matching product when the response is valid', async () => { expect.assertions(1)