Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ generate-migrations:
run-migrations:
$(DOCKER_COMPOSE_CMD) exec api-dev sh -c "npm run migration:run"

test:
$(DOCKER_COMPOSE_CMD) exec api-dev sh -c "npm run test"

cov:
$(DOCKER_COMPOSE_CMD) exec api-dev sh -c "npm run test:cov"

build: ## Build the Docker images
ifndef PROFILE
@$(MAKE) list-profiles
Expand Down
43 changes: 41 additions & 2 deletions src/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,57 @@ import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;

const mockAppService = {
getHello: jest.fn().mockReturnValue('Hello World!'),
getStatus: jest.fn().mockReturnValue({ online: true }),
getOpenSourceLink: jest.fn().mockReturnValue({
visibility: 'Public',
ownership: '@SebastienCozeDev',
link: 'https://github.com/SebastienCozeDev/task-flow-api',
}),
};

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
providers: [
{
provide: AppService,
useValue: mockAppService,
},
],
}).compile();

appController = app.get<AppController>(AppController);
jest.clearAllMocks();
});

it('should be defined', () => {
expect(appController).toBeDefined();
});

describe('root', () => {
describe('getHello', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
expect(mockAppService.getHello).toHaveBeenCalledTimes(1);
});
});

describe('getStatus', () => {
it('should return the application status', () => {
expect(appController.getStatus()).toEqual({ online: true });
expect(mockAppService.getStatus).toHaveBeenCalledTimes(1);
});
});

describe('getOpenSourceLink', () => {
it('should return the repository information', () => {
expect(appController.getOpenSourceLink()).toEqual({
visibility: 'Public',
ownership: '@SebastienCozeDev',
link: 'https://github.com/SebastienCozeDev/task-flow-api',
});
expect(mockAppService.getOpenSourceLink).toHaveBeenCalledTimes(1);
});
});
});
2 changes: 1 addition & 1 deletion src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class AppService {

getOpenSourceLink(): { visibility: string, ownership: string, link: string } {
return {
visibility: "Private",
visibility: "Public",
ownership: "@SebastienCozeDev",
link: "https://github.com/SebastienCozeDev/task-flow-api",
}
Expand Down