-
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.
[backend] Add API GET /room/:id/bans (#188)
[backend] * Add test for GET /room/:id/bans * Add API GET /room/:id/bans --------- Co-authored-by: Shun Usami <[email protected]>
- Loading branch information
Showing
6 changed files
with
214 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PrismaModule } from 'src/prisma/prisma.module'; | ||
import { BanModule } from './ban/ban.module'; | ||
import { RoomController } from './room.controller'; | ||
import { RoomService } from './room.service'; | ||
|
||
@Module({ | ||
controllers: [RoomController], | ||
providers: [RoomService], | ||
imports: [PrismaModule, BanModule], | ||
imports: [PrismaModule], | ||
}) | ||
export class RoomModule {} |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ import supertest from 'supertest'; | |
import { constants } from './constants'; | ||
import { TestApp, UserEntityWithAccessToken } from './utils/app'; | ||
import { initializeApp } from './utils/initialize'; | ||
import { expectRoom } from './utils/matcher'; | ||
import { expectPublicUser, expectRoom } from './utils/matcher'; | ||
|
||
describe('RoomController (e2e)', () => { | ||
let app: TestApp; | ||
|
@@ -1678,6 +1678,185 @@ describe('RoomController (e2e)', () => { | |
}); | ||
}); | ||
|
||
describe('GET /room/:id/bans (Get banned users)', () => { | ||
describe('Owner', () => { | ||
let _publicRoom: RoomEntity; | ||
let bannedUser: UserEntityWithAccessToken; | ||
beforeAll(async () => { | ||
bannedUser = await app.createAndLoginUser({ | ||
name: 'BANNED USER', | ||
email: '[email protected]', | ||
password: '12345678', | ||
}); | ||
_publicRoom = await setupRoom(constants.room.publicRoom); | ||
// await app.banUser(_publicRoom.id, bannedUser.id, owner.accessToken); | ||
}); | ||
afterAll(async () => { | ||
await app.deleteRoom(_publicRoom.id, owner.accessToken).expect(204); | ||
await app.deleteUser(bannedUser.id, bannedUser.accessToken).expect(204); | ||
}); | ||
describe('No banned users in the room', () => { | ||
it('should get empty array (200 OK)', async () => { | ||
const res = await app | ||
.getBannedUsers(_publicRoom.id, owner.accessToken) | ||
.expect(200); | ||
expect(res.body).toBeInstanceOf(Array); | ||
expect(res.body).toHaveLength(0); | ||
}); | ||
}); | ||
it('Ban user', async () => { | ||
await app | ||
.banUser(_publicRoom.id, bannedUser.id, owner.accessToken) | ||
.expect(200); | ||
}); | ||
describe('Banned users in the room', () => { | ||
it('should get banned users (200 OK)', async () => { | ||
const res = await app | ||
.getBannedUsers(_publicRoom.id, owner.accessToken) | ||
.expect(200); | ||
expect(res.body).toBeInstanceOf(Array); | ||
res.body.forEach(expectPublicUser); | ||
const { | ||
/* eslint-disable */ | ||
email, | ||
twoFactorEnabled, | ||
accessToken, | ||
/* eslint-enable */ | ||
...bannedUserWithoutAccessToken | ||
} = bannedUser; | ||
|
||
expect(res.body).toContainEqual(bannedUserWithoutAccessToken); | ||
}); | ||
}); | ||
}); | ||
describe('Admin', () => { | ||
let _publicRoom: RoomEntity; | ||
let bannedUser: UserEntityWithAccessToken; | ||
beforeAll(async () => { | ||
bannedUser = await app.createAndLoginUser({ | ||
name: 'BANNED USER', | ||
email: '[email protected]', | ||
password: '12345678', | ||
}); | ||
_publicRoom = await setupRoom(constants.room.publicRoom); | ||
// await app.banUser(_publicRoom.id, bannedUser.id, owner.accessToken); | ||
}); | ||
afterAll(async () => { | ||
await app.deleteRoom(_publicRoom.id, owner.accessToken).expect(204); | ||
await app.deleteUser(bannedUser.id, bannedUser.accessToken).expect(204); | ||
}); | ||
describe('No banned users in the room', () => { | ||
it('should get empty array (200 OK)', async () => { | ||
const res = await app | ||
.getBannedUsers(_publicRoom.id, admin.accessToken) | ||
.expect(200); | ||
expect(res.body).toBeInstanceOf(Array); | ||
expect(res.body).toHaveLength(0); | ||
}); | ||
}); | ||
it('Ban user', async () => { | ||
await app | ||
.banUser(_publicRoom.id, bannedUser.id, owner.accessToken) | ||
.expect(200); | ||
}); | ||
describe('Banned users in the room', () => { | ||
it('should get banned users (200 OK)', async () => { | ||
const res = await app | ||
.getBannedUsers(_publicRoom.id, admin.accessToken) | ||
.expect(200); | ||
expect(res.body).toBeInstanceOf(Array); | ||
res.body.forEach(expectPublicUser); | ||
const { | ||
/* eslint-disable */ | ||
email, | ||
twoFactorEnabled, | ||
accessToken, | ||
/* eslint-enable */ | ||
...bannedUserWithoutAccessToken | ||
} = bannedUser; | ||
|
||
expect(res.body).toContainEqual(bannedUserWithoutAccessToken); | ||
}); | ||
}); | ||
}); | ||
describe('Member', () => { | ||
let _publicRoom: RoomEntity; | ||
let bannedUser: UserEntityWithAccessToken; | ||
beforeAll(async () => { | ||
bannedUser = await app.createAndLoginUser({ | ||
name: 'BANNED USER', | ||
email: '[email protected]', | ||
password: '12345678', | ||
}); | ||
_publicRoom = await setupRoom(constants.room.publicRoom); | ||
// await app.banUser(_publicRoom.id, bannedUser.id, owner.accessToken); | ||
}); | ||
afterAll(async () => { | ||
await app.deleteRoom(_publicRoom.id, owner.accessToken).expect(204); | ||
await app.deleteUser(bannedUser.id, bannedUser.accessToken).expect(204); | ||
}); | ||
describe('No banned users in the room', () => { | ||
it('should get empty array (200 OK)', async () => { | ||
const res = await app | ||
.getBannedUsers(_publicRoom.id, admin.accessToken) | ||
.expect(200); | ||
expect(res.body).toBeInstanceOf(Array); | ||
expect(res.body).toHaveLength(0); | ||
}); | ||
}); | ||
it('Ban user', async () => { | ||
await app | ||
.banUser(_publicRoom.id, bannedUser.id, owner.accessToken) | ||
.expect(200); | ||
}); | ||
describe('Banned users in the room', () => { | ||
it('should not get banned users (403 Forbidden)', async () => { | ||
await app | ||
.getBannedUsers(publicRoom.id, member.accessToken) | ||
.expect(403); | ||
}); | ||
}); | ||
}); | ||
describe('notMember', () => { | ||
let _publicRoom: RoomEntity; | ||
let bannedUser: UserEntityWithAccessToken; | ||
beforeAll(async () => { | ||
bannedUser = await app.createAndLoginUser({ | ||
name: 'BANNED USER', | ||
email: '[email protected]', | ||
password: '12345678', | ||
}); | ||
_publicRoom = await setupRoom(constants.room.publicRoom); | ||
// await app.banUser(_publicRoom.id, bannedUser.id, owner.accessToken); | ||
}); | ||
afterAll(async () => { | ||
await app.deleteRoom(_publicRoom.id, owner.accessToken).expect(204); | ||
await app.deleteUser(bannedUser.id, bannedUser.accessToken).expect(204); | ||
}); | ||
describe('No banned users in the room', () => { | ||
it('should get empty array (200 OK)', async () => { | ||
const res = await app | ||
.getBannedUsers(_publicRoom.id, admin.accessToken) | ||
.expect(200); | ||
expect(res.body).toBeInstanceOf(Array); | ||
expect(res.body).toHaveLength(0); | ||
}); | ||
}); | ||
it('Ban user', async () => { | ||
await app | ||
.banUser(_publicRoom.id, bannedUser.id, owner.accessToken) | ||
.expect(200); | ||
}); | ||
describe('Banned users in the room', () => { | ||
it('should not get banned users (403 Forbidden)', async () => { | ||
await app | ||
.getBannedUsers(publicRoom.id, notMember.accessToken) | ||
.expect(403); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('DELETE /room/:id/bans/:userId (Unban user)', () => { | ||
describe('Owner', () => { | ||
let _publicRoom: RoomEntity; | ||
|
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