Skip to content

Commit

Permalink
Merge pull request #297 from 42-world/develop
Browse files Browse the repository at this point in the history
🔥 Main Merge 🏃‍♀️🏃‍♂️🏃
  • Loading branch information
Skyrich2000 authored Aug 6, 2022
2 parents 5e1b0f1 + a324af3 commit b57a550
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ test: test-api

.PHONY: test-api
test-api: test-ready
yarn test
yarn test:e2e ./apps/api/test/e2e/*.e2e-spec.ts

# Alpha & Production =================================================
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/notification/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class NotificationService {
}

async findByUserId(userId: number): Promise<Notification[]> {
return this.notificationRepository.find({ where: { userId } });
return this.notificationRepository.find({ where: { userId }, order: { createdAt: 'DESC' } });
}

async updateIsReadByUserId(userId: number): Promise<void> {
Expand Down
21 changes: 11 additions & 10 deletions apps/api/test/e2e/notification.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,18 @@ describe('Notification', () => {
describe('/notifications', () => {
let dummyUser: User;
let dummyArticle: Article;
let dummyNotification: Notification;
let dummyNotification: Notification[];

beforeEach(async () => {
users = await dummy.createDummyUsers(userRepository);
dummyUser = users.cadet[0];
categories = await dummy.createDummyCategories(categoryRepository);
articles = await dummy.createDummyArticles(articleRepository, users, categories);
dummyArticle = articles.first;
dummyNotification = dummy.notification(
NotificationType.NEW_COMMENT,
dummyUser.id,
dummyArticle.id,
'notification content',
);
dummyNotification = [
dummy.notification(NotificationType.NEW_COMMENT, dummyUser.id, dummyArticle.id, 'notification content'),
dummy.notification(NotificationType.NEW_COMMENT, dummyUser.id, dummyArticle.id, 'notification content 2'),
];
await notificationRepository.save(dummyNotification);
JWT = dummy.jwt(dummyUser, authService);
});
Expand All @@ -88,9 +86,12 @@ describe('Notification', () => {
.get('/notifications')
.set('Cookie', `${process.env.ACCESS_TOKEN_KEY}=${JWT}`);
expect(res.status).toEqual(HttpStatus.OK);
expect(res.body[0].articleId).toEqual(dummyArticle.id);
expect(res.body[0].type).toEqual(dummyNotification.type);
expect(res.body[0].content).toEqual(dummyNotification.content);
expect(res.body[0].articleId).toEqual(dummyNotification[1].articleId);
expect(res.body[0].type).toEqual(dummyNotification[1].type);
expect(res.body[0].content).toEqual(dummyNotification[1].content);
expect(res.body[1].articleId).toEqual(dummyNotification[0].articleId);
expect(res.body[1].type).toEqual(dummyNotification[0].type);
expect(res.body[1].content).toEqual(dummyNotification[0].content);
});

test('[실패] GET - 로그인하지 않고 호출', async () => {
Expand Down
6 changes: 3 additions & 3 deletions libs/utils/src/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ describe('includeRole', () => {
test('ADMIN 권한을 확인하는 경우', () => {
const result = includeRole(UserRole.ADMIN);

expect(result.sort()).toStrictEqual([UserRole.ADMIN, UserRole.CADET, UserRole.NOVICE]);
expect(result.sort()).toStrictEqual([UserRole.ADMIN, UserRole.CADET, UserRole.GUEST, UserRole.NOVICE]);
});

test('CADET 권한을 확인하는 경우', () => {
const result = includeRole(UserRole.CADET);

expect(result.sort()).toStrictEqual([UserRole.CADET, UserRole.NOVICE]);
expect(result.sort()).toStrictEqual([UserRole.CADET, UserRole.GUEST, UserRole.NOVICE]);
});

test('NOVICE 권한을 확인하는 경우', () => {
const result = includeRole(UserRole.NOVICE);

expect(result.sort()).toStrictEqual([UserRole.NOVICE]);
expect(result.sort()).toStrictEqual([UserRole.GUEST, UserRole.NOVICE]);
});
});

0 comments on commit b57a550

Please sign in to comment.