-
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.
- Loading branch information
Showing
5 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/api-client/__tests__/api/setCustomerForOrder.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 setCustomerForOrder from '../../src/api/setCustomerForOrder'; | ||
import setCustomerForOrderMutation from '../../src/api/setCustomerForOrder/setCustomerForOrderMutation'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] setCustomerForOrder', () => { | ||
it('sets customer for certain order', async () => { | ||
const givenVariables = { firstName: 'test', lastName: 'test', emailAddress: 'test@test.com' }; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
mutate: ({ variables, mutation }) => { | ||
expect(variables).toEqual({ input: givenVariables }); | ||
expect(mutation).toEqual(setCustomerForOrderMutation); | ||
|
||
return { data: 'set customer for order response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await setCustomerForOrder(context, givenVariables); | ||
|
||
expect(data).toBe('set customer for order 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 setCustomerForOrderMutation from './setCustomerForOrderMutation'; | ||
import { CustomQuery } from '@vue-storefront/core'; | ||
import gql from 'graphql-tag'; | ||
import { Context, CreateCustomerInput, SetCustomerForOrderResponse } from '../../types'; | ||
|
||
const setCustomerForOrder = async (context: Context, params: CreateCustomerInput, customQuery?: CustomQuery): Promise<SetCustomerForOrderResponse> => { | ||
const setCustomerForOrderVariables = { | ||
input: params | ||
}; | ||
|
||
const { setCustomerForOrder } = context.extendQuery( | ||
customQuery, { setCustomerForOrder: { query: setCustomerForOrderMutation, variables: setCustomerForOrderVariables } } | ||
); | ||
|
||
const request = await context.client.mutate({ | ||
mutation: gql`${setCustomerForOrder.query}`, | ||
variables: setCustomerForOrder.variables, | ||
fetchPolicy: 'no-cache' | ||
}) as SetCustomerForOrderResponse; | ||
|
||
return request; | ||
}; | ||
|
||
export default setCustomerForOrder; |
14 changes: 14 additions & 0 deletions
14
packages/api-client/src/api/setCustomerForOrder/setCustomerForOrderMutation.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 setCustomerForOrder($input: CreateCustomerInput!) { | ||
setCustomerForOrder(input: $input) { | ||
...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