diff --git a/fixtures/checkout-create-invalid-variant-id-error-fixture.js b/fixtures/checkout-create-invalid-variant-id-error-fixture.js new file mode 100644 index 000000000..3cfb17106 --- /dev/null +++ b/fixtures/checkout-create-invalid-variant-id-error-fixture.js @@ -0,0 +1,7 @@ +export default { + "errors": [ + { + "message": "Variable input of type CheckoutCreateInput! was provided invalid value" + } + ] +} diff --git a/src/handle-checkout-mutation.js b/src/handle-checkout-mutation.js index 728f9185c..5cf7086bc 100644 --- a/src/handle-checkout-mutation.js +++ b/src/handle-checkout-mutation.js @@ -1,5 +1,5 @@ export default function handleCheckoutMutation(mutationRootKey, client) { - return function({data, errors, model}) { + return function({data = {}, errors, model = {}}) { const rootData = data[mutationRootKey]; const rootModel = model[mutationRootKey]; diff --git a/test/client-checkout-integration-test.js b/test/client-checkout-integration-test.js index 42f12d6d1..bfb55abaf 100644 --- a/test/client-checkout-integration-test.js +++ b/test/client-checkout-integration-test.js @@ -7,6 +7,7 @@ import fetchMockPostOnce from './fetch-mock-helper'; import checkoutFixture from '../fixtures/checkout-fixture'; import checkoutNullFixture from '../fixtures/node-null-fixture'; import checkoutCreateFixture from '../fixtures/checkout-create-fixture'; +import checkoutCreateInvalidVariantIdErrorFixture from '../fixtures/checkout-create-invalid-variant-id-error-fixture'; import checkoutCreateWithPaginatedLineItemsFixture from '../fixtures/checkout-create-with-paginated-line-items-fixture'; import {secondPageLineItemsFixture, thirdPageLineItemsFixture} from '../fixtures/paginated-line-items-fixture'; import checkoutLineItemsAddFixture from '../fixtures/checkout-line-items-add-fixture'; @@ -101,6 +102,25 @@ suite('client-checkout-integration-test', () => { }); }); + test('it resolve with user errors on Client.checkout#create when variantId is invalid', () => { + const input = { + lineItems: [ + { + variantId: 'a-bad-id', + quantity: 5 + } + ] + }; + + fetchMockPostOnce(fetchMock, apiUrl, checkoutCreateInvalidVariantIdErrorFixture); + + return client.checkout.create(input).then(() => { + assert.ok(false, 'Promise should not resolve'); + }).catch((error) => { + assert.equal(error.message, '[{"message":"Variable input of type CheckoutCreateInput! was provided invalid value"}]'); + }); + }); + test('it resolves with a checkout on Client.checkout#updateAttributes', () => { const checkoutId = 'Z2lkOi8vU2hvcGlmeS9FeGFtcGxlLzE='; const input = {