From 199e80fa51c8f748beb0ab5c5e1ed29498aab3a7 Mon Sep 17 00:00:00 2001 From: Adam Raya Date: Thu, 23 Mar 2023 10:25:21 -0700 Subject: [PATCH] [commerce-sdk-react] Fix Shopper Baskets Test case (#1082) * Fix Shopper Basket empty response test cases * lint --- .../src/hooks/ShopperBaskets/mutation.test.ts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 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..15d935bb7c 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,18 @@ 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,23 +257,20 @@ describe('ShopperBaskets mutations', () => { assertUpdateQuery(result.current.customerBaskets, oldCustomerBaskets) } ) - test.each([ - deleteTestCase, - addPriceBooksToBasketTestCase, - addTaxesForBasketTestCase, - addTaxesForBasketItemTestCase - ])('`%s` returns void on success', async () => { - // 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) - }) - 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