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

Commit

Permalink
feat(product): add unit tests to cover 100% of paramConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Kucmus committed Oct 15, 2019
1 parent 5c4e7c0 commit 1f87bdc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ParamsConverter } from "../../src/index";

describe("ParamsConverter", () => {
describe("getParams", () => {
it("should returns null if no params provided", async () => {
const paramsObject = ParamsConverter.getParams();
expect(paramsObject).toBeNull();
});
it("should returns only pagination if no other params provided", async () => {
const paramsObjectPage = ParamsConverter.getParams({ page: 1 });
expect(paramsObjectPage).toHaveProperty("page");

const paramsObjectLimit = ParamsConverter.getParams({ limit: 1 });
expect(paramsObjectLimit).toHaveProperty("limit");

const paramsObjectPageAndLimit = ParamsConverter.getParams({
page: 1,
limit: 5
});
expect(paramsObjectPageAndLimit).toHaveProperty("page");
expect(paramsObjectPageAndLimit).toHaveProperty("limit");
});
it("should returns only sorting if no other params provided", async () => {
const paramsObject = ParamsConverter.getParams(null, { sort: "-name" });
expect(paramsObject).toHaveProperty("sort");
expect(paramsObject).not.toBeNull();
if (paramsObject) {
expect(paramsObject.sort).toEqual("-name");
} else {
console.error(`there is no sort property included`);
}
});
it("should returns filter property if any provided", async () => {
const paramsObject = ParamsConverter.getParams(null, null, {
filter: {}
});
expect(paramsObject).toHaveProperty("filter");
});
it("should returns all types of params if all provided", async () => {
const paramsObject = ParamsConverter.getParams(
{ page: 1 },
{ sort: "name" },
{ filter: {} }
);
expect(paramsObject).toHaveProperty("page");
expect(paramsObject).toHaveProperty("sort");
expect(paramsObject).toHaveProperty("filter");
});
});
});
2 changes: 2 additions & 0 deletions packages/shopware-6-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { setup, config } from "./settings";
export { Category, CategoryService } from "./categoryService";
export { ProductService } from "./services/productService";
export { ParamsConverter } from "./helpers/paramsConverter";

0 comments on commit 1f87bdc

Please sign in to comment.