Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/theme/composables/useConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from '@nuxtjs/composition-api';
import { Logger } from '~/helpers/logger';
import { useConfigStore } from '~/stores/config';
import { UseConfigErrors, UseConfigInterface } from './useConfig';
import type { UseConfigErrors, UseConfigInterface, UseConfigLoadParams } from './useConfig';

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

const load = async () => {
const load = async (params?: UseConfigLoadParams) => {
error.value.load = null;
loading.value = true;

Logger.debug('useConfig/load');

try {
const { data } = await app.$vsf.$magento.api.storeConfig();
const { data } = await app.$vsf.$magento.api.storeConfig(params?.customQuery ?? null);
configStore.$patch((state) => {
state.storeConfig = data.storeConfig || {};
});
Expand Down
6 changes: 6 additions & 0 deletions packages/theme/composables/useConfig/useConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComputedRef, DeepReadonly, Ref } from '@nuxtjs/composition-api';
import { StoreConfig } from '~/modules/GraphQL/types';
import { ComposableFunctionArgs } from '~/composables';

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

/**
* The params object accepted by the `load` method in the {@link useConfig|useConfig()} composable
*/
export type UseConfigLoadParams = ComposableFunctionArgs<{}>;

/**
* Data and methods returned from the {@link useConfig|useConfig()} composable
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const loadBlocksCommand = {
execute: async (context: VsfContext, params) => {
Logger.debug('[Magento]: Load CMS Blocks content', { params });
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const { data } = await context.$magento.api.cmsBlocks(params.identifiers);
const { data } = await context.$magento.api.cmsBlocks(params.identifiers, params.customQuery ?? null);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const loadContentCommand = {
execute: async (context: VsfContext, params) => {
Logger.debug('[Magento]: Load CMS Page content', { params });
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const { data } = await context.$magento.api.cmsPage(params.identifier);
const { data } = await context.$magento.api.cmsPage(params.identifier, params.customQuery ?? null);

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

Expand Down
2 changes: 1 addition & 1 deletion packages/theme/composables/useCountrySearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function useCountrySearch(): UseCountrySearchInterface {

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { defineComponent, onMounted, useContext } from '@nuxtjs/composition-api';
import { createLocalVue } from '@vue/test-utils';
import { PiniaVuePlugin, setActivePinia, createPinia } from 'pinia';
import { createTestingPinia } from '@pinia/testing';
import { render } from '@testing-library/vue';
import { useCurrency } from '../index';

const localVue = createLocalVue();
localVue.use(PiniaVuePlugin);
const pinia = createTestingPinia();
const appMock = {
app: {
$vsf: {
$magento: {
api: {
currency: jest.fn(),
},
},
},
},
};

jest.mock('@nuxtjs/composition-api', () => {
const actual = jest.requireActual('@nuxtjs/composition-api');
return {
...actual,
useContext: jest.fn(),
};
});

describe('useCurrency', () => {
beforeEach(() => {
setActivePinia(createPinia());
});

const MockComponent = defineComponent({
name: 'MockComponent',
setup() {
const { load } = useCurrency();

onMounted(async () => {
await load({
customQuery: {
currency: 'custom-currency-query',
},
});
});
},
template: '<div>mock</div>',
});

it('the load method should receive custom query', () => {
// given
(useContext as jest.Mock).mockReturnValue(appMock);

// when
render(MockComponent, {
localVue,
pinia,
});

// then
expect(appMock.app.$vsf.$magento.api.currency)
.toHaveBeenCalledWith({ currency: 'custom-currency-query' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const updateSubscriptionCommand = {
execute: async (context: UseContextReturn, params: UseNewsletterUpdateSubscriptionParams): Promise<SubscriptionStatusesEnum | null> => {
const { data } = await context.app.$vsf.$magento.api.subscribeEmailToNewsletter({
email: params.email,
});
}, params?.customQuery ?? null);

return data?.subscribeEmailToNewsletter?.status ?? null;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const addReviewCommand = {
...input
} = params;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const loadCustomerReviewsCommand = {
execute: async (context: VsfContext, params?: ComposableFunctionArgs<CustomerProductReviewParams>) => {
Logger.debug('[Magento] load customer review based on:', { params });

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Logger } from '~/helpers/logger';
import { VsfContext } from '~/composables/context';
import { ComposableFunctionArgs } from '~/composables';

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

const { data } = await context.$magento.api.productReviewRatingsMetadata();
const { data } = await context.$magento.api.productReviewRatingsMetadata(params?.customQuery ?? null);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const searchReviewsCommand = {
...input
} = params;

const { data } = await context.$magento.api.productReview(input as GetProductSearchParams);
const { data } = await context.$magento.api.productReview(input as GetProductSearchParams, params?.customQuery ?? null);

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

Expand Down
5 changes: 3 additions & 2 deletions packages/theme/composables/useReview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
UseReviewSearchParams,
UseReviewAddReviewParams,
} from './useReview';
import { ComposableFunctionArgs } from '~/composables';

/**
* Allows loading and adding product reviews.
Expand Down Expand Up @@ -59,13 +60,13 @@ export function useReview(): UseReviewInterface {
}
};

const loadReviewMetadata = async () => {
const loadReviewMetadata = async (params?: ComposableFunctionArgs<{}>) => {
Logger.debug('useReview/loadReviewMetadata');

try {
loading.value = true;
error.value.loadReviewMetadata = null;
return await loadReviewMetadataCommand.execute(context);
return await loadReviewMetadataCommand.execute(context, params);
} catch (err) {
error.value.loadReviewMetadata = err;
Logger.error('useReview/loadReviewMetadata', err);
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/composables/useReview/useReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface UseReviewInterface {
* Internally, it calls the {@link @vue-storefront/magento-api#productReviewRatingsMetadata} API endpoint
* and accepts the custom queries named `productReviewRatingsMetadata`.
*/
loadReviewMetadata(): Promise<ProductReviewRatingsMetadataQuery['productReviewRatingsMetadata']['items'] | []>;
loadReviewMetadata(params?: ComposableFunctionArgs<{}>): Promise<ProductReviewRatingsMetadataQuery['productReviewRatingsMetadata']['items'] | []>;

/**
* Submits a new product review
Expand Down
6 changes: 3 additions & 3 deletions packages/theme/composables/useUrlResolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@nuxtjs/composition-api';
import { RoutableInterface } from '~/modules/GraphQL/types';
import { Logger } from '~/helpers/logger';
import type { UseUrlResolverErrors, UseUrlResolverInterface } from '~/composables';
import type { ComposableFunctionArgs, UseUrlResolverErrors, UseUrlResolverInterface } from '~/composables';

/**
* Allows searching the resolver for current
Expand All @@ -24,14 +24,14 @@ export function useUrlResolver(): UseUrlResolverInterface {
search: null,
});

const search = async (): Promise<RoutableInterface | null> => {
const search = async (params?: ComposableFunctionArgs<{}>): Promise<RoutableInterface | null> => {
loading.value = true;
let results: RoutableInterface | null = null;

try {
const clearUrl = path.replace(/[a-z]+\/[cp|]\//gi, '');
Logger.debug('[Magento] Find information based on URL', { clearUrl });
const { data } = await context.$magento.api.route(clearUrl);
const { data } = await context.$magento.api.route(clearUrl, params?.customQuery ?? null);
results = data?.route ?? null;

if (!results) nuxtError({ statusCode: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function useCategory(): UseCategoryInterface {

try {
loading.value = true;
const { data } = await app.context.$vsf.$magento.api.categoryList(params);
const { data } = await app.context.$vsf.$magento.api.categoryList(params, params?.customQuery ?? null);
Logger.debug('[Result]:', { data });
categories.value = data.categories.items;
error.value.load = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export interface UseCategoryErrors {
}

/** The {@link useCategory} params object received by `load` function. */
export interface UseCategoryParamsInput {
export type UseCategoryParamsInput = ComposableFunctionArgs< {
pageSize: number;
}
}>;

/**
* Data and methods returned from the {@link useCategory} composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readonly, ref, useContext } from '@nuxtjs/composition-api';
import { Logger } from '~/helpers/logger';
import type { CategorySearchQueryVariables, CategoryTree } from '~/modules/GraphQL/types';
import type { UseCategorySearchErrors, UseCategorySearchInterface } from './useCategorySearch';
import { ComposableFunctionArgs } from '~/composables';

/**
* Allows searching for categories. It is
Expand All @@ -17,13 +18,13 @@ export function useCategorySearch(): UseCategorySearchInterface {
});
const result = ref<CategoryTree[] | null>(null);

const search = async (searchParams: CategorySearchQueryVariables) => {
Logger.debug('useCategory/search', searchParams);
const search = async (params: ComposableFunctionArgs<CategorySearchQueryVariables>) => {
Logger.debug('useCategory/search', params);

try {
loading.value = true;
const { filters } = searchParams;
const { data } = await app.context.$vsf.$magento.api.categorySearch({ filters });
const { filters } = params;
const { data } = await app.context.$vsf.$magento.api.categorySearch({ filters }, params?.customQuery ?? null);

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { readonly, ref } from '@nuxtjs/composition-api';
import { Logger } from '~/helpers/logger';
import type { ComposableFunctionArgs } from '~/composables/types';
import type { GetProductSearchParams } from '~/modules/catalog/product/types';
import useApi from '~/composables/useApi';
import { sortingOptions } from '~/modules/catalog/category/composables/useFacet/sortingOptions';
Expand All @@ -26,7 +25,7 @@ export function useFacet(): UseFacetInterface {
search: null,
});
const defaultItemsPerPage = 20;
const search = async (params?: ComposableFunctionArgs<FacetSearchParams>) => {
const search = async (params?: FacetSearchParams) => {
Logger.debug('useFacet/search', params);

result.value.input = params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function useRelatedProducts(): UseRelatedProductsInterface {

Logger.debug('[Magento] Load related products based on ', { searchParams });

const { data } = await app.$vsf.$magento.api.relatedProduct(searchParams as GetProductSearchParams);
const { data } = await app.$vsf.$magento.api.relatedProduct(searchParams as GetProductSearchParams, params?.customQuery ?? null);

Logger.debug('[Result] Related products:', { data });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function useUpsellProducts(): UseUpsellProductsInterface {
.$vsf
.$magento
.api
.upsellProduct(searchParams);
.upsellProduct(searchParams, params?.customQuery ?? null);

Logger.debug('[Result] Upsell products:', { data });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Logger } from '~/helpers/logger';
import { BillingCartAddress, Maybe, SetBillingAddressOnCartInput } from '~/modules/GraphQL/types';

export const saveBillingAddressCommand = {
execute: async (context, cartId, billingDetails): Promise<Maybe<BillingCartAddress>> => {
execute: async (context, cartId, billingDetails, customQuery): Promise<Maybe<BillingCartAddress>> => {
const {
apartment,
neighborhood,
Expand All @@ -29,6 +29,7 @@ export const saveBillingAddressCommand = {

const { data } = await context.$vsf.$magento.api.setBillingAddressOnCart(
setBillingAddressOnCartInput,
customQuery,
);

Logger.debug('[Result]:', { data });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export function useBilling(): UseBillingInterface {
return billingInfo;
};

const save = async ({ billingDetails }: UseBillingSaveParams): Promise<Maybe<BillingCartAddress>> => {
const save = async ({ billingDetails, customQuery = null }: UseBillingSaveParams): Promise<Maybe<BillingCartAddress>> => {
Logger.debug('useBilling.save');
let billingInfo = null;

try {
loading.value = true;
billingInfo = await saveBillingAddressCommand.execute(context, cart.value.id, billingDetails);
billingInfo = await saveBillingAddressCommand.execute(context, cart.value.id, billingDetails, customQuery);

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export type UseBillingLoadParams = ComposableFunctionArgs<{}>;
/**
* The params object accepted by the `save` method in the {@link useBilling|useBilling()} composable
*/
export interface UseBillingSaveParams {
export type UseBillingSaveParams = ComposableFunctionArgs<{
billingDetails: BillingDetails;
}
}>;

/**
* Data and methods returned from the {@link useBilling|useBilling()} composable
Expand Down
Loading