Skip to content

Commit

Permalink
Added #304 test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Ferrero committed Jan 11, 2022
1 parent cc9cc07 commit 976e831
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/moleculer-db-adapter-sequelize/test/unit/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const { ServiceBroker } = require("moleculer");
jest.mock("sequelize");

const model = {
tableName: "posts",
primaryKeyAttribute: 'id',
sync: jest.fn(() => Promise.resolve()),
findAll: jest.fn(() => Promise.resolve()),
count: jest.fn(() => Promise.resolve()),
Expand Down Expand Up @@ -40,6 +42,7 @@ function protectReject(err) {
const fakeModel = {
name: "posts",
define: {
id: { type: "number", primaryKey: true },
a: 5
},
options: {
Expand Down Expand Up @@ -163,7 +166,10 @@ describe("Test SequelizeAdapter", () => {
adapter.model.findAll.mockClear();
adapter.createCursor(null, true);
expect(adapter.model.count).toHaveBeenCalledTimes(1);
expect(adapter.model.count).toHaveBeenCalledWith();
expect(adapter.model.count).toHaveBeenCalledWith({
distinct: true,
col: `${model.tableName}.${model.primaryKeyAttribute}`
});
});

it("call with query", () => {
Expand All @@ -179,7 +185,11 @@ describe("Test SequelizeAdapter", () => {
let query = {};
adapter.createCursor({ query }, true);
expect(adapter.model.count).toHaveBeenCalledTimes(1);
expect(adapter.model.count).toHaveBeenCalledWith({ where: query });
expect(adapter.model.count).toHaveBeenCalledWith({
distinct: true,
col: `${model.tableName}.${model.primaryKeyAttribute}`,
where: query
});
});

it("call with sort string", () => {
Expand Down

0 comments on commit 976e831

Please sign in to comment.