-
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.
* feat(#87): Made a start on the cron activity purges * feat(#87): Added .gitattributes file so LF is always committed * feat(#87): Added most of what is required to implement activity based purging. WSL is giving me dodgy test runs so screw that! * feat(#87): Fixed line endings * feat(#87): WIP: I give up with WSL, no more. * fix: Fix test wonkyness * feat: #67: Added meat to the bones for inactivity purges and maintenance of old activity records * feat: #67: Activity scanning service fully tested * feat: #67: Linting * feat: #67: Fixed typing issue * feat: #67: Purge service getPurgableMembers tested. Added inactive stats. * feat: #67: Removed origin message from removeActivityRecord * feat: #67: Comment * feat: #67: Simplified IF statement * feat: #67: Added dry run to thanos snap command * feat: #67: Completed implementation and tests of the purge service. * feat: #67: Added missing test to see if activity service was actually called * feat: #67: Added missing test to see if activity service was actually called * feat: #67: Migrated the start of the purges into the purge service, so cron and channel can be kept simple. Updated and added tests for purge cron service. * feat: #67: Added sortMember basic tests, its a sort function * feat: #67: Added guild member event tests * feat: #67: Added thanos snap command tests * feat: #67: Removed dead code * feat: #67: Added purge cron service but commented out * feat: #67: Migrated purge candidates report into the purging process itself. Added test to reflect this. * feat: #67: Removed purge candidates command, this can be handled with a purge dry run now the report is in there. * feat: #67: All tests now work * feat: #67: Added DM sent to members to inform them they've been removed. * feat: #67: Added additional checks to ensure DMs are not sent on dry run * feat: #67: Added additional tests for Discord Service
- Loading branch information
1 parent
5fd599d
commit 8c13c1e
Showing
20 changed files
with
1,908 additions
and
524 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 |
---|---|---|
|
@@ -40,3 +40,4 @@ jobs: | |
with: | ||
tag: ${{ steps.version.outputs.newTag }} | ||
generateReleaseNotes: true | ||
makeLatest: true |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { ThanosSnapCommand } from './thanos.snap.command'; | ||
import { PurgeService } from '../services/purge.service'; | ||
import { ChatInputCommandInteraction } from 'discord.js'; | ||
import { DryRunDto } from '../dto/dry.run.dto'; | ||
import { TestBootstrapper } from '../../test.bootstrapper'; | ||
import { ReflectMetadataProvider } from '@discord-nestjs/core'; | ||
|
||
describe('ThanosSnapCommand', () => { | ||
let command: ThanosSnapCommand; | ||
let purgeService: PurgeService; | ||
|
||
const mockPurgeService = { | ||
startPurge: jest.fn(), | ||
}; | ||
|
||
const mockDiscordUser = TestBootstrapper.getMockDiscordUser(); | ||
|
||
const mockInteraction = TestBootstrapper.getMockDiscordInteraction('12345', mockDiscordUser) as unknown as ChatInputCommandInteraction[]; | ||
|
||
beforeEach(async () => { | ||
const moduleRef = await Test.createTestingModule({ | ||
providers: [ | ||
ThanosSnapCommand, | ||
ReflectMetadataProvider, | ||
{ | ||
provide: PurgeService, | ||
useValue: mockPurgeService, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
command = moduleRef.get<ThanosSnapCommand>(ThanosSnapCommand); | ||
purgeService = moduleRef.get<PurgeService>(PurgeService); | ||
|
||
jest.spyOn(command['logger'], 'error'); | ||
jest.spyOn(command['logger'], 'warn'); | ||
jest.spyOn(command['logger'], 'log'); | ||
jest.spyOn(command['logger'], 'debug'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(command).toBeDefined(); | ||
}); | ||
|
||
describe('onThanosSnapCommand', () => { | ||
it('should log the execution of the command', async () => { | ||
const dto: DryRunDto = { dryRun: false }; | ||
|
||
await command.onThanosSnapCommand(dto, mockInteraction); | ||
|
||
expect(command['logger'].log).toHaveBeenCalledWith('Executing Thanos Snap Command'); | ||
expect(mockInteraction[0].reply).toHaveBeenCalledWith('I am... inevitable.'); | ||
expect(purgeService.startPurge).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should send a dry run message if dryRun is true', async () => { | ||
const dto: DryRunDto = { dryRun: true }; | ||
|
||
await command.onThanosSnapCommand(dto, mockInteraction); | ||
|
||
expect(mockInteraction[0].reply).toHaveBeenCalledWith('I am... inevitable.'); | ||
expect(mockInteraction[0].channel.send).toHaveBeenCalledWith('## This is a dry run! No members will be kicked!'); | ||
expect(purgeService.startPurge).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should send a gif and start the purge', async () => { | ||
const dto: DryRunDto = { dryRun: false }; | ||
|
||
await command.onThanosSnapCommand(dto, mockInteraction); | ||
|
||
expect(mockInteraction[0].channel.send).toHaveBeenCalledWith('https://media.giphy.com/media/ie76dJeem4xBDcf83e/giphy.gif'); | ||
expect(purgeService.startPurge).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.