-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: space-delete-api * fix: 에러 메시지 추가 * fix: json pasing 안되는 이슈 해결 * refactor: validation Service validation으로 네이밍 변경 * feat: space update 로직 추가 * fix: updateSpaceByName * fix: 노드 위 우클릭시 이동모드 자동 활성화되는 오류 수정 (#195) fix: 노드 위 우클릭 시 이동모드 활성화되는 것 방지 * fix: 이동모드 활성화 함수에서 button 판별오류 수정 (#196) * fix: mouse-event에 대해서만 button 판별하도록 수정 * feat: 인터랙션 가이드 UI 추가 (#197) * feat: 인터랙션 가이드 추가 * chore: 인터랙션 가이드 내용 추가 * feat: 모바일 환경에서 더보기 버튼을 통한 노드.간선 편집 (#199) * feat: 터치디바이스 여부 확인 로직 * feat: 모바일환경에서 더보기 버튼 클릭 시 context-menu 표시 * feat: 더보기 버튼 클릭 시 clientX, clientY값 정의하여 전달 * feat: 간선 삭제 버튼 스타일 수정 * feat: 삭제 버튼 터치 핸들러 연결 * feat: 서브스페이스 삭제 api 연동 * feat: 작업 내용 저장 * feat: save * fix: space delete id가 아니라 src에 있는 걸 갖고 올 수 있도록 수정 * feat: deleteNote Controller API 추가 * feat: 서브스페이스 수정 api 연동 --------- Co-authored-by: CatyJazzy <[email protected]> Co-authored-by: Heejin Na <[email protected]> Co-authored-by: CatyJazzy <[email protected]>
- Loading branch information
1 parent
17dd8aa
commit 022635a
Showing
20 changed files
with
625 additions
and
19 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
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,123 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { SpaceController } from './space.controller'; | ||
import { SpaceService } from './space.service'; | ||
import { CreateSpaceDto } from './dto/create.space.dto'; | ||
import { HttpException } from '@nestjs/common'; | ||
import { GUEST_USER_ID } from '../common/constants/space.constants'; | ||
|
||
describe('SpaceController', () => { | ||
let spaceController: SpaceController; | ||
let spaceService: Partial<SpaceService>; | ||
|
||
beforeEach(async () => { | ||
spaceService = { | ||
existsById: jest.fn(), | ||
getBreadcrumb: jest.fn(), | ||
create: jest.fn(), | ||
}; | ||
|
||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [SpaceController], | ||
providers: [ | ||
{ | ||
provide: SpaceService, | ||
useValue: spaceService, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
spaceController = module.get<SpaceController>(SpaceController); | ||
}); | ||
|
||
describe('existsBySpace', () => { | ||
it('스페이스가 존재할 경우 true를 반환해야 한다', async () => { | ||
const spaceId = '123'; | ||
(spaceService.existsById as jest.Mock).mockResolvedValue(true); | ||
|
||
const result = await spaceController.existsBySpace(spaceId); | ||
|
||
expect(spaceService.existsById).toHaveBeenCalledWith(spaceId); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('예외가 발생하면 오류를 던져야 한다', async () => { | ||
const spaceId = '123'; | ||
(spaceService.existsById as jest.Mock).mockRejectedValue( | ||
new Error('Unexpected Error'), | ||
); | ||
|
||
await expect(spaceController.existsBySpace(spaceId)).rejects.toThrow( | ||
'Unexpected Error', | ||
); | ||
}); | ||
}); | ||
|
||
describe('getBreadcrumb', () => { | ||
it('주어진 스페이스 ID에 대한 경로를 반환해야 한다', async () => { | ||
const spaceId = '123'; | ||
const breadcrumb = ['Home', 'Space']; | ||
(spaceService.getBreadcrumb as jest.Mock).mockResolvedValue(breadcrumb); | ||
|
||
const result = await spaceController.getBreadcrumb(spaceId); | ||
|
||
expect(spaceService.getBreadcrumb).toHaveBeenCalledWith(spaceId); | ||
expect(result).toEqual(breadcrumb); | ||
}); | ||
}); | ||
|
||
describe('createSpace', () => { | ||
it('스페이스를 생성하고 URL 경로를 반환해야 한다', async () => { | ||
const createSpaceDto: CreateSpaceDto = { | ||
userId: GUEST_USER_ID, | ||
spaceName: 'New Space', | ||
parentContextNodeId: '123', | ||
}; | ||
|
||
const mockSpace = { toObject: () => ({ id: 'space123' }) }; | ||
(spaceService.create as jest.Mock).mockResolvedValue(mockSpace); | ||
|
||
const result = await spaceController.createSpace(createSpaceDto); | ||
|
||
expect(spaceService.create).toHaveBeenCalledWith( | ||
GUEST_USER_ID, | ||
'New Space', | ||
'123', | ||
); | ||
expect(result).toEqual({ urlPath: 'space123' }); | ||
}); | ||
|
||
it('잘못된 요청인 경우 400 오류를 던져야 한다', async () => { | ||
const createSpaceDto: CreateSpaceDto = { | ||
userId: 'invalidUser', | ||
spaceName: '', | ||
parentContextNodeId: '123', | ||
}; | ||
|
||
await expect(spaceController.createSpace(createSpaceDto)).rejects.toThrow( | ||
HttpException, | ||
); | ||
|
||
expect(spaceService.create).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('스페이스 생성에 실패한 경우 404 오류를 던져야 한다', async () => { | ||
const createSpaceDto: CreateSpaceDto = { | ||
userId: GUEST_USER_ID, | ||
spaceName: 'New Space', | ||
parentContextNodeId: '123', | ||
}; | ||
|
||
(spaceService.create as jest.Mock).mockResolvedValue(null); | ||
|
||
await expect(spaceController.createSpace(createSpaceDto)).rejects.toThrow( | ||
HttpException, | ||
); | ||
|
||
expect(spaceService.create).toHaveBeenCalledWith( | ||
GUEST_USER_ID, | ||
'New Space', | ||
'123', | ||
); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { SpaceService } from './space.service'; | ||
import { getModelToken } from '@nestjs/mongoose'; | ||
import { SpaceDocument } from './space.schema'; | ||
import { SpaceValidation } from './space.validation.service'; | ||
import { Model } from 'mongoose'; | ||
|
||
jest.mock('uuid', () => ({ | ||
v4: jest.fn(() => 'mock-uuid'), | ||
})); | ||
|
||
describe('SpaceService', () => { | ||
let spaceService: SpaceService; | ||
let spaceModel: Model<SpaceDocument>; | ||
let spaceValidation: SpaceValidation; | ||
|
||
beforeEach(async () => { | ||
const mockSpaceModel = { | ||
findOne: jest.fn().mockReturnValue({ | ||
exec: jest.fn(), | ||
}), | ||
findOneAndUpdate: jest.fn().mockReturnValue({ | ||
exec: jest.fn(), | ||
}), | ||
countDocuments: jest.fn(), | ||
create: jest.fn(), | ||
}; | ||
|
||
const mockSpaceValidation = { | ||
validateSpaceLimit: jest.fn().mockResolvedValue(undefined), | ||
validateParentNodeExists: jest.fn().mockResolvedValue(undefined), | ||
}; | ||
|
||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
SpaceService, | ||
{ | ||
provide: getModelToken(SpaceDocument.name), | ||
useValue: mockSpaceModel, | ||
}, | ||
{ | ||
provide: SpaceValidation, | ||
useValue: mockSpaceValidation, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
spaceService = module.get<SpaceService>(SpaceService); | ||
spaceModel = module.get<Model<SpaceDocument>>( | ||
getModelToken(SpaceDocument.name), | ||
); | ||
spaceValidation = module.get<SpaceValidation>(SpaceValidation); | ||
}); | ||
|
||
describe('getBreadcrumb', () => { | ||
it('스페이스의 경로를 반환해야 한다', async () => { | ||
const mockSpaces = [ | ||
{ id: 'parent-id', name: 'Parent Space', parentSpaceId: null }, | ||
{ id: '123', name: 'Child Space', parentSpaceId: 'parent-id' }, | ||
]; | ||
|
||
(spaceModel.findOne as jest.Mock) | ||
.mockReturnValueOnce({ | ||
exec: jest.fn().mockResolvedValue(mockSpaces[1]), | ||
}) | ||
.mockReturnValueOnce({ | ||
exec: jest.fn().mockResolvedValue(mockSpaces[0]), | ||
}); | ||
|
||
const result = await spaceService.getBreadcrumb('123'); | ||
|
||
expect(spaceModel.findOne).toHaveBeenCalledWith({ id: '123' }); | ||
expect(spaceModel.findOne).toHaveBeenCalledWith({ id: 'parent-id' }); | ||
expect(result).toEqual([ | ||
{ name: 'Parent Space', url: 'parent-id' }, | ||
{ name: 'Child Space', url: '123' }, | ||
]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.