-
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) getShippingMethods function
- Loading branch information
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/api-client/__tests__/api/getShippingMethods.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 getShippingMethods from '../../src/api/getShippingMethods'; | ||
import eligibleShippingMethodsQuery from '../../src/api/getShippingMethods/eligibleShippingMethodsQuery'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] getShippingMethods', () => { | ||
it('returns shipping methods', async () => { | ||
const givenVariables = {}; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
query: ({ variables, query }) => { | ||
expect(variables).toEqual(givenVariables); | ||
expect(query).toEqual(eligibleShippingMethodsQuery); | ||
|
||
return { data: 'get shipping methods response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await getShippingMethods(context); | ||
|
||
expect(data).toBe('get shipping methods response'); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/api-client/src/api/getShippingMethods/eligibleShippingMethodsQuery.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,15 @@ | ||
import gql from 'graphql-tag'; | ||
|
||
export default gql` | ||
query eligibleShippingMethods { | ||
eligibleShippingMethods { | ||
id | ||
price | ||
priceWithTax | ||
code | ||
name | ||
description | ||
metadata | ||
} | ||
} | ||
`; |
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,22 @@ | ||
import gql from 'graphql-tag'; | ||
import eligibleShippingMethodsQuery from './eligibleShippingMethodsQuery'; | ||
import { CustomQuery } from '@vue-storefront/core'; | ||
import { Context, RequestDataStructure, GetShippingMethodsResponse, PaymentMethodQuote } from '../../types'; | ||
|
||
const getShippingMethods = async (context: Context, customQuery?: CustomQuery): Promise<GetShippingMethodsResponse> => { | ||
const getShippingMethods = {}; | ||
|
||
const { eligibleShippingMethods } = context.extendQuery( | ||
customQuery, { eligibleShippingMethods: { query: eligibleShippingMethodsQuery, variables: getShippingMethods } } | ||
); | ||
|
||
const request = await context.client.query<RequestDataStructure<'eligiblePaymentMethods', PaymentMethodQuote[]>>({ | ||
query: gql`${eligibleShippingMethods.query}`, | ||
variables: eligibleShippingMethods.variables, | ||
fetchPolicy: 'no-cache' | ||
}); | ||
return request; | ||
|
||
}; | ||
|
||
export default getShippingMethods; |
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