Skip to content

Commit

Permalink
[commerce-sdk-react] Fix Shopper Baskets Test case (#1082)
Browse files Browse the repository at this point in the history
* Fix Shopper Basket empty response test cases

* lint
  • Loading branch information
adamraya authored Mar 23, 2023
1 parent b11a91a commit 199e80f
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,18 @@ const addTaxesForBasketItemTestCase = [
const nonEmptyResponseTestCases = Object.entries(testMap) as Array<
[NonEmptyResponseMutations, Argument<Client[NonEmptyResponseMutations]>]
>
// 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(() => {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 199e80f

Please sign in to comment.