Skip to content

Commit 5160dea

Browse files
author
Marcin Kwiatkowski
committed
test: added missing custom queries to composables
1 parent 9b5e81b commit 5160dea

File tree

50 files changed

+196
-102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+196
-102
lines changed

packages/theme/composables/useConfig/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
} from '@nuxtjs/composition-api';
44
import { Logger } from '~/helpers/logger';
55
import { useConfigStore } from '~/stores/config';
6-
import { UseConfigErrors, UseConfigInterface } from './useConfig';
6+
import type { UseConfigErrors, UseConfigInterface, UseConfigLoadParams } from './useConfig';
77

88
/**
99
* Allows interacting with the store configuration.
@@ -17,14 +17,14 @@ export function useConfig(): UseConfigInterface {
1717
const configStore = useConfigStore();
1818
const config = computed(() => configStore.storeConfig);
1919

20-
const load = async () => {
20+
const load = async (params?: UseConfigLoadParams) => {
2121
error.value.load = null;
2222
loading.value = true;
2323

2424
Logger.debug('useConfig/load');
2525

2626
try {
27-
const { data } = await app.$vsf.$magento.api.storeConfig();
27+
const { data } = await app.$vsf.$magento.api.storeConfig(params?.customQuery ?? null);
2828
configStore.$patch((state) => {
2929
state.storeConfig = data.storeConfig || {};
3030
});

packages/theme/composables/useConfig/useConfig.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComputedRef, DeepReadonly, Ref } from '@nuxtjs/composition-api';
22
import { StoreConfig } from '~/modules/GraphQL/types';
3+
import { ComposableFunctionArgs } from '~/composables';
34

45
/**
56
* Errors that occured in the {@link useConfig|useConfig()} composable
@@ -11,6 +12,11 @@ export interface UseConfigErrors {
1112
load: Error | null;
1213
}
1314

15+
/**
16+
* The params object accepted by the `load` method in the {@link useConfig|useConfig()} composable
17+
*/
18+
export type UseConfigLoadParams = ComposableFunctionArgs<{}>;
19+
1420
/**
1521
* Data and methods returned from the {@link useConfig|useConfig()} composable
1622
*/

packages/theme/composables/useContent/commands/loadBlocksCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const loadBlocksCommand = {
55
execute: async (context: VsfContext, params) => {
66
Logger.debug('[Magento]: Load CMS Blocks content', { params });
77
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
8-
const { data } = await context.$magento.api.cmsBlocks(params.identifiers);
8+
const { data } = await context.$magento.api.cmsBlocks(params.identifiers, params.customQuery ?? null);
99

1010
Logger.debug('[Result]:', { data });
1111

packages/theme/composables/useContent/commands/loadContentCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const loadContentCommand = {
55
execute: async (context: VsfContext, params) => {
66
Logger.debug('[Magento]: Load CMS Page content', { params });
77
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
8-
const { data } = await context.$magento.api.cmsPage(params.identifier);
8+
const { data } = await context.$magento.api.cmsPage(params.identifier, params.customQuery ?? null);
99

1010
Logger.debug('[Result]:', { data });
1111

packages/theme/composables/useCountrySearch/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function useCountrySearch(): UseCountrySearchInterface {
2525

2626
Logger.debug('[Magento]: Search country information based on', { params });
2727

28-
const { data } = await app.$vsf.$magento.api.country(params.id);
28+
const { data } = await app.$vsf.$magento.api.country(params.id, params?.customQuery ?? null);
2929

3030
Logger.debug('[Result]:', { data });
3131

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { defineComponent, onMounted, useContext } from '@nuxtjs/composition-api';
2+
import { createLocalVue } from '@vue/test-utils';
3+
import { PiniaVuePlugin, setActivePinia, createPinia } from 'pinia';
4+
import { createTestingPinia } from '@pinia/testing';
5+
import { render } from '@testing-library/vue';
6+
import { useCurrency } from '../index';
7+
8+
const localVue = createLocalVue();
9+
localVue.use(PiniaVuePlugin);
10+
const pinia = createTestingPinia();
11+
const appMock = {
12+
app: {
13+
$vsf: {
14+
$magento: {
15+
api: {
16+
currency: jest.fn(),
17+
},
18+
},
19+
},
20+
},
21+
};
22+
23+
jest.mock('@nuxtjs/composition-api', () => {
24+
const actual = jest.requireActual('@nuxtjs/composition-api');
25+
return {
26+
...actual,
27+
useContext: jest.fn(),
28+
};
29+
});
30+
31+
describe('useCurrency', () => {
32+
beforeEach(() => {
33+
setActivePinia(createPinia());
34+
});
35+
36+
const MockComponent = defineComponent({
37+
name: 'MockComponent',
38+
setup() {
39+
const { load } = useCurrency();
40+
41+
onMounted(async () => {
42+
await load({
43+
customQuery: {
44+
currency: 'custom-currency-query',
45+
},
46+
});
47+
});
48+
},
49+
template: '<div>mock</div>',
50+
});
51+
52+
it('the load method should receive custom query', () => {
53+
// given
54+
(useContext as jest.Mock).mockReturnValue(appMock);
55+
56+
// when
57+
render(MockComponent, {
58+
localVue,
59+
pinia,
60+
});
61+
62+
// then
63+
expect(appMock.app.$vsf.$magento.api.currency)
64+
.toHaveBeenCalledWith({ currency: 'custom-currency-query' });
65+
});
66+
});

packages/theme/composables/useNewsletter/commands/updateSubscriptionCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const updateSubscriptionCommand = {
66
execute: async (context: UseContextReturn, params: UseNewsletterUpdateSubscriptionParams): Promise<SubscriptionStatusesEnum | null> => {
77
const { data } = await context.app.$vsf.$magento.api.subscribeEmailToNewsletter({
88
email: params.email,
9-
});
9+
}, params?.customQuery ?? null);
1010

1111
return data?.subscribeEmailToNewsletter?.status ?? null;
1212
},

packages/theme/composables/useReview/commands/addReviewCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const addReviewCommand = {
1212
...input
1313
} = params;
1414

15-
const { data } = await context.$magento.api.createProductReview(input);
15+
const { data } = await context.$magento.api.createProductReview(input, params?.customQuery ?? null);
1616

1717
Logger.debug('[Result]:', { data });
1818

packages/theme/composables/useReview/commands/loadCustomerReviewsCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const loadCustomerReviewsCommand = {
1111
execute: async (context: VsfContext, params?: ComposableFunctionArgs<CustomerProductReviewParams>) => {
1212
Logger.debug('[Magento] load customer review based on:', { params });
1313

14-
const { data } = await context.$magento.api.customerProductReview(params);
14+
const { data } = await context.$magento.api.customerProductReview(params, params?.customQuery ?? null);
1515

1616
Logger.debug('[Result]:', { data });
1717

packages/theme/composables/useReview/commands/loadReviewMetadataCommand.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Logger } from '~/helpers/logger';
22
import { VsfContext } from '~/composables/context';
3+
import { ComposableFunctionArgs } from '~/composables';
34

45
export const loadReviewMetadataCommand = {
5-
execute: async (context: VsfContext) => {
6+
execute: async (context: VsfContext, params?: ComposableFunctionArgs<{}>) => {
67
Logger.debug('[Magento] load review metadata');
78

8-
const { data } = await context.$magento.api.productReviewRatingsMetadata();
9+
const { data } = await context.$magento.api.productReviewRatingsMetadata(params?.customQuery ?? null);
910

1011
Logger.debug('[Result]:', { data });
1112

0 commit comments

Comments
 (0)