-
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.
Merge pull request #61 from DevKor-github/staging
Staging
- Loading branch information
Showing
16 changed files
with
464 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"license": "UNLICENSED", | ||
"scripts": { | ||
"ssh:staging": "ssh -i ../../keys/blccu-dev-rsa.pem [email protected];", | ||
"ssh:prod": "ssh -i ../../keys/blccu-dev-rsa.pem [email protected]", | ||
"ssh:prod1": "ssh -i ../../keys/blccu-prod.pem [email protected]", | ||
"ssh:prod2": "ssh -i ../../keys/blccu-prod.pem [email protected]", | ||
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js", | ||
|
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
155 changes: 155 additions & 0 deletions
155
src/APIs/announcements/__test__/announcements.controller.spec.ts
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,155 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AnnouncementsController } from '../announcements.controller'; | ||
import { AnnouncementsService } from '../announcements.service'; | ||
import { | ||
MockService, | ||
MockServiceFactory, | ||
TEST_DATE_FIELDS, | ||
} from '@/utils/test.utils'; | ||
import { Request } from 'express'; | ||
import { AnnouncementCreateRequestDto } from '../dtos/request/announcement-create-request.dto'; | ||
import { AnnouncementDto } from '../dtos/common/announcement.dto'; | ||
import { AnnouncementPatchRequestDto } from '../dtos/request/announcement-patch-request.dto'; | ||
import { | ||
BlccuExceptionTest, | ||
BlccuHttpException, | ||
} from '@/common/blccu-exception'; | ||
|
||
describe('announcementsController', () => { | ||
let req: Request; | ||
let ctrl_announcements: AnnouncementsController; | ||
let svc_annoucements: MockService<AnnouncementsService>; | ||
let dto_announcement: AnnouncementDto; | ||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [AnnouncementsController], | ||
providers: [ | ||
{ | ||
provide: AnnouncementsService, | ||
useValue: MockServiceFactory.getMockService(AnnouncementsService), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
dto_announcement = { | ||
id: 1, | ||
title: '제목없음', | ||
content: '공지내용', | ||
...TEST_DATE_FIELDS, | ||
}; | ||
ctrl_announcements = module.get<AnnouncementsController>( | ||
AnnouncementsController, | ||
); | ||
svc_annoucements = | ||
module.get<MockService<AnnouncementsService>>(AnnouncementsService); | ||
req = { user: { userId: 1 } } as Request; | ||
}); | ||
|
||
describe('createAnnouncement', () => { | ||
it('should return AnnouncementDto for valid input', async () => { | ||
// Arrange | ||
const dto_createAnnouncement: AnnouncementCreateRequestDto = { | ||
title: '제목없음', | ||
content: '공지내용', | ||
}; | ||
svc_annoucements.createAnnoucement.mockResolvedValue(dto_announcement); | ||
// Act | ||
const result = await ctrl_announcements.createAnnouncement( | ||
req, | ||
dto_createAnnouncement, | ||
); | ||
// Assert | ||
expect(result).toEqual(dto_announcement); | ||
expect(svc_annoucements.createAnnoucement).toHaveBeenCalledWith({ | ||
...dto_createAnnouncement, | ||
userId: req.user.userId, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getAnnouncements', () => { | ||
it('should return AnnoucementDto[] for any condition', async () => { | ||
// Arrange | ||
svc_annoucements.getAnnouncements.mockResolvedValue([dto_announcement]); | ||
// Act | ||
const result = await ctrl_announcements.getAnnouncements(); | ||
// Assert | ||
expect(result).toEqual([dto_announcement]); | ||
expect(svc_annoucements.getAnnouncements).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('patchAnnouncement', () => { | ||
it('should return AnnouncementDto for valid input', async () => { | ||
// Arrange | ||
const announcementId = 1; | ||
const dto_patchAnnouncement: AnnouncementPatchRequestDto = { | ||
title: '수정된 제목', | ||
content: '수정된 내용', | ||
}; | ||
svc_annoucements.patchAnnouncement.mockResolvedValue({ | ||
dto_announcement, | ||
...dto_patchAnnouncement, | ||
}); | ||
|
||
// Act | ||
const result = await ctrl_announcements.patchAnnouncement( | ||
req, | ||
dto_patchAnnouncement, | ||
announcementId, | ||
); | ||
// Assert | ||
expect(result).toEqual({ dto_announcement, ...dto_patchAnnouncement }); | ||
expect(svc_annoucements.patchAnnouncement).toHaveBeenCalledWith({ | ||
...dto_patchAnnouncement, | ||
announcementId, | ||
userId: req.user.userId, | ||
}); | ||
}); | ||
|
||
it('should throw exception for non-admin user', async () => { | ||
// Arrange | ||
const announcementId = 1; | ||
const dto_patchAnnouncement: AnnouncementPatchRequestDto = { | ||
title: '수정된 제목', | ||
content: '수정된 내용', | ||
}; | ||
svc_annoucements.patchAnnouncement.mockRejectedValue( | ||
new BlccuHttpException('NOT_AN_ADMIN'), | ||
); | ||
// Act | ||
const act = () => | ||
ctrl_announcements.patchAnnouncement( | ||
req, | ||
dto_patchAnnouncement, | ||
announcementId, | ||
); | ||
// Assert | ||
expect(act()).rejects.toThrow(BlccuExceptionTest('NOT_AN_ADMIN')); | ||
expect(svc_annoucements.patchAnnouncement).toHaveBeenCalledWith({ | ||
...dto_patchAnnouncement, | ||
announcementId, | ||
userId: req.user.userId, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('removeAnnouncement', () => { | ||
it('should return AnnouncementDto for valid input', async () => { | ||
// Arrange | ||
const announcementId = 1; | ||
svc_annoucements.removeAnnouncement.mockResolvedValue(dto_announcement); | ||
// Act | ||
const result = await ctrl_announcements.removeAnnouncement( | ||
req, | ||
announcementId, | ||
); | ||
// Assert | ||
expect(result).toEqual(dto_announcement); | ||
expect(svc_annoucements.removeAnnouncement).toHaveBeenCalledWith({ | ||
userId: req.user.userId, | ||
announcementId, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.