Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Feat/new api for v6.2 #720

Merged
merged 30 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ddf6226
feat(composables): update customer specific areas for new api
mkucmus Mar 31, 2020
654655b
feat(client): move customer-related functionalities to store-api
mkucmus Mar 31, 2020
52a75b9
chore: lint
mkucmus Mar 31, 2020
350a82f
Merge branch 'feat/use-store-api-for-customer-#547' into feat/new-api…
mkucmus May 6, 2020
9a43074
feat(client): adjustments for SW v6.2 (store-api)
mkucmus May 8, 2020
782ebd8
feat(commons): adjustments for SW v6.2 (store-api)
mkucmus May 8, 2020
fe9bed0
feat(composables): adjustments for SW v6.2 (store-api)
mkucmus May 8, 2020
2ace75b
feat(default-theme): adjustments for SW v6.2 (store-api)
mkucmus May 8, 2020
88c097e
feat(nuxt-module): remove api suffix after API domain URL
mkucmus May 8, 2020
f4fbf06
docs(client): product-listing definitions
mkucmus May 11, 2020
eebb3eb
feat: handle product-listing endpoint
mkucmus May 12, 2020
29d36cd
Merge branch 'master' into feat/new-api-for-v6.2
mkucmus May 12, 2020
eaf4fa6
fix: restore old api key
mkucmus May 12, 2020
5159787
fix: delete uknown dir
mkucmus May 12, 2020
35f121f
fix(commons): module imports
mkucmus May 12, 2020
6e51eb5
fix(defaul-theme): remove testing data
mkucmus May 12, 2020
e9a92ea
feat(client): prefix endpoints with api type
mkucmus May 12, 2020
443b250
Merge branch 'master' into feat/new-api-for-v6.2
mkucmus May 12, 2020
f1ce40b
fix: pagination scope
mkucmus May 12, 2020
21c1e07
Merge branch 'feat/new-api-for-v6.2' of github.com:DivanteLtd/shopwar…
mkucmus May 12, 2020
4e7ca47
Merge branch 'master' into feat/new-api-for-v6.2
patzick May 13, 2020
116db6c
feat(client): update API version compatibility
mkucmus May 13, 2020
7b2934c
docs(client): version image
mkucmus May 13, 2020
880b805
Merge branch 'feat/new-api-for-v6.2' of github.com:DivanteLtd/shopwar…
mkucmus May 13, 2020
9cbce90
fix: implement CR comments
mkucmus May 13, 2020
8f1d74c
feat: add TODO issue URL
mkucmus May 13, 2020
46667a4
fix: uncomment some parts of useProductListing
mkucmus May 13, 2020
3c19d9e
fix: route change condition - allow listing elements to be empty
mkucmus May 13, 2020
a872ec9
chore: fix tests
patzick May 13, 2020
228188a
chore: tests
patzick May 13, 2020
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
3 changes: 2 additions & 1 deletion api/composables.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { NavigationElement } from '@shopware-pwa/commons/interfaces/models/conte
import { Order } from '@shopware-pwa/commons/interfaces/models/checkout/order/Order';
import { PaymentMethod } from '@shopware-pwa/commons/interfaces/models/checkout/payment/PaymentMethod';
import { Product } from '@shopware-pwa/commons/interfaces/models/content/product/Product';
import { ProductListingResult } from '@shopware-pwa/commons/interfaces/response/ProductListingResult';
import { Ref } from '@vue/composition-api';
import { Salutation } from '@shopware-pwa/commons/interfaces/models/system/salutation/Salutation';
import { SessionContext } from '@shopware-pwa/commons/interfaces/response/SessionContext';
Expand Down Expand Up @@ -201,7 +202,7 @@ export interface UseProductListing {
}

// @alpha (undocumented)
export const useProductListing: (initialProducts?: Product[]) => UseProductListing;
export const useProductListing: (initialListing?: ProductListingResult | undefined) => UseProductListing;

// @alpha (undocumented)
export interface UseProductSearch {
Expand Down
6 changes: 6 additions & 0 deletions api/shopware-6-client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { NotFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter'
import { Order } from '@shopware-pwa/commons/interfaces/models/checkout/order/Order';
import { PaymentMethod } from '@shopware-pwa/commons/interfaces/models/checkout/payment/PaymentMethod';
import { Product } from '@shopware-pwa/commons/interfaces/models/content/product/Product';
import { ProductListingResult } from '@shopware-pwa/commons/interfaces/response/ProductListingResult';
import { RangeFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter';
import { Salutation } from '@shopware-pwa/commons/interfaces/models/system/salutation/Salutation';
import { SearchCriteria } from '@shopware-pwa/commons/interfaces/search/SearchCriteria';
Expand Down Expand Up @@ -166,6 +167,9 @@ export function getCustomerOrderDetails(orderId: string): Promise<Order>;
// @beta
export function getCustomerOrders(): Promise<Order[]>;

// @alpha
export const getListingProducts: (categoryId: string, searchCriteria?: SearchCriteria | undefined) => Promise<ProductListingResult>;

// @alpha (undocumented)
export function getNavigation(params: GetNavigationParams): Promise<NavigationResponse>;

Expand Down Expand Up @@ -285,6 +289,8 @@ export interface ShopwareParams {
// (undocumented)
limit?: number;
// (undocumented)
p?: number;
// (undocumented)
page?: number;
// (undocumented)
sort?: string;
Expand Down
13 changes: 13 additions & 0 deletions packages/commons/interfaces/response/ProductListingResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Product } from "@shopware-pwa/commons/interfaces/models/content/product/Product";

export interface ProductListingResult<> {
patzick marked this conversation as resolved.
Show resolved Hide resolved
apiAlias: string;
patzick marked this conversation as resolved.
Show resolved Hide resolved
total: number;
elements: Product[];
sorting: string;
page: number;
limit: number;
sortings: any[];
aggregations: any[];
currentFilters: any[];
patzick marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 11 additions & 5 deletions packages/commons/interfaces/search/SearchCriteria.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Pagination } from "./Pagination";
import { Pagination } from "@shopware-pwa/commons/interfaces/search/Pagination";
import {
EqualsFilter,
RangeFilter,
MultiFilter,
EqualsAnyFilter,
} from "./SearchFilter";
import { Association } from "./Association";
import { Aggregation } from "./Aggregation";
import { TotalCountMode } from "./TotalCountMode";
} from "@shopware-pwa/commons/interfaces/search/SearchFilter";
import { Association } from "@shopware-pwa/commons/interfaces/search/Association";
import { Aggregation } from "@shopware-pwa/commons/interfaces/search/Aggregation";
import { TotalCountMode } from "@shopware-pwa/commons/interfaces/search/TotalCountMode";

/**
* @alpha
Expand All @@ -23,12 +23,18 @@ export interface Grouping {
field: string;
}

export enum ApiType {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this enum can be moved into searchConverter.ts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right!

store = "store-api",
salesChannel = "sales-channel-api",
}

/**
* configutarion.displayParents: true - if you want to show all the products
*
* @alpha
*/
export interface SearchCriteria {
apiType?: ApiType;
patzick marked this conversation as resolved.
Show resolved Hide resolved
filters?: Array<EqualsFilter | EqualsAnyFilter | RangeFilter | MultiFilter>;
pagination?: Pagination;
sort?: Sort;
Expand Down
13 changes: 13 additions & 0 deletions packages/composables/__tests__/useCms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ describe("Shopware composables", () => {
expect(error.value).toStrictEqual({ message: "Something went wrong..." });
});

it("should performs search default pagination limit if not provided", async () => {
const { search, page } = useCms();
mockedGetPage.getPage.mockResolvedValueOnce({} as any);
expect(page.value).toEqual(null);
await search("");
expect(mockedGetPage.getPage).toBeCalledWith("", {
configuration: {
associations: [{ associations: [{ name: "group" }], name: "options" }],
},
pagination: { limit: 10 },
});
});

it("should return activeCategoryId if it's included within the page object", async () => {
const { categoryId, search } = useCms();
const response: shopwareClient.PageResolverResult<any> = {
Expand Down
91 changes: 79 additions & 12 deletions packages/composables/__tests__/useProductListing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("Composables - useProductListing", () => {
expect(products.value).toHaveLength(0);
});
it("should have empty array if no products passed", async () => {
const { products } = useProductListing([]);
const { products } = useProductListing({ elements: [] } as any);
expect(products.value).toHaveLength(0);
});
});
Expand Down Expand Up @@ -99,30 +99,57 @@ describe("Composables - useProductListing", () => {
expect(selectedFilters.value).toHaveProperty("color");
expect(selectedFilters.value.color).toStrictEqual([]);
});

it("selectedFilters should append the filters array on force", async () => {
const {
selectedFilters,
toggleFilter,
resetFilters,
} = useProductListing();
resetFilters();

toggleFilter({
type: SearchFilterType.EQUALS,
value: "white",
field: "color",
} as EqualsFilter);

toggleFilter({
type: SearchFilterType.EQUALS,
value: "black",
field: "color",
} as EqualsFilter),
true;

expect(selectedFilters.value).toHaveProperty("color");
expect(selectedFilters.value.color).toStrictEqual(["white", "black"]);
});
});

describe("search", () => {
it("should reset search criteria on category change event", async () => {
const { products, selectedFilters } = useProductListing([
{ product: "1" } as any,
]);
const { products, selectedFilters } = useProductListing({
elements: [{ product: "1" }],
} as any);
expect(selectedFilters.value).toStrictEqual({});

expect(products.value).toHaveLength(1);
});

it("should set loading property to false when search is done", async () => {
const { loading, search } = useProductListing([{ product: "1" } as any]);
const { loading, search } = useProductListing({
elements: [{ product: "1" }],
} as any);
await search();
expect(loading.value).toBe(false);
});

//
it("should return default total and empty product listing when page resolver fails", async () => {
mockedGetPage.getProducts.mockResolvedValueOnce({} as any);
mockedGetPage.getListingProducts.mockResolvedValueOnce({} as any);

const { pagination, products, search } = useProductListing();
await search();
const { products, search, pagination } = useProductListing();
search();
expect(pagination.value).toStrictEqual({
currentPage: 1,
perPage: 10,
Expand All @@ -132,8 +159,8 @@ describe("Composables - useProductListing", () => {
});

it("should return products if exist", async () => {
mockedGetPage.getProducts.mockResolvedValueOnce({
data: [
mockedGetPage.getListingProducts.mockResolvedValueOnce({
elements: [
{
id: "123456",
},
Expand Down Expand Up @@ -175,18 +202,58 @@ describe("Composables - useProductListing", () => {
it("should perform no search and leave default pagination if no change performed", async () => {
const { pagination, changePagination } = useProductListing();

changePagination(undefined as any);
await changePagination(undefined as any);
expect(pagination.value).toStrictEqual({
currentPage: 1,
perPage: 10,
total: 0,
});
});

it("should not change pagination state to privided one once a useProductListing argument is passed hasn't any required fields", async () => {
const { pagination } = useProductListing({
// page: undefined,
// total: undefined,
// limit: undefined,
elements: [{ id: "123456" }],
} as any);

expect(pagination.value).toStrictEqual({
currentPage: 1,
perPage: 10,
total: 0,
});
});

it("should not change pagination state to privided one once a useProductListing argument is passed has no pagination data", async () => {
const { pagination } = useProductListing(undefined as any);

expect(pagination.value).toStrictEqual({
currentPage: 1,
perPage: 10,
total: 0,
});
});

it("should change pagination state to privided one as a useProductListing argument is passed", async () => {
const { pagination } = useProductListing({
total: 6,
page: 2,
limit: 10,
elements: [{ id: "123456" }],
} as any);

expect(pagination.value).toStrictEqual({
currentPage: 2,
perPage: 10,
total: 6,
});
});

it("should perform change the shared pagination object if change succeeds", async () => {
const { pagination, changePagination } = useProductListing();

changePagination(10);
await changePagination(10);
expect(pagination.value).toStrictEqual({
currentPage: 10,
perPage: 10,
Expand Down
Loading