feat: complete testing, security, dynamic content, and devops overhaul
This commit is contained in:
1 parent
467532713c
commit
40ff169dc2
52 files changed
+3918
-104
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AuthController } from './auth.controller';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
describe('AuthController', () => {
|
||||
let controller: AuthController;
|
||||
let service: AuthService;
|
||||
|
||||
const mockAuthService = {
|
||||
sendOtp: jest.fn().mockResolvedValue({ success: true, message: 'کد تایید ارسال شد' }),
|
||||
verifyOtp: jest.fn().mockResolvedValue({ success: true, data: { accessToken: 'token' } }),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AuthController],
|
||||
providers: [
|
||||
{ provide: AuthService, useValue: mockAuthService },
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<AuthController>(AuthController);
|
||||
service = module.get<AuthService>(AuthService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
|
||||
it('should call sendOtp on service', async () => {
|
||||
const dto = { phoneNumber: '09123456789' };
|
||||
const result = await controller.sendOtp(dto);
|
||||
expect(service.sendOtp).toHaveBeenCalledWith(dto);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('should call verifyOtp on service', async () => {
|
||||
const dto = { phoneNumber: '09123456789', code: '12345' };
|
||||
const result = await controller.verifyOtp(dto);
|
||||
expect(service.verifyOtp).toHaveBeenCalledWith(dto);
|
||||
expect(result.data.accessToken).toBe('token');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user