Skip to content

Commit

Permalink
カバレッジ向上
Browse files Browse the repository at this point in the history
  • Loading branch information
na2na-p committed Nov 22, 2023
1 parent 239fe41 commit 34e8d08
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/features/core/internal/Voice/internal/Voice.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,48 @@ describe('Voice', () => {
);
});

it('should throw an error if the channel is null', async () => {
const mockedInteraction = {
reply: vi.fn(),
} as unknown as Readonly<ChatInputCommandInteraction>;

(getActorId as MockedFunction<typeof getActorId>).mockResolvedValueOnce({
voice: { channel: null },
} as GuildMember);
(
getJoinableStateStatus as MockedFunction<typeof getJoinableStateStatus>
).mockReturnValueOnce(JOINABLE_STATE_STATUS.ALREADY_JOINED);

await expect(
voice.join({ interaction: mockedInteraction })
).rejects.toThrowError(
'Channel is null. Please check getJoinableStateStatus()'
);
});

// JOINABLE_STATE_STATUS.ALREADY_JOINED
it('should return false if the channel is already joined', async () => {
const mockedInteraction = {
reply: vi.fn(),
} as unknown as Readonly<ChatInputCommandInteraction>;

(getActorId as MockedFunction<typeof getActorId>).mockResolvedValueOnce({
voice: {
channel: {
id: 'channelId',
guild: {
id: 'guildId',
},
},
},
} as GuildMember);
(
getJoinableStateStatus as MockedFunction<typeof getJoinableStateStatus>
).mockReturnValueOnce(JOINABLE_STATE_STATUS.ALREADY_JOINED);

const result = await voice.join({ interaction: mockedInteraction });
});

it('should join the voice channel and return true', async () => {
const mockedGuildMember = {
voice: {
Expand Down
2 changes: 1 addition & 1 deletion src/features/core/internal/Voice/internal/Voice.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Voice {
adapterCreator: channel.guild.voiceAdapterCreator,
});
this.connection.push({
guildId: actor.guild.id,
guildId: channel.guildId,
connection: connectedChannel,
player: undefined,
});
Expand Down

0 comments on commit 34e8d08

Please sign in to comment.