-
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: #56 (api) transitionOrderToState
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/api-client/__tests__/api/transitionOrderToState.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 transitionOrderToState from '../../src/api/transitionOrderToState'; | ||
import transitionOrderToStateMutation from '../../src/api/transitionOrderToState/transitionOrderToStateMutation'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] transitionOrderToState', () => { | ||
it('sets payment method for certain order', async () => { | ||
const givenVariables = { state: 'test' }; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
mutate: ({ variables, mutation }) => { | ||
expect(variables).toEqual(givenVariables); | ||
expect(mutation).toEqual(transitionOrderToStateMutation); | ||
|
||
return { data: 'transition order to state response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await transitionOrderToState(context, { state: 'test' }); | ||
|
||
expect(data).toBe('transition order to state response'); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/api-client/src/api/transitionOrderToState/index.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,24 @@ | ||
import transitionOrderToStateMutation from './transitionOrderToStateMutation'; | ||
import { CustomQuery } from '@vue-storefront/core'; | ||
import gql from 'graphql-tag'; | ||
import { Context, TransitionOrderToState, TransitionOrderToStateParams } from '../../types'; | ||
|
||
const transitionOrderToState = async (context: Context, params: TransitionOrderToStateParams, customQuery?: CustomQuery): Promise<TransitionOrderToState> => { | ||
const transitionOrderToStateVariables = { | ||
...params | ||
}; | ||
|
||
const { transitionOrderToState } = context.extendQuery( | ||
customQuery, { transitionOrderToState: { query: transitionOrderToStateMutation, variables: transitionOrderToStateVariables } } | ||
); | ||
|
||
const request = await context.client.mutate({ | ||
mutation: gql`${transitionOrderToState.query}`, | ||
variables: transitionOrderToState.variables, | ||
fetchPolicy: 'no-cache' | ||
}) as TransitionOrderToState; | ||
|
||
return request; | ||
}; | ||
|
||
export default transitionOrderToState; |
14 changes: 14 additions & 0 deletions
14
packages/api-client/src/api/transitionOrderToState/transitionOrderToStateMutation.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 transitionOrderToState($state: String!) { | ||
transitionOrderToState(state: $state) { | ||
...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