-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[backend] mute user in room #216
Conversation
Warning Rate Limit Exceeded@lim396 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 13 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThe recent update introduces a Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
backend/test/room.e2e-spec.ts
Outdated
it('should get empty array after the duration (200 OK)', (done) => { | ||
setTimeout(async () => { | ||
const res = await app | ||
.getMutedUsers(_publicRoom.id, owner.accessToken) | ||
.expect(200); | ||
expect(res.body).toBeInstanceOf(Array); | ||
expect(res.body).toHaveLength(0); | ||
done(); | ||
// const res2 = await app | ||
// .getMutedUsers(_publicRoom.id, admin.accessToken) | ||
// .expect(200); | ||
// expect(res2.body).toBeInstanceOf(Array); | ||
// expect(res2.body).toHaveLength(0); | ||
}, 2000); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test case for checking the empty array of muted users after the mute duration has passed is implemented correctly. However, the use of setTimeout
in tests is not recommended due to potential flakiness. Consider using fake timers or other time-mocking libraries for more reliable and faster tests.
- it('should get empty array after the duration (200 OK)', (done) => {
+ it('should get empty array after the duration (200 OK)', async () => {
+ jest.useFakeTimers();
+ // ... setup the mute ...
+ jest.advanceTimersByTime(2000);
+ const res = await app
+ .getMutedUsers(_publicRoom.id, owner.accessToken)
+ .expect(200);
+ expect(res.body).toBeInstanceOf(Array);
+ expect(res.body).toHaveLength(0);
+ jest.useRealTimers();
+ });
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
it('should get empty array after the duration (200 OK)', (done) => { | |
setTimeout(async () => { | |
const res = await app | |
.getMutedUsers(_publicRoom.id, owner.accessToken) | |
.expect(200); | |
expect(res.body).toBeInstanceOf(Array); | |
expect(res.body).toHaveLength(0); | |
done(); | |
// const res2 = await app | |
// .getMutedUsers(_publicRoom.id, admin.accessToken) | |
// .expect(200); | |
// expect(res2.body).toBeInstanceOf(Array); | |
// expect(res2.body).toHaveLength(0); | |
}, 2000); | |
}); | |
it('should get empty array after the duration (200 OK)', async () => { | |
jest.useFakeTimers(); | |
// ... setup the mute ... | |
jest.advanceTimersByTime(2000); | |
const res = await app | |
.getMutedUsers(_publicRoom.id, owner.accessToken) | |
.expect(200); | |
expect(res.body).toBeInstanceOf(Array); | |
expect(res.body).toHaveLength(0); | |
jest.useRealTimers(); | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mockタイマーは色々試行錯誤しましたが、まだ上手く使えなかったので後ほど試してみます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lim396: Understood! If you encounter any issues or have questions when you revisit the mock timers, feel free to reach out. Good luck!
…ute period without unmuting
482c05c
to
b528900
Compare
} else { | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こういう名前の関数で、これが書かれない気がする
} | ||
if (await this.isExpired(roomId, userId)) { | ||
await this.remove(roomId, userId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここまでまとめてremoveIfAlreadyExistsAndExpired
みたいな(もっといい名前考えてほしいですが)ふうに切り分けた方が自然かな
if (await this.isExpired(roomId, userId)) {
await this.remove(roomId, userId);
}
durationの指定がない場合は無期限のmuteになる仕様です。
タイマー関数をmockに置き換えなどはまだ出来ていません。
テストの追加や修正により大きなPRになってしまっています🙏
追加したテスト
room.e2e-spec
chat-gateway.e2e-spec
修正したテスト
chat-gateway.e2e-specを少し修正