-
Notifications
You must be signed in to change notification settings - Fork 3
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 #305 from na2na-p/topic/test
テスト追加
- Loading branch information
Showing
11 changed files
with
218 additions
and
59 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,3 +1,4 @@ | ||
node_modules | ||
coverage | ||
dist/ | ||
.env |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
src/features/commands/internal/CommandBase/internal/CommandBase.class.spec.ts
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,45 @@ | ||
import type { | ||
CacheType, | ||
ChatInputCommandInteraction, | ||
} from '@/features/library/index.js'; | ||
|
||
import { CommandBase } from './CommandBase.class.js'; | ||
|
||
describe('CommandBase', () => { | ||
class TestCommand extends CommandBase { | ||
public readonly name = 'test'; | ||
public readonly description = 'test command'; | ||
|
||
public async interact(): Promise<void> { | ||
// do nothing | ||
} | ||
} | ||
|
||
let command: TestCommand; | ||
|
||
beforeEach(() => { | ||
command = new TestCommand(); | ||
}); | ||
|
||
describe('register', () => { | ||
it('should return the command instance', () => { | ||
expect(command.register()).toBe(command); | ||
}); | ||
}); | ||
|
||
describe('isInteract', () => { | ||
it('should return true if the interaction command name matches the command name', () => { | ||
const interaction = { commandName: 'test' } as Readonly< | ||
ChatInputCommandInteraction<CacheType> | ||
>; | ||
expect(command.isInteract({ interaction })).toBe(true); | ||
}); | ||
|
||
it('should return false if the interaction command name does not match the command name', () => { | ||
const interaction = { commandName: 'other' } as Readonly< | ||
ChatInputCommandInteraction<CacheType> | ||
>; | ||
expect(command.isInteract({ interaction })).toBe(false); | ||
}); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
src/features/commands/internal/Ping/internal/Ping.class.spec.ts
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,32 @@ | ||
import type { | ||
CacheType, | ||
ChatInputCommandInteraction, | ||
} from '@/features/library/index.js'; | ||
|
||
import { Ping } from './Ping.class.js'; | ||
|
||
describe('Ping', () => { | ||
let ping: Ping; | ||
|
||
beforeEach(() => { | ||
ping = new Ping(); | ||
}); | ||
|
||
describe('interact', () => { | ||
it('should reply with the RTT in milliseconds', async () => { | ||
const interaction = { | ||
createdAt: new Date('2022-01-01T00:00:00.000Z'), | ||
reply: jest.fn(), | ||
} as unknown as Readonly<ChatInputCommandInteraction<CacheType>>; | ||
const expectedRTT = 100; | ||
|
||
jest | ||
.spyOn(Date, 'now') | ||
.mockReturnValueOnce(new Date('2022-01-01T00:00:00.100Z').getTime()); | ||
|
||
await ping.interact({ interaction }); | ||
|
||
expect(interaction.reply).toHaveBeenCalledWith(`RTT: ${expectedRTT}ms`); | ||
}); | ||
}); | ||
}); |
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
1 change: 1 addition & 0 deletions
1
src/features/commands/internal/Ping/internal/funcs/getRTT/index.ts
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 @@ | ||
export { getRTT } from './internal/getRTT.js'; |
13 changes: 13 additions & 0 deletions
13
src/features/commands/internal/Ping/internal/funcs/getRTT/internal/getRTT.spec.ts
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,13 @@ | ||
import { getRTT } from './getRTT.js'; | ||
|
||
describe('getRTT', () => { | ||
it('should return the correct RTT', () => { | ||
const localTime = 1000; | ||
const serverTime = 500; | ||
const expectedRTT = localTime - serverTime; | ||
|
||
const result = getRTT({ localTime, serverTime }); | ||
|
||
expect(result).toBe(expectedRTT); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
src/features/commands/internal/Ping/internal/funcs/getRTT/internal/getRTT.ts
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,10 @@ | ||
// ローカルタイム-サーバタイムの引き算をする | ||
export const getRTT = ({ | ||
localTime, | ||
serverTime, | ||
}: { | ||
localTime: number; | ||
serverTime: number; | ||
}): number => { | ||
return localTime - serverTime; | ||
}; |
Oops, something went wrong.