-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove interval logging; make eslint ignore any files outside of src or tests; add updateHandler unit test; remove unnecessary logging * mock env in updateHandler * mock env properly; change log,error to trace * format code
- Loading branch information
1 parent
c44eb20
commit 06e7a5e
Showing
9 changed files
with
119 additions
and
31 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
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,6 +1,6 @@ | ||
import { adminDM, getIntervalId } from '../server' | ||
import { adminDM, intervalId } from '../server' | ||
|
||
export async function throwErrorToAdmin(msg: string) { | ||
await adminDM.send(msg) | ||
clearInterval(getIntervalId()) | ||
clearInterval(intervalId.value) | ||
} |
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,93 @@ | ||
import db, { NotificationChannel } from '@/database/database' | ||
import { updateAll } from '@/scraper/updateAll' | ||
import { adminDM, client } from '@/server' | ||
import updateHandler from '@/utils/updateHandler' | ||
import { DiscordAPIError } from 'discord.js' | ||
|
||
jest.mock('@/env/env', () => {}) | ||
jest.mock('@/server', () => { | ||
return { | ||
client: { | ||
channels: { | ||
fetch: jest.fn(), | ||
}, | ||
}, | ||
adminDM: { | ||
send: jest.fn(), | ||
}, | ||
} | ||
}) | ||
jest.mock('@/server') | ||
jest.mock('@/scraper/updateAll') | ||
jest.mock('@/database/database', () => { | ||
return { | ||
getAllChannels: jest.fn(), | ||
} | ||
}) | ||
|
||
describe('catch discord error', () => { | ||
let channels: NotificationChannel[] | ||
let error: any | ||
let messages: string[] | ||
|
||
beforeAll(() => { | ||
;(updateAll as jest.Mock).mockImplementation(() => { | ||
return messages | ||
}) | ||
;(db.getAllChannels as jest.Mock).mockImplementation(() => { | ||
return channels | ||
}) | ||
;(client.channels.fetch as jest.Mock).mockImplementation(() => { | ||
throw error | ||
}) | ||
}) | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('discord error', async () => { | ||
channels = [ | ||
{ | ||
guildID: '123', | ||
channelID: '456', | ||
}, | ||
] | ||
|
||
error = new DiscordAPIError( | ||
{ | ||
code: 50001, | ||
errors: {}, | ||
message: '', | ||
}, | ||
50001, | ||
403, | ||
'GET', | ||
'', | ||
{} | ||
) | ||
|
||
messages = ['g'] | ||
|
||
await updateHandler() | ||
|
||
expect(adminDM.send).toHaveBeenCalledTimes(0) | ||
}) | ||
|
||
it('non-discord error', async () => { | ||
channels = [ | ||
{ | ||
guildID: '123', | ||
channelID: '456', | ||
}, | ||
] | ||
|
||
error = 'gg' | ||
|
||
messages = ['g'] | ||
|
||
await updateHandler() | ||
|
||
expect(adminDM.send).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |