-
Notifications
You must be signed in to change notification settings - Fork 0
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 #45 from JHWelch/add-health-check
Add health check
- Loading branch information
Showing
20 changed files
with
247 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { beforeEach, describe, expect, it, jest } from '@jest/globals' | ||
import Config from '../../src/config/config' | ||
|
||
beforeEach(() => { | ||
jest.resetModules() | ||
process.env = { | ||
NOTION_TOKEN: 'NOTION_TOKEN', | ||
DATABASE_ID: 'DATABASE_ID', | ||
PORT: '3000', | ||
GOOGLE_CLOUD_PROJECT: 'GOOGLE_CLOUD_PROJECT', | ||
ADMIN_EMAIL: '[email protected]', | ||
TMDB_READ_KEY: 'TMDB_READ_KEY', | ||
CALENDAR_URL: 'https://CALENDAR_URL', | ||
} | ||
}) | ||
|
||
|
||
describe('env variables all present', () => { | ||
it('returns the config', () => { | ||
const config = new Config() | ||
|
||
expect(config.notionToken).toBe('NOTION_TOKEN') | ||
expect(config.notionDatabaseId).toBe('DATABASE_ID') | ||
expect(config.port).toBe(3000) | ||
expect(config.googleCloudProject).toBe('GOOGLE_CLOUD_PROJECT') | ||
expect(config.adminEmail).toBe('[email protected]') | ||
expect(config.tmdbApiKey).toBe('TMDB_READ_KEY') | ||
expect(config.calendarUrl).toBe('https://CALENDAR_URL') | ||
}) | ||
}) | ||
|
||
describe('env missing NOTION_TOKEN', () => { | ||
beforeEach(() => { | ||
delete process.env.NOTION_TOKEN | ||
}) | ||
|
||
it('throws an error', () => { | ||
expect(() => new Config()).toThrowError('NOTION_TOKEN is missing') | ||
}) | ||
}) | ||
|
||
describe('env missing DATABASE_ID', () => { | ||
beforeEach(() => { | ||
delete process.env.DATABASE_ID | ||
}) | ||
|
||
it('throws an error', () => { | ||
expect(() => new Config()).toThrowError('DATABASE_ID is missing') | ||
}) | ||
}) | ||
|
||
describe('env missing PORT', () => { | ||
beforeEach(() => { | ||
delete process.env.PORT | ||
}) | ||
|
||
it('defaults to 8080', () => { | ||
expect(new Config().port).toBe(8080) | ||
}) | ||
}) | ||
|
||
describe('env missing GOOGLE_CLOUD_PROJECT', () => { | ||
beforeEach(() => { | ||
delete process.env.GOOGLE_CLOUD_PROJECT | ||
}) | ||
|
||
it('throws an error', () => { | ||
expect(() => new Config()).toThrowError('GOOGLE_CLOUD_PROJECT is missing') | ||
}) | ||
}) | ||
|
||
|
||
describe('env missing ADMIN_EMAIL', () => { | ||
beforeEach(() => { | ||
delete process.env.ADMIN_EMAIL | ||
}) | ||
|
||
it('throws an error', () => { | ||
expect(() => new Config()).toThrowError('ADMIN_EMAIL is missing') | ||
}) | ||
}) | ||
|
||
describe('env missing TMDB_READ_KEY', () => { | ||
beforeEach(() => { | ||
delete process.env.TMDB_READ_KEY | ||
}) | ||
|
||
it('throws an error', () => { | ||
expect(() => new Config()).toThrowError('TMDB_READ_KEY is missing') | ||
}) | ||
}) | ||
|
||
describe('env missing CALENDAR_URL', () => { | ||
beforeEach(() => { | ||
delete process.env.CALENDAR_URL | ||
}) | ||
|
||
it('throws an error', () => { | ||
expect(() => new Config()).toThrowError('CALENDAR_URL is missing') | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
import { beforeEach, describe, expect, it } from '@jest/globals' | ||
import { getMockReq, getMockRes } from '@jest-mock/express' | ||
import HealthCheckController from '../../src/controllers/healthCheckController' | ||
|
||
const { res, mockClear } = getMockRes() | ||
|
||
beforeEach(() => { | ||
mockClear() | ||
}) | ||
|
||
describe('index', () => { | ||
it('should respond ok', async () => { | ||
const req = getMockReq() | ||
|
||
await HealthCheckController.index(req, res) | ||
|
||
expect(res.status).toHaveBeenCalledWith(200) | ||
expect(res.send).toHaveBeenCalledWith('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 |
---|---|---|
|
@@ -4,11 +4,11 @@ import { getMockReq, getMockRes } from '@jest-mock/express' | |
import { Timestamp, addDoc } from 'firebase/firestore' | ||
import { FirebaseMock } from '../support/firebaseMock' | ||
import FirestoreAdapter from '../../src/data/firestore/firestoreAdapter' | ||
import { mockConfig } from '../support/mockConfig' | ||
|
||
const { res, mockClear } = getMockRes() | ||
|
||
beforeEach(() => { | ||
process.env.ADMIN_EMAIL = '[email protected]' | ||
jest.clearAllMocks() | ||
mockClear() | ||
}) | ||
|
@@ -23,7 +23,7 @@ describe('store', () => { | |
let firestoreAdapter: FirestoreAdapter | ||
|
||
beforeEach(() => { | ||
firestoreAdapter = new FirestoreAdapter() | ||
firestoreAdapter = new FirestoreAdapter(mockConfig()) | ||
}) | ||
|
||
describe('has correct week', () => { | ||
|
@@ -69,7 +69,7 @@ describe('store', () => { | |
expect(addDoc).toHaveBeenCalledWith( | ||
FirebaseMock.mockCollection('mail'), | ||
{ | ||
to: 'admin@example.com', | ||
to: 'ADMIN_EMAIL@example.com', | ||
message: { | ||
subject: 'TNMC RSVP: test name', | ||
// eslint-disable-next-line max-len | ||
|
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
Oops, something went wrong.