Skip to content

Commit

Permalink
feat: fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NithinKuruba committed Oct 27, 2023
1 parent ea3de11 commit ee390a9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docker/kc-cron-job/__tests__/zip-logs.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { saveFilesToDatabase, getDate, getClient } = require('../event-logs');
const { saveFilesToDatabase, getDate } = require('../event-logs');
const { getPgClient } = require('../helpers.js');
const fsPromises = require('fs').promises;
const path = require('path');
const { Client } = require('pg');
Expand All @@ -19,7 +20,7 @@ jest.mock('pg', () => {
const mockClient = {
connect: jest.fn(),
query: jest.fn(),
end: jest.fn(),
end: jest.fn()
};
return { Client: jest.fn(() => mockClient) };
});
Expand All @@ -37,7 +38,7 @@ const clearFiles = () => fsPromises.rmdir(dir, { force: true, recursive: true })
describe('Save Files to Database', () => {
let client;
beforeEach(() => {
client = new Client();
client = getPgClient();
});

afterAll(async () => {
Expand All @@ -52,13 +53,13 @@ describe('Save Files to Database', () => {

// Empty line in logs should log a message indicating could not be parsed
const jsonParseError = console.info.mock.calls.find((call) =>
call[0].startsWith('Error trying to JSON parse line'),
call[0].startsWith('Error trying to JSON parse line')
);
expect(jsonParseError).not.toBe(undefined);

// Log with missing sequence should log a message indicating could not be uploaded
const unexpectedFormatError = console.info.mock.calls.find((call) =>
call[0].startsWith('Log does not have expected format'),
call[0].startsWith('Log does not have expected format')
);
expect(unexpectedFormatError).not.toBe(undefined);

Expand Down

0 comments on commit ee390a9

Please sign in to comment.