Skip to content

Commit 673bc0e

Browse files
committed
added category lists
1 parent 445604c commit 673bc0e

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "migros-api-wrapper",
3-
"version": "1.1.15",
3+
"version": "1.1.16",
44
"description": "Making the api of migros more accessible to the public.",
55
"keywords": [
66
"migros",
@@ -12,7 +12,10 @@
1212
],
1313
"main": "dist/index.js",
1414
"typings": "./dist/index.d.ts",
15-
"files": ["/dist", "/src"],
15+
"files": [
16+
"/dist",
17+
"/src"
18+
],
1619
"scripts": {
1720
"test": "jest",
1821
"lint": "eslint . --ext .ts",

src/api/MigrosAPI.ts

+20
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import {
2121
IProductSearchOptions,
2222
} from "./onesearch-oc-seaapi/product-search";
2323
import { migusto } from "./migusto";
24+
import {
25+
ICategoryListBody,
26+
ICategoryListOptions,
27+
} from "./onesearch-oc-seaapi/category";
2428

2529
export class MigrosAPI {
2630
private _leShopToken: string | undefined;
@@ -118,6 +122,22 @@ export class MigrosAPI {
118122
},
119123
},
120124
productSearch: {
125+
categoryList: async (
126+
categoryListBody: ICategoryListBody,
127+
categoryListOptions?: ICategoryListOptions,
128+
token: string | undefined = this.leShopToken,
129+
): Promise<any> => {
130+
if (!token) {
131+
throw Error("LeShop Token is undefined");
132+
}
133+
return await productSearch.listCategories(
134+
categoryListBody,
135+
{
136+
leshopch: token,
137+
},
138+
categoryListOptions,
139+
);
140+
},
121141
searchProduct: async (
122142
productSearchBody: IProductSearchBody,
123143
productSearchOptions?: IProductSearchOptions,

src/api/onesearch-oc-seaapi/category.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface ICategoryListBody extends Record<string, any> {
2424
language?: Language;
2525
productIds?: string[];
2626
regionId?: Region;
27-
requestSponsoredProducts: boolean;
27+
requestSponsoredProducts?: boolean;
2828
sortFields?: SortFields[];
2929
sortOrder?: SortOrder;
3030
}

src/api/onesearch-oc-seaapi/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { postProductSearch } from "./product-search";
22
import { categoryList } from "./category";
33

44
export const productSearch = {
5-
searchProduct: postProductSearch,
6-
category: categoryList
7-
}
5+
searchProduct: postProductSearch,
6+
listCategories: categoryList,
7+
};

tests/category-list.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, expect, test } from "@jest/globals";
2+
import { MigrosAPI } from "../src";
3+
import { ICategoryListBody } from "../src/api/onesearch-oc-seaapi/category";
4+
5+
describe("Get a list of categories", () => {
6+
test("Search for Dairy", async () => {
7+
const guestInfo = await MigrosAPI.account.oauth2.getGuestToken();
8+
const categoryListBody: ICategoryListBody = {
9+
from: 0,
10+
categoryId: 7494731,
11+
};
12+
const response = await MigrosAPI.products.productSearch.listCategories(
13+
categoryListBody,
14+
{
15+
leshopch: guestInfo.token,
16+
},
17+
);
18+
expect(response.categories[0].name).toBe(
19+
"Dairy, eggs & fresh convenience food",
20+
);
21+
});
22+
});

tests/migusto-recipe-products.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ describe("Search for recipe products", () => {
1212
};
1313
const response =
1414
await MigrosAPI.migusto.recipeProducts(recipeProductOptions);
15-
expect(response.productIds).toContain("233520695510");
15+
expect(response.productIds).toContain("220221000110");
1616
});
1717
});

0 commit comments

Comments
 (0)