diff --git a/package.json b/package.json index 73b556f..97a1db7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "migros-api-wrapper", - "version": "1.1.15", + "version": "1.1.16", "description": "Making the api of migros more accessible to the public.", "keywords": [ "migros", @@ -12,7 +12,10 @@ ], "main": "dist/index.js", "typings": "./dist/index.d.ts", - "files": ["/dist", "/src"], + "files": [ + "/dist", + "/src" + ], "scripts": { "test": "jest", "lint": "eslint . --ext .ts", diff --git a/src/api/MigrosAPI.ts b/src/api/MigrosAPI.ts index 4bc1008..f71cceb 100644 --- a/src/api/MigrosAPI.ts +++ b/src/api/MigrosAPI.ts @@ -21,6 +21,10 @@ import { IProductSearchOptions, } from "./onesearch-oc-seaapi/product-search"; import { migusto } from "./migusto"; +import { + ICategoryListBody, + ICategoryListOptions, +} from "./onesearch-oc-seaapi/category"; export class MigrosAPI { private _leShopToken: string | undefined; @@ -118,6 +122,22 @@ export class MigrosAPI { }, }, productSearch: { + categoryList: async ( + categoryListBody: ICategoryListBody, + categoryListOptions?: ICategoryListOptions, + token: string | undefined = this.leShopToken, + ): Promise => { + if (!token) { + throw Error("LeShop Token is undefined"); + } + return await productSearch.listCategories( + categoryListBody, + { + leshopch: token, + }, + categoryListOptions, + ); + }, searchProduct: async ( productSearchBody: IProductSearchBody, productSearchOptions?: IProductSearchOptions, diff --git a/src/api/onesearch-oc-seaapi/category.ts b/src/api/onesearch-oc-seaapi/category.ts index 93a822b..32c3acc 100644 --- a/src/api/onesearch-oc-seaapi/category.ts +++ b/src/api/onesearch-oc-seaapi/category.ts @@ -24,7 +24,7 @@ export interface ICategoryListBody extends Record { language?: Language; productIds?: string[]; regionId?: Region; - requestSponsoredProducts: boolean; + requestSponsoredProducts?: boolean; sortFields?: SortFields[]; sortOrder?: SortOrder; } diff --git a/src/api/onesearch-oc-seaapi/index.ts b/src/api/onesearch-oc-seaapi/index.ts index 76e4fcb..60d3226 100644 --- a/src/api/onesearch-oc-seaapi/index.ts +++ b/src/api/onesearch-oc-seaapi/index.ts @@ -2,6 +2,6 @@ import { postProductSearch } from "./product-search"; import { categoryList } from "./category"; export const productSearch = { - searchProduct: postProductSearch, - category: categoryList -} + searchProduct: postProductSearch, + listCategories: categoryList, +}; diff --git a/tests/category-list.test.ts b/tests/category-list.test.ts new file mode 100644 index 0000000..16e3a7e --- /dev/null +++ b/tests/category-list.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, test } from "@jest/globals"; +import { MigrosAPI } from "../src"; +import { ICategoryListBody } from "../src/api/onesearch-oc-seaapi/category"; + +describe("Get a list of categories", () => { + test("Search for Dairy", async () => { + const guestInfo = await MigrosAPI.account.oauth2.getGuestToken(); + const categoryListBody: ICategoryListBody = { + from: 0, + categoryId: 7494731, + }; + const response = await MigrosAPI.products.productSearch.listCategories( + categoryListBody, + { + leshopch: guestInfo.token, + }, + ); + expect(response.categories[0].name).toBe( + "Dairy, eggs & fresh convenience food", + ); + }); +}); diff --git a/tests/migusto-recipe-products.test.ts b/tests/migusto-recipe-products.test.ts index 4c98585..f376a4d 100644 --- a/tests/migusto-recipe-products.test.ts +++ b/tests/migusto-recipe-products.test.ts @@ -12,6 +12,6 @@ describe("Search for recipe products", () => { }; const response = await MigrosAPI.migusto.recipeProducts(recipeProductOptions); - expect(response.productIds).toContain("233520695510"); + expect(response.productIds).toContain("220221000110"); }); });