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,73 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PetsController } from './pets.controller';
|
||||
import { PetsService } from './pets.service';
|
||||
|
||||
describe('PetsController', () => {
|
||||
let controller: PetsController;
|
||||
let service: PetsService;
|
||||
|
||||
const mockPetsService = {
|
||||
create: jest.fn().mockResolvedValue({ id: 'pet-id', name: 'Buddy' }),
|
||||
findAllByUser: jest.fn().mockResolvedValue([{ id: 'pet-id', name: 'Buddy' }]),
|
||||
findOne: jest.fn().mockResolvedValue({ id: 'pet-id', name: 'Buddy' }),
|
||||
update: jest.fn().mockResolvedValue({ id: 'pet-id', name: 'Buddy New' }),
|
||||
remove: jest.fn().mockResolvedValue({ success: true }),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PetsController],
|
||||
providers: [
|
||||
{ provide: PetsService, useValue: mockPetsService },
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<PetsController>(PetsController);
|
||||
service = module.get<PetsService>(PetsService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
|
||||
it('should create pet', async () => {
|
||||
const req = { user: { id: 'user-id' } };
|
||||
const dto = { name: 'Buddy', type: 'Dog' };
|
||||
const result = await controller.create(req, dto);
|
||||
expect(service.create).toHaveBeenCalledWith('user-id', dto);
|
||||
expect(result.id).toBe('pet-id');
|
||||
});
|
||||
|
||||
it('should findAll pets', async () => {
|
||||
const req = { user: { id: 'user-id' } };
|
||||
const result = await controller.findAll(req);
|
||||
expect(service.findAllByUser).toHaveBeenCalledWith('user-id');
|
||||
expect(result).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should findOne pet', async () => {
|
||||
const req = { user: { id: 'user-id' } };
|
||||
const result = await controller.findOne(req, 'pet-id');
|
||||
expect(service.findOne).toHaveBeenCalledWith('pet-id', 'user-id');
|
||||
expect(result.id).toBe('pet-id');
|
||||
});
|
||||
|
||||
it('should update pet', async () => {
|
||||
const req = { user: { id: 'user-id' } };
|
||||
const dto = { name: 'Buddy New' };
|
||||
const result = await controller.update(req, 'pet-id', dto);
|
||||
expect(service.update).toHaveBeenCalledWith('pet-id', 'user-id', dto);
|
||||
expect(result.name).toBe('Buddy New');
|
||||
});
|
||||
|
||||
it('should remove pet', async () => {
|
||||
const req = { user: { id: 'user-id' } };
|
||||
const result = await controller.remove(req, 'pet-id');
|
||||
expect(service.remove).toHaveBeenCalledWith('pet-id', 'user-id');
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user