This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(product): add unit tests to cover 100% of paramConverter
- Loading branch information
Maciej Kucmus
committed
Oct 15, 2019
1 parent
5c4e7c0
commit 1f87bdc
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/shopware-6-client/__tests__/helpers/paramsConverter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |