Skip to content

Commit 1684f26

Browse files
committed
test(redirect): refactor RedirectService test setup for improved clarity and organization
1 parent 36b91b0 commit 1684f26

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/server/modules/redirect/services/__tests__/RedirectService.test.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,24 @@ const mockLinkStatisticsService = {
3636
}
3737

3838
describe('RedirectService', () => {
39-
let redirectService: RedirectService
39+
// Create service instance with mocked dependencies
40+
const redirectService = new RedirectService(
41+
mockUrlRepository as unknown as UrlRepositoryInterface,
42+
mockCrawlerCheckService as unknown as CrawlerCheckService,
43+
mockCookieArrayReducerService as unknown as CookieArrayReducerService,
44+
mockLinkStatisticsService as unknown as LinkStatisticsService,
45+
)
4046

4147
beforeEach(() => {
42-
// Reset mocks
4348
jest.clearAllMocks()
4449

45-
// Setup default mock returns
50+
// Setup default mock returns after clearing
4651
mockUrlRepository.getLongUrl.mockResolvedValue('https://example.com')
4752
mockCrawlerCheckService.isCrawler.mockReturnValue(false)
4853
mockCookieArrayReducerService.userHasVisitedShortlink.mockReturnValue(false)
4954
mockCookieArrayReducerService.writeShortlinkToCookie.mockReturnValue([
5055
'test',
5156
])
52-
53-
// Create service instance with mocked dependencies
54-
redirectService = new RedirectService(
55-
mockUrlRepository as unknown as UrlRepositoryInterface,
56-
mockCrawlerCheckService as unknown as CrawlerCheckService,
57-
mockCookieArrayReducerService as unknown as CookieArrayReducerService,
58-
mockLinkStatisticsService as unknown as LinkStatisticsService,
59-
)
6057
})
6158

6259
describe('redirectFor', () => {

0 commit comments

Comments
 (0)