-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from santoshshinde2012/dev
updates test cases
- Loading branch information
Showing
12 changed files
with
744 additions
and
548 deletions.
There are no files selected for viewing
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
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
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
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
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,36 +1,33 @@ | ||
import 'jest'; | ||
import express from 'express'; | ||
import request from 'supertest'; | ||
import { | ||
StatusCodes, | ||
} from 'http-status-codes'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import IntegrationHelpers from '../helpers/Integration-helpers'; | ||
|
||
describe('status integration tests', () => { | ||
let app: express.Application; | ||
|
||
beforeAll(async() => { | ||
app = await IntegrationHelpers.getApp(); | ||
}); | ||
let app: express.Application; | ||
|
||
beforeAll(async () => { | ||
app = await IntegrationHelpers.getApp(); | ||
}); | ||
|
||
it('can get default route success', async () => { | ||
const response = await request(app) | ||
.get('/') | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', 'application/json; charset=utf-8'); | ||
it('can get default route success', async () => { | ||
const response = await request(app) | ||
.get('/') | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', 'application/json; charset=utf-8'); | ||
|
||
const { status } = response; | ||
expect(status).toBe(StatusCodes.OK); | ||
}); | ||
const { status } = response; | ||
expect(status).toBe(StatusCodes.OK); | ||
}); | ||
|
||
it('can get default web route success', async () => { | ||
const response = await request(app) | ||
.get('/web') | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', 'application/json; charset=utf-8'); | ||
it('can get default web route success', async () => { | ||
const response = await request(app) | ||
.get('/web') | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', 'application/json; charset=utf-8'); | ||
|
||
const { status } = response; | ||
expect(status).toBe(StatusCodes.OK); | ||
}); | ||
const { status } = response; | ||
expect(status).toBe(StatusCodes.OK); | ||
}); | ||
}); |
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,56 @@ | ||
import database from '../../src/database'; | ||
import App from '../../src/App'; | ||
import logger from '../../src/lib/logger'; | ||
|
||
jest.mock('../../src/database', () => ({ | ||
authenticate: jest.fn(), | ||
sync: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../src/routes', () => ({ | ||
registerRoutes: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../src/lib/logger', () => ({ | ||
info: jest.fn(), | ||
error: jest.fn(), | ||
})); | ||
|
||
describe('App', () => { | ||
let app: App; | ||
|
||
beforeEach(() => { | ||
app = new App(); | ||
}); | ||
|
||
describe('assertDatabaseConnection', () => { | ||
it('should log success message when database connection is established', async () => { | ||
(database.authenticate as jest.Mock).mockResolvedValueOnce( | ||
undefined, | ||
); | ||
(database.sync as jest.Mock).mockResolvedValueOnce(undefined); | ||
|
||
await app['assertDatabaseConnection'](); | ||
|
||
expect(database.authenticate).toHaveBeenCalled(); | ||
expect(database.sync).toHaveBeenCalled(); | ||
expect(logger.info).toHaveBeenCalledWith( | ||
'Connection has been established successfully.', | ||
); | ||
expect(logger.error).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should log error message when database connection fails', async () => { | ||
const error = new Error('Connection failed'); | ||
(database.authenticate as jest.Mock).mockRejectedValueOnce(error); | ||
|
||
await app['assertDatabaseConnection'](); | ||
|
||
expect(database.authenticate).toHaveBeenCalled(); | ||
expect(logger.error).toHaveBeenCalledWith( | ||
'Unable to connect to the database:', | ||
error, | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.