-
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/setPaymentMethod.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 setPaymentMethod from '../../src/api/setPaymentMethod'; | ||
import addPaymentToOrderMutation from '../../src/api/setPaymentMethod/addPaymentToOrderMutation'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] setPaymentMethod', () => { | ||
it('sets payment method for certain order', async () => { | ||
const givenVariables = { metadata: { id: '1' }, method: 'test' }; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
mutate: ({ variables, mutation }) => { | ||
expect(variables).toEqual({ input: givenVariables }); | ||
expect(mutation).toEqual(addPaymentToOrderMutation); | ||
|
||
return { data: 'set payment method response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await setPaymentMethod(context, { metadata: { id: '1' }, method: 'test' }); | ||
|
||
expect(data).toBe('set payment 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
14 changes: 14 additions & 0 deletions
14
packages/api-client/src/api/setPaymentMethod/addPaymentToOrderMutation.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 addPaymentToOrder($input: PaymentInput!) { | ||
addPaymentToOrder(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import addPaymentToOrderMutation from './addPaymentToOrderMutation'; | ||
import { CustomQuery } from '@vue-storefront/core'; | ||
import gql from 'graphql-tag'; | ||
import { Context, PaymentInput, SetShippingMethodResponse } from '../../types'; | ||
|
||
const setPaymentMethod = async (context: Context, params: PaymentInput, customQuery?: CustomQuery): Promise<SetShippingMethodResponse> => { | ||
const setPaymentMethodVariables = { | ||
input: params | ||
}; | ||
|
||
const { addPaymentToOrder } = context.extendQuery( | ||
customQuery, { addPaymentToOrder: { query: addPaymentToOrderMutation, variables: setPaymentMethodVariables } } | ||
); | ||
|
||
const request = await context.client.mutate({ | ||
mutation: gql`${addPaymentToOrder.query}`, | ||
variables: addPaymentToOrder.variables, | ||
fetchPolicy: 'no-cache' | ||
}) as SetShippingMethodResponse; | ||
|
||
return request; | ||
}; | ||
|
||
export default setPaymentMethod; |
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