Skip to content

Commit

Permalink
Merge pull request #66 from osstotalsoft/fix-logging-tests
Browse files Browse the repository at this point in the history
fix prisma logging tests
  • Loading branch information
alexandra-c authored Jan 20, 2022
2 parents 65bc02c + 1e92539 commit 3c6ddc0
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,36 @@ describe("logging plugin tests:", () => {
expect(context.logs[1].loggingLevel).toBe(loggingLevels.DEBUG)
})

it("logDbError should clears logs from context, call insert logs and return new ApolloError: ", async () => {
it("logDbError should clear logs from context, call insert logs and return new ApolloError: ", async () => {
//arrange
const message = "Error log message"
const code = "Error_Message_Code"
const errorMessage = "ErrorMessage"

const context = { logs: [], dbInstance: jest.fn(() => ({ insert: jest.fn(() => []) })) }

const loggingUtils = require("../loggingUtils")
jest.mock("../loggingUtils");
loggingUtils.saveLogs.mockResolvedValue(null);
global.console = { error: jest.fn() }
global.console = { log: jest.fn(), error: jest.fn() }

<%_ if(dataLayer == "knex") {_%>
const context = { logs: [], dbInstance: jest.fn(() => ({ insert: jest.fn(() => []) })) }
<%_ } else if(dataLayer == "prisma") {_%>
const context = { logs: [] }
jest.mock('../../../utils/prisma', () => ({
eventLog: {
createMany: jest.fn().mockReturnValue([])
}
}))
<%_}_%>

//act
const res = await logDbError(context, message, code, loggingLevels.ERROR, new Error(errorMessage))

//assert
expect(context.logs).toBe(null)
<%_ if(dataLayer == "knex") {_%>
expect(context.dbInstance.mock.calls.length).toBe(1);
<%_}_%>
expect(console.error).toBeCalled()
expect(res).toBeInstanceOf(ApolloError)

Expand Down

0 comments on commit 3c6ddc0

Please sign in to comment.