Skip to content

Commit

Permalink
fix: fixes bug, with already loggin users, then left, an exception wa…
Browse files Browse the repository at this point in the history
…s thrown
  • Loading branch information
oliverlorenz committed Oct 3, 2020
1 parent 1358435 commit 5d6f3ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ describe("StartStopServerByDiscordVoiceChannel", () => {
handler.start();
});

it("check startToStopTransitionHandler does not throw error", async (done) => {
const emitter = new EventEmitter();
observer.onThresholdReached?.mockImplementationOnce(() => {});
observer.onThresholdLeft?.mockImplementationOnce(
(threshold: number, callback: () => void) => {
emitter.on("triggerLeft", callback);
}
);
handler.onceStopFinished(() => {
done();
});
await handler.start();
emitter.emit("triggerLeft");
});

it("should send if running", () => {
vmHandler.onStarted?.mockImplementationOnce(
(callback: (ip: string) => void) => {
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ export class DiscordVoiceChannelServerHandler {

this.stopToStartTransitionHandler.onTransitionFinished(async () => {
await this.messageHandler.sendStopMessage();
this.startToStopTransitionHandler.reset();
if (this.startToStopTransitionHandler.is(State.STATUS_B)) {
this.startToStopTransitionHandler.reset();
}
this.emitter.emit(Event.STOP_FINISHED);
});

Expand Down

0 comments on commit 5d6f3ec

Please sign in to comment.