-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #49 (api) setShippingMethod function
- Loading branch information
Showing
6 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/api-client/__tests__/api/setShippingMethod.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import setShippingMethod from '../../src/api/setShippingMethod'; | ||
import setOrderShippingMethodMutation from '../../src/api/setShippingMethod/setOrderShippingMethodMutation'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] setShippingMethod', () => { | ||
it('sets shipping method for certain order', async () => { | ||
const givenVariables = { shippingMethodId: '1'}; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
mutate: ({ variables, mutation }) => { | ||
expect(variables).toEqual(givenVariables); | ||
expect(mutation).toEqual(setOrderShippingMethodMutation); | ||
|
||
return { data: 'set shipping method response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await setShippingMethod(context, { shippingMethodId: '1' }); | ||
|
||
expect(data).toBe('set shipping method response'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import setOrderShippingMethodMutation from './setOrderShippingMethodMutation'; | ||
import { CustomQuery } from '@vue-storefront/core'; | ||
import gql from 'graphql-tag'; | ||
import { Context, SetShippingMethodParams, SetShippingMethodResponse } from '../../types'; | ||
|
||
const setShippingMethod = async (context: Context, params: SetShippingMethodParams, customQuery?: CustomQuery): Promise<SetShippingMethodResponse> => { | ||
const setShippingMethodVariables = { | ||
...params | ||
}; | ||
|
||
const { setOrderShippingMethod } = context.extendQuery( | ||
customQuery, { setOrderShippingMethod: { query: setOrderShippingMethodMutation, variables: setShippingMethodVariables } } | ||
); | ||
|
||
const request = await context.client.mutate({ | ||
mutation: gql`${setOrderShippingMethod.query}`, | ||
variables: setOrderShippingMethod.variables, | ||
fetchPolicy: 'no-cache' | ||
}) as SetShippingMethodResponse; | ||
|
||
return request; | ||
}; | ||
|
||
export default setShippingMethod; |
14 changes: 14 additions & 0 deletions
14
packages/api-client/src/api/setShippingMethod/setOrderShippingMethodMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import gql from 'graphql-tag'; | ||
import { CartFragment, ErrorResultFragment } from '../../fragments'; | ||
|
||
export default gql` | ||
${CartFragment} | ||
${ErrorResultFragment} | ||
mutation setOrderShippingMethod($shippingMethodId: ID!) { | ||
setOrderShippingMethod(shippingMethodId: $shippingMethodId) { | ||
...Cart | ||
...ErrorResult | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters