-
-
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.
- Loading branch information
Showing
5 changed files
with
121 additions
and
15 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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": "airbnb-base", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"import/extensions": ["warn", "ignorePackages"] | ||
} | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
"jest": true | ||
}, | ||
"extends": "airbnb-base", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"import/extensions": [ | ||
"warn", | ||
"ignorePackages", | ||
{ | ||
"js": "never" | ||
} | ||
] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,69 @@ | ||
// test all NotifierService methods | ||
import { jest } from '@jest/globals'; | ||
import NotifierService from './NotifierService.js'; | ||
|
||
const mockNotify = jest.fn(); | ||
const mockHello = jest.fn(); | ||
const mockGoodbye = jest.fn(); | ||
jest.unstable_mockModule('./providers/DiscordNotifierProvider', () => ({ | ||
hello: mockHello, | ||
goodbye: mockGoodbye, | ||
notify: mockNotify, | ||
})); | ||
|
||
describe('NotifierService', () => { | ||
const services = [ | ||
{ | ||
name: 'test', | ||
notifiers: [ | ||
{ | ||
type: 'discord', | ||
webhook: '1234', | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'test2', | ||
notifiers: [ | ||
{ | ||
type: 'discord', | ||
webhook: '1234', | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'test3', | ||
notifiers: [ | ||
{ | ||
type: 'discord', | ||
webhook: '1234', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('notify', () => { | ||
it('should call notify for each notifier', () => { | ||
NotifierService.notify(services[0], 'UP'); | ||
expect(mockNotify).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('hello', () => { | ||
it('should call hello for each notifier', () => { | ||
NotifierService.hello(services); | ||
expect(mockHello).toHaveBeenCalledTimes(3); | ||
}); | ||
}); | ||
|
||
describe('goodbye', () => { | ||
it('should call goodbye for each notifier', () => { | ||
NotifierService.goodbye(services); | ||
expect(mockGoodbye).toHaveBeenCalledTimes(3); | ||
}); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
src/services/notifier/providers/DiscordNotifierProvider.test.js
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,30 @@ | ||
import { jest } from '@jest/globals'; | ||
import { MessageBuilder, Webhook } from 'discord-webhook-node'; | ||
import DiscordNotifierProvider from './DiscordNotifierProvider'; | ||
|
||
const plop = jest.fn(); | ||
jest.unstable_mockModule('discord-webhook-node', () => ({ | ||
MessageBuilder, | ||
Webhook, | ||
})); | ||
|
||
describe('DiscordNotifierProvider', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should notify discord', () => { | ||
DiscordNotifierProvider.notify('name', 'status', { webhook: 'http://plop' }); | ||
expect(plop).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should say hello to discord', () => { | ||
DiscordNotifierProvider.hello('name', { webhook: 'http://' }); | ||
expect(mockSend).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should say goodbye to discord', async () => { | ||
await DiscordNotifierProvider.goodbye('name', { webhook: 'http://' }); | ||
expect(mockSend).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |