-
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.
* ログインしているユーザーは部屋を作ったり、他人のルームに入ることができます。 * [DB modify] User と Room の中間テーブル(useronroom) を作成し、n to m の関係になりました。
- Loading branch information
Showing
6 changed files
with
230 additions
and
7 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
backend/prisma/migrations/20231113075959_unique_roomid_userid/migration.sql
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,8 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[userid,roomid]` on the table `useronroom` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- CreateIndex | ||
CREATE UNIQUE INDEX "useronroom_userid_roomid_key" ON "useronroom"("userid", "roomid"); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { IsString, IsNotEmpty, IsNumber } from 'class-validator'; | ||
|
||
export class UserOnRoomDto { | ||
@IsNumber() | ||
id: number; | ||
|
||
@IsNumber() | ||
userid: number; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
role: string; | ||
|
||
@IsNumber() | ||
roomid: number; | ||
} |
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,6 +1,7 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { RoomService } from './room.service'; | ||
import { PrismaService } from 'src/prisma/prisma.service'; | ||
import { CreateRoomDto } from './dto/create-room.dto'; | ||
|
||
describe('RoomService', () => { | ||
let service: RoomService; | ||
|
@@ -13,7 +14,157 @@ describe('RoomService', () => { | |
service = module.get<RoomService>(RoomService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
// it('should be defined', () => { | ||
// expect(service).toBeDefined(); | ||
// }); | ||
|
||
describe('findAll()', () => { | ||
it('should return an array of rooms', async () => { | ||
const rooms = await service.findAll(); | ||
expect(rooms).toBeInstanceOf(Array); | ||
}); | ||
}); | ||
|
||
describe('enterRoom()', () => { | ||
const user = { id: 1, name: 'test' }; | ||
const createRoomDto: CreateRoomDto = { name: 'testRoom1', userId: user.id }; | ||
|
||
it('should create a room', async () => { | ||
const room = await service.create(createRoomDto); | ||
console.log(room); | ||
expect(room).toHaveProperty('id'); | ||
expect(room).toHaveProperty('name'); | ||
}); | ||
it('should create a room', async () => { | ||
const room = await service.create(createRoomDto); | ||
console.log(room); | ||
expect(room).toHaveProperty('name'); | ||
}); | ||
it('should not create a room', async () => { | ||
const NotExistUserId = 10000000; | ||
await expect( | ||
service.create({ name: 'testRoom1', userId: NotExistUserId }), | ||
).rejects.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('findOne()', () => { | ||
const user = { id: 1, name: 'test' }; | ||
let roomId: number; | ||
const createRoomDto: CreateRoomDto = { name: 'testRoom1', userId: user.id }; | ||
it('should throw error', async () => { | ||
await expect(service.findOne(10000000, user.id)).rejects.toThrow(); | ||
}); | ||
it('should return a room', async () => { | ||
const room = await service.create(createRoomDto); | ||
console.log(room); | ||
expect(room).toHaveProperty('id'); | ||
expect(room).toHaveProperty('name'); | ||
roomId = room.id; | ||
}); | ||
it('should return a room', async () => { | ||
const room = await service.findOne(roomId, user.id); | ||
console.log(room); | ||
expect(room).toHaveProperty('id'); | ||
expect(room).toHaveProperty('name'); | ||
expect(room).toHaveProperty('users'); | ||
}); | ||
}); | ||
|
||
describe('leaveRoom()', () => { | ||
const user = { id: 1, name: 'test' }; | ||
let roomId: number; | ||
const createRoomDto: CreateRoomDto = { name: 'testRoom1', userId: user.id }; | ||
it('should throw error', async () => { | ||
await expect(service.leaveRoom(10000000, user.id)).rejects.toThrow(); | ||
}); | ||
it('should return a room', async () => { | ||
const room = await service.create(createRoomDto); | ||
console.log(room); | ||
expect(room).toHaveProperty('id'); | ||
expect(room).toHaveProperty('name'); | ||
roomId = room.id; | ||
}); | ||
it('should return a room', () => { | ||
return service | ||
.leaveRoom(roomId, user.id) | ||
.then((room) => { | ||
console.log(room); | ||
expect(room.id).toBe(roomId); | ||
expect(room.userid).toBe(user.id); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
}); | ||
}); | ||
// describe('/room/:id (POST)', () => { | ||
// let roomId: number; | ||
// const user = {id: 1, name: 'test'}; | ||
// const createRoomDto: CreateRoomDto = {name: 'testRoom1', userId: user.id}; | ||
|
||
// const room = await service.create(createRoomDto); | ||
// it('should enter a room', async () => { | ||
// const room = await service.create(createRoomDto); | ||
// console.log(room); | ||
// expect(room).toHaveProperty('id'); | ||
// expect(room).toHaveProperty('name'); | ||
// roomId = room.id; | ||
// }) | ||
// it('should not create a room', async () => { | ||
// const NotExistUserId = 10000000; | ||
// await expect(service.create({name: 'testRoom1', userId: NotExistUserId})).rejects.toThrow(); | ||
// }) | ||
|
||
// }) | ||
|
||
// it('should return a room', async () => { | ||
// const room = await service.findOne(roomId, user.id); | ||
// console.log(room); | ||
// expect(room).toHaveProperty('id'); | ||
// expect(room).toHaveProperty('name'); | ||
// }) | ||
// it('should return an error', async () => { | ||
// const room = await service.findOne(roomId + 1, user.id); | ||
// console.log(room); | ||
|
||
// }) | ||
// it('should return an error', async () => { | ||
// const room = await service.findOne(roomId, user.id + 1); | ||
// console.log(room); | ||
// expect(room).toHaveProperty('error'); | ||
// }) | ||
// it('should remove a room', async () => { | ||
// const room = await service.leaveRoom(roomId, user.id); | ||
// console.log(room); | ||
// expect(room).toHaveProperty('id'); | ||
// expect(room).toHaveProperty('name'); | ||
// }) | ||
// it('should return an error', async () => { | ||
// const room = await service.leaveRoom(roomId, user.id); | ||
// console.log(room); | ||
// expect(room).toHaveProperty('error'); | ||
// }) | ||
// it('should return an error', async () => { | ||
// const room = await service.findOne(roomId, user.id); | ||
// console.log(room); | ||
// }) | ||
|
||
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjMsImlhdCI6MTY5OTg2Mjg3NiwiZXhwIjoxNjk5ODY0Njc2fQ.ks3iRk8bKv6PGLV8V04zuB18xJ1l9CcVCQH_xjaIFnE | ||
|
||
/* | ||
{ | ||
"email": "[email protected]", | ||
"password": "password-susami" | ||
} | ||
*/ | ||
|
||
/* | ||
{ | ||
"email": "[email protected]", | ||
"password": "password-kakiba" | ||
} | ||
*/ | ||
|
||
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTY5OTg2MjgwMiwiZXhwIjoxNjk5ODY0NjAyfQ.OaQlF9NZTfbKaQ9-Ac4cSqZQU6oJE2de1Z-a-fsvH4A | ||
}); |
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