-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bcfca6
commit 40d4e90
Showing
51 changed files
with
229 additions
and
126 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
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
8 changes: 4 additions & 4 deletions
8
src/modules/auth/controllers/private/private-auth.controller.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
4 changes: 2 additions & 2 deletions
4
src/modules/auth/controllers/public/public-auth.controller.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
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
17 changes: 12 additions & 5 deletions
17
src/modules/auth/tests/controllers/auth.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
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 |
---|---|---|
@@ -1,18 +1,101 @@ | ||
import { Test, TestingModule } from '@nestjs/testing' | ||
import { AuthService } from '../../services/auth.service' | ||
// import { UserService } from '@src/modules/user/services' | ||
// import { AuthService, LoginAttemptService } from '../../services' | ||
// import { SessionService } from '@src/modules/session/services' | ||
// import { HashUtil, TokenUtil } from '@src/shared/utils' | ||
// import { Test, TestingModule } from '@nestjs/testing' | ||
// import { LoginDto } from '../../dtos' | ||
// import { CreateUserDto } from '@src/modules/user/dtos' | ||
// import { User } from '@src/modules/user/schemas' | ||
|
||
describe('AuthService', () => { | ||
let service: AuthService | ||
// // Import the actual TokenUtil for mocking | ||
// import { TokenUtil as RealTokenUtil } from '@src/shared/utils/token.util' | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [AuthService], | ||
}).compile() | ||
// // Mock the TokenUtil methods | ||
// jest.mock('@src/shared/utils/token.util') | ||
|
||
service = module.get<AuthService>(AuthService) | ||
}) | ||
// describe('🏠Auth Service | Login', () => { | ||
// let authService: AuthService | ||
// let fakeUserService: Partial<UserService> | ||
// let fakeLoginAttemptService: Partial<LoginAttemptService> | ||
// let fakeSessionService: Partial<SessionService> | ||
// let fakeHashUtil: Partial<HashUtil> | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined() | ||
}) | ||
}) | ||
// beforeEach(async () => { | ||
// fakeUserService = { | ||
// createUser: jest.fn(), | ||
// findUserByEmail: jest.fn(), | ||
// } | ||
|
||
// fakeLoginAttemptService = { | ||
// isFailedLoginAttemptsExceeded: jest.fn(), | ||
// incrementFailedLoginAttemptsCount: jest.fn(), | ||
// } | ||
|
||
// fakeSessionService = { | ||
// createSession: jest.fn(), | ||
// getSession: jest.fn(), | ||
// deleteSession: jest.fn(), | ||
// } | ||
|
||
// fakeHashUtil = { | ||
// verifyHash: jest.fn(async () => await Promise.resolve(true)), // Provide a mock implementation | ||
// } | ||
|
||
// // Reset the mock implementation for each test | ||
// ;(RealTokenUtil.generateAccessToken as jest.Mock).mockReset() | ||
// ;(RealTokenUtil.generateRefreshToken as jest.Mock).mockReset() | ||
// ;(RealTokenUtil.verifyAccessToken as jest.Mock).mockReset() | ||
// ;(RealTokenUtil.verifyRefreshToken as jest.Mock).mockReset() | ||
|
||
// const module: TestingModule = await Test.createTestingModule({ | ||
// providers: [ | ||
// AuthService, | ||
// { provide: UserService, useValue: fakeUserService }, | ||
// { provide: LoginAttemptService, useValue: fakeLoginAttemptService }, | ||
// { provide: SessionService, useValue: fakeSessionService }, | ||
// { provide: HashUtil, useValue: fakeHashUtil }, | ||
// { provide: TokenUtil, useClass: RealTokenUtil }, // Use the actual TokenUtil class | ||
// ], | ||
// }).compile() | ||
|
||
// authService = module.get<AuthService>(AuthService) | ||
// }) | ||
|
||
// it('should login successfully and return tokens', async () => { | ||
// const mockData: LoginDto = { | ||
// email: 'test@example.com', | ||
// password: 'password123', | ||
// } | ||
|
||
// const mockUser = { _id: 'mockUserId', password: 'hashedPassword' } | ||
// const mockIpAddress = '127.0.0.1' | ||
// const mockDevice = { browser: 'Chrome' } | ||
// const mockAccessToken = 'mockAccessToken' | ||
// const mockRefreshToken = 'mockRefreshToken' | ||
|
||
// fakeUserService.findUserByEmail.mockResolvedValueOnce(mockUser) | ||
|
||
// // Mock the TokenUtil methods | ||
// ;(RealTokenUtil.generateAccessToken as jest.Mock).mockResolvedValueOnce(mockAccessToken) | ||
// ;(RealTokenUtil.generateRefreshToken as jest.Mock).mockResolvedValueOnce(mockRefreshToken) | ||
|
||
// const result = await authService.login(mockData, mockIpAddress, mockDevice) | ||
|
||
// expect(result).toEqual({ | ||
// accessToken: mockAccessToken, | ||
// refreshToken: mockRefreshToken, | ||
// }) | ||
|
||
// expect(fakeLoginAttemptService.isFailedLoginAttemptsExceeded).toHaveBeenCalled() | ||
// expect(fakeUserService.findUserByEmail).toHaveBeenCalledWith(mockData.email) | ||
// expect(fakeHashUtil.verifyHash).toHaveBeenCalledWith(mockData.password, mockUser.password) | ||
// expect(RealTokenUtil.generateAccessToken).toHaveBeenCalledWith({ _id: mockUser._id }) | ||
// expect(RealTokenUtil.generateRefreshToken).toHaveBeenCalledWith({ _id: mockUser._id }) | ||
// expect(fakeSessionService.createSession).toHaveBeenCalledWith({ | ||
// accessToken: mockAccessToken, | ||
// refreshToken: mockRefreshToken, | ||
// ipAddress: mockIpAddress, | ||
// device: mockDevice, | ||
// }) | ||
// }) | ||
// }) |
4 changes: 2 additions & 2 deletions
4
src/modules/keyword/controllers/private/private-keyword.controller.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
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
4 changes: 2 additions & 2 deletions
4
src/modules/post/controllers/private/private-post-analytics.controller.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
6 changes: 3 additions & 3 deletions
6
src/modules/post/controllers/private/private-post-core.controller.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
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
6 changes: 3 additions & 3 deletions
6
src/modules/quote/controllers/private/private-quote.controller.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
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
Oops, something went wrong.