Skip to content

Commit

Permalink
added category lists
Browse files Browse the repository at this point in the history
  • Loading branch information
aliyss committed Sep 7, 2024
1 parent 445604c commit 673bc0e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions src/api/MigrosAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,6 +122,22 @@ export class MigrosAPI {
},
},
productSearch: {
categoryList: async (
categoryListBody: ICategoryListBody,
categoryListOptions?: ICategoryListOptions,
token: string | undefined = this.leShopToken,
): Promise<any> => {

Check warning on line 129 in src/api/MigrosAPI.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected any. Specify a different type
if (!token) {
throw Error("LeShop Token is undefined");
}
return await productSearch.listCategories(
categoryListBody,
{
leshopch: token,
},
categoryListOptions,
);
},
searchProduct: async (
productSearchBody: IProductSearchBody,
productSearchOptions?: IProductSearchOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/api/onesearch-oc-seaapi/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ICategoryListBody extends Record<string, any> {
language?: Language;
productIds?: string[];
regionId?: Region;
requestSponsoredProducts: boolean;
requestSponsoredProducts?: boolean;
sortFields?: SortFields[];
sortOrder?: SortOrder;
}
Expand Down
6 changes: 3 additions & 3 deletions src/api/onesearch-oc-seaapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { postProductSearch } from "./product-search";
import { categoryList } from "./category";

export const productSearch = {
searchProduct: postProductSearch,
category: categoryList
}
searchProduct: postProductSearch,
listCategories: categoryList,
};
22 changes: 22 additions & 0 deletions tests/category-list.test.ts
Original file line number Diff line number Diff line change
@@ -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",
);
});
});
2 changes: 1 addition & 1 deletion tests/migusto-recipe-products.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

0 comments on commit 673bc0e

Please sign in to comment.