Skip to content

Commit 1e00528

Browse files
committed
Add jest-stare for test report
1 parent 37b0848 commit 1e00528

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

jest.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
roots: ['<rootDir>/src', '<rootDir>/test'],
5+
testMatch: ['<rootDir>/test/**/*.spec.ts'],
6+
moduleFileExtensions: ['ts', 'js', 'json'],
7+
transform: {
8+
'^.+\\.ts$': ['ts-jest', {
9+
tsconfig: '<rootDir>/tsconfig.json',
10+
diagnostics: true,
11+
}],
12+
},
13+
coverageDirectory: 'coverage',
14+
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts'],
15+
moduleNameMapper: {
16+
'^src/(.*)$': '<rootDir>/src/$1',
17+
},
18+
reporters: [
19+
'default',
20+
['jest-stare', {
21+
resultDir: 'jest-stare',
22+
reportTitle: 'NotifyLog Test Results',
23+
coverageLink: '../coverage/lcov-report/index.html',
24+
}],
25+
],
26+
};

test/notification/notification.controller.spec.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { LoggerServiceFile } from '../../src/logger/services/logger.service.file
66
import { LoggerServiceDb } from '../../src/logger/services/logger.service.db';
77
import { SendNotificationDto } from '../../src/notification/presentation/dtos/send-notification.dto';
88
import { Notification } from '../../src/notification/domain/entities/notification.entity';
9-
import { NotificationChannel, NotificationType } from '../../src/config/notification.config';
9+
import {
10+
NotificationChannel,
11+
NotificationType,
12+
} from '../../src/config/notification.config';
1013

1114
describe('NotificationController', () => {
1215
let controller: NotificationController;
@@ -18,7 +21,6 @@ describe('NotificationController', () => {
1821
'Test Subject',
1922
'Test Body',
2023
NotificationChannel.EMAIL,
21-
NotificationType.ADMISSION_ID,
2224
new Date(),
2325
);
2426

@@ -83,7 +85,11 @@ describe('NotificationController', () => {
8385
it('should send notification and log successfully', async () => {
8486
await controller.send(mockSendDto);
8587

86-
expect(factory.createStrategy).toHaveBeenCalledWith(mockSendDto.mediaType);
88+
// eslint-disable-next-line @typescript-eslint/unbound-method
89+
expect(factory.createStrategy).toHaveBeenCalledWith(
90+
mockSendDto.mediaType,
91+
);
92+
// eslint-disable-next-line @typescript-eslint/unbound-method
8793
expect(repository.save).toHaveBeenCalledWith(expect.any(Notification));
8894
expect(mockStrategy.send).toHaveBeenCalledWith(expect.any(Notification));
8995
});
@@ -102,6 +108,7 @@ describe('NotificationController', () => {
102108
jest.spyOn(repository, 'findAll');
103109
const result = await controller.getNotificationHistory(1, 10);
104110

111+
// eslint-disable-next-line @typescript-eslint/unbound-method
105112
expect(repository.findAll).toHaveBeenCalledWith(0, 10);
106113
expect(result).toEqual({
107114
data: [mockNotification],
@@ -112,9 +119,12 @@ describe('NotificationController', () => {
112119
});
113120

114121
it('should handle custom pagination', async () => {
115-
jest.spyOn(repository, 'findAll').mockResolvedValue([mockNotification, mockNotification]);
122+
jest
123+
.spyOn(repository, 'findAll')
124+
.mockResolvedValue([mockNotification, mockNotification]);
116125
const result = await controller.getNotificationHistory(2, 5);
117126

127+
// eslint-disable-next-line @typescript-eslint/unbound-method
118128
expect(repository.findAll).toHaveBeenCalledWith(5, 5);
119129
expect(result).toEqual({
120130
data: [mockNotification, mockNotification],

0 commit comments

Comments
 (0)