From 50a78becf4abc913d0ebf855303f03ab4f8750c7 Mon Sep 17 00:00:00 2001 From: Bartosz Herba Date: Wed, 3 Apr 2024 12:40:03 +0200 Subject: [PATCH] fix: custom query and mutation params passing --- .changeset/nine-berries-move.md | 5 +++++ packages/api-client/__tests__/mockData/api/storeConfig.ts | 4 ++-- packages/sdk/__tests__/unit/customMutation.unit.spec.ts | 8 ++++++-- packages/sdk/__tests__/unit/customQuery.unit.spec.ts | 6 +++++- packages/sdk/src/methods/customMutation/index.ts | 2 +- packages/sdk/src/methods/customQuery/index.ts | 2 +- 6 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 .changeset/nine-berries-move.md diff --git a/.changeset/nine-berries-move.md b/.changeset/nine-berries-move.md new file mode 100644 index 000000000..ec2fb64c2 --- /dev/null +++ b/.changeset/nine-berries-move.md @@ -0,0 +1,5 @@ +--- +"@vue-storefront/magento-sdk": patch +--- + +[FIXED] Correctly passing properties and options to `customQuery` and `customMutation` SDK methods. Previously, the `customHeaders` option was not being passed properly. Now, all options will be properly passed to the `customQuery` and `customMutation` methods. diff --git a/packages/api-client/__tests__/mockData/api/storeConfig.ts b/packages/api-client/__tests__/mockData/api/storeConfig.ts index ee147805c..68a7ec02a 100644 --- a/packages/api-client/__tests__/mockData/api/storeConfig.ts +++ b/packages/api-client/__tests__/mockData/api/storeConfig.ts @@ -12,7 +12,7 @@ const STORE_CONFIG_MOCK_RESP = { configurable_thumbnail_source: "parent", copyright: "Copyright © 2013-present Magento, Inc. All rights reserved.", default_description: null, - default_display_currency_code: "USD", + default_display_currency_code: "EUR", default_keywords: null, default_title: "Magento Commerce", grid_per_page: 12, @@ -24,7 +24,7 @@ const STORE_CONFIG_MOCK_RESP = { list_mode: "grid-list", list_per_page: 10, list_per_page_values: "5,10,15,20,25", - locale: "en_US", + locale: expect.any(String), logo_alt: null, logo_height: null, logo_width: null, diff --git a/packages/sdk/__tests__/unit/customMutation.unit.spec.ts b/packages/sdk/__tests__/unit/customMutation.unit.spec.ts index fceccb5fb..0f236c9f0 100644 --- a/packages/sdk/__tests__/unit/customMutation.unit.spec.ts +++ b/packages/sdk/__tests__/unit/customMutation.unit.spec.ts @@ -3,7 +3,7 @@ import { describeGroup } from './__config__/jest.setup'; import { client } from '../../src'; import { MethodBaseOptions } from '../../src/types'; -const PARAMS_MOCK = { mutation: '{ __typename }', mutationVariables: {} }; +const PARAMS_MOCK = { mutation: '{ __typename }', mutationVariables: {}, customHeaders: {} }; const OPTIONS_MOCK = { clientConfig: {}, customHeaders: {} } as MethodBaseOptions; const RESPONSE_MOCK = { data: { data: 'some_data', error: null } }; const ERROR_MOCK = new Error('error'); @@ -24,7 +24,11 @@ describe(describeGroup('customMutation'), () => { it('makes a call to API Middleware with proper params and options', async () => { await customMutation(PARAMS_MOCK, OPTIONS_MOCK); - expect(client.post).toBeCalledWith('customMutation', [expect.objectContaining(PARAMS_MOCK), {}], {}); + expect(client.post).toBeCalledWith( + 'customMutation', + { customHeaders: {}, mutation: '{ __typename }', mutationVariables: {} }, + {}, + ); }); it('extracts and returns a response', async () => { diff --git a/packages/sdk/__tests__/unit/customQuery.unit.spec.ts b/packages/sdk/__tests__/unit/customQuery.unit.spec.ts index 537570597..6b844568e 100644 --- a/packages/sdk/__tests__/unit/customQuery.unit.spec.ts +++ b/packages/sdk/__tests__/unit/customQuery.unit.spec.ts @@ -24,7 +24,11 @@ describe(describeGroup('customQuery'), () => { it('makes a call to API Middleware with proper params and options', async () => { await customQuery(PARAMS_MOCK, OPTIONS_MOCK); - expect(client.post).toBeCalledWith('customQuery', [expect.objectContaining(PARAMS_MOCK), {}], {}); + expect(client.post).toBeCalledWith( + 'customQuery', + { customHeaders: {}, query: '{ __typename }', queryVariables: {} }, + {}, + ); }); it('extracts and returns a response', async () => { diff --git a/packages/sdk/src/methods/customMutation/index.ts b/packages/sdk/src/methods/customMutation/index.ts index c174fcdb3..b2b6e2515 100644 --- a/packages/sdk/src/methods/customMutation/index.ts +++ b/packages/sdk/src/methods/customMutation/index.ts @@ -77,7 +77,7 @@ export async function customMutation, IN return new AxiosRequestSender(client) .setUrl('customMutation') .setMethod('POST') - .setProps([params, options?.customHeaders]) + .setProps({ ...params, customHeaders: options?.customHeaders }) .setConfig(options?.clientConfig) .send(); } diff --git a/packages/sdk/src/methods/customQuery/index.ts b/packages/sdk/src/methods/customQuery/index.ts index a6024c030..9a51833d9 100644 --- a/packages/sdk/src/methods/customQuery/index.ts +++ b/packages/sdk/src/methods/customQuery/index.ts @@ -92,7 +92,7 @@ export async function customQuery, INPUT ex return new AxiosRequestSender(client) .setUrl('customQuery') .setMethod('POST') - .setProps([params, options?.customHeaders]) + .setProps({ ...params, customHeaders: options?.customHeaders }) .setConfig(options?.clientConfig) .send(); }