From d64153912cf40cbde56db79857ba42675232858e Mon Sep 17 00:00:00 2001 From: Adam Raya Navarro Date: Thu, 23 Mar 2023 09:49:47 -0700 Subject: [PATCH 1/2] Fix Shopper Basket empty response test cases --- .../src/hooks/ShopperBaskets/mutation.test.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts b/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts index eee9a5a30a..8981d1abb9 100644 --- a/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts +++ b/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts @@ -164,15 +164,21 @@ const addTaxesForBasketItemTestCase = [ const nonEmptyResponseTestCases = Object.entries(testMap) as Array< [NonEmptyResponseMutations, Argument] > -// Most test cases only apply to non-delete test cases, some (error handling) can include deleteBasket -const allTestCases = [ - ...nonEmptyResponseTestCases, + +// Endpoints returning void response on success +const emptyResponseTestCases = [ deleteTestCase, addPriceBooksToBasketTestCase, addTaxesForBasketTestCase, addTaxesForBasketItemTestCase ] +// Most test cases only apply to non-empty response test cases, some (error handling) can include deleteBasket +const allTestCases = [ + ...nonEmptyResponseTestCases, + ...emptyResponseTestCases +] + describe('ShopperBaskets mutations', () => { const storedCustomerIdKey = `${DEFAULT_TEST_CONFIG.siteId}_customer_id` beforeAll(() => { @@ -254,14 +260,8 @@ describe('ShopperBaskets mutations', () => { assertUpdateQuery(result.current.customerBaskets, oldCustomerBaskets) } ) - test.each([ - deleteTestCase, - addPriceBooksToBasketTestCase, - addTaxesForBasketTestCase, - addTaxesForBasketItemTestCase - ])('`%s` returns void on success', async () => { + test.each(emptyResponseTestCases)('`%s` returns void on success', async (mutationName, options) => { // Almost the standard 'returns data' test, just a different return type - const [mutationName, options] = deleteTestCase mockMutationEndpoints(basketsEndpoint, oldBasket) const {result, waitForValueToChange: wait} = renderHookWithProviders(() => { return useShopperBasketsMutation(mutationName) From a0a4f36257a1c13e07eee2b74b2989d5066c5758 Mon Sep 17 00:00:00 2001 From: Adam Raya Navarro Date: Thu, 23 Mar 2023 10:03:34 -0700 Subject: [PATCH 2/2] lint --- .../src/hooks/ShopperBaskets/mutation.test.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts b/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts index 8981d1abb9..15d935bb7c 100644 --- a/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts +++ b/packages/commerce-sdk-react/src/hooks/ShopperBaskets/mutation.test.ts @@ -174,10 +174,7 @@ const emptyResponseTestCases = [ ] // Most test cases only apply to non-empty response test cases, some (error handling) can include deleteBasket -const allTestCases = [ - ...nonEmptyResponseTestCases, - ...emptyResponseTestCases -] +const allTestCases = [...nonEmptyResponseTestCases, ...emptyResponseTestCases] describe('ShopperBaskets mutations', () => { const storedCustomerIdKey = `${DEFAULT_TEST_CONFIG.siteId}_customer_id` @@ -260,17 +257,20 @@ describe('ShopperBaskets mutations', () => { assertUpdateQuery(result.current.customerBaskets, oldCustomerBaskets) } ) - test.each(emptyResponseTestCases)('`%s` returns void on success', async (mutationName, options) => { - // Almost the standard 'returns data' test, just a different return type - mockMutationEndpoints(basketsEndpoint, oldBasket) - const {result, waitForValueToChange: wait} = renderHookWithProviders(() => { - return useShopperBasketsMutation(mutationName) - }) - expect(result.current.data).toBeUndefined() - act(() => result.current.mutate(options)) - await waitAndExpectSuccess(wait, () => result.current) - expect(result.current.data).toBeUndefined() - }) + test.each(emptyResponseTestCases)( + '`%s` returns void on success', + async (mutationName, options) => { + // Almost the standard 'returns data' test, just a different return type + mockMutationEndpoints(basketsEndpoint, oldBasket) + const {result, waitForValueToChange: wait} = renderHookWithProviders(() => { + return useShopperBasketsMutation(mutationName) + }) + expect(result.current.data).toBeUndefined() + act(() => result.current.mutate(options)) + await waitAndExpectSuccess(wait, () => result.current) + expect(result.current.data).toBeUndefined() + } + ) test('`deleteBasket` removes the basket from the cache on success', async () => { // Almost the standard 'updates cache' test, but the cache changes are different const [mutationName, options] = deleteTestCase