Skip to content

Commit af56cb0

Browse files
committed
Finish Get CoursesCounter feature
1 parent 5f5ce97 commit af56cb0

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

src/Contexts/Mooc/CoursesCounter/application/Find/CoursesCounterFinder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class CoursesCounterFinder {
77

88
async run() {
99
const counter = await this.repository.search();
10-
if (counter === null) {
10+
if (!counter) {
1111
throw new CoursesCounterNotExist();
1212
}
1313

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export class CoursesCounterNotExist extends Error {
22
constructor() {
3-
super('The courses counter not exist');
3+
super('The courses counter does not exists');
44
}
55
}

src/apps/mooc_backend/controllers/CoursesCounterGetController.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ import { Controller } from './Controller';
22
import { Request, Response } from 'express';
33
import { CoursesCounterFinder } from '../../../Contexts/Mooc/CoursesCounter/application/Find/CoursesCounterFinder';
44
import httpStatus = require('http-status');
5+
import { CoursesCounterNotExist } from '../../../Contexts/Mooc/CoursesCounter/domain/CoursesCounterNotExist';
56

67
export class CoursesCounterGetController implements Controller {
78
constructor(private coursesCounterFinder: CoursesCounterFinder) {}
89
async run(req: Request, res: Response): Promise<void> {
9-
const counter = this.coursesCounterFinder.run();
10-
11-
res.status(httpStatus.OK).send(counter);
10+
try {
11+
const counter = await this.coursesCounterFinder.run();
12+
res.status(httpStatus.OK).send(counter);
13+
} catch (e) {
14+
if (e instanceof CoursesCounterNotExist) {
15+
res.status(httpStatus.NOT_FOUND).send();
16+
} else {
17+
res.status(httpStatus.INTERNAL_SERVER_ERROR).send();
18+
}
19+
}
1220
}
1321
}

tests/apps/mooc_backend/features/step_definitions/controller.steps.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ let _request: request.Test;
99
let _response: request.Response;
1010

1111
Given('I send a GET request to {string}', (route: string) => {
12-
console.log(route)
1312
_request = request(app).get(route);
1413
});
1514

@@ -27,6 +26,10 @@ Then('the response should be empty', () => {
2726
assert.deepEqual(_response.body, {});
2827
});
2928

29+
Then('the response content should be:', response => {
30+
assert.deepEqual(_response.body, response);
31+
});
32+
3033
Before(async () => {
3134
const environmentArranger: Promise<EnvironmentArranger> = container.get('Mooc.EnvironmentArranger');
3235
await (await environmentArranger).arrange();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Given } from 'cucumber';
2+
import container from '../../../../../src/apps/mooc_backend/config/dependency-injection';
3+
import { EventBus } from '../../../../../src/Contexts/Shared/domain/EventBus';
4+
5+
Given('I send an event to the event bus:', (event: any) => {
6+
const eventBus = container.get('Mooc.shared.EventBus') as EventBus;
7+
eventBus.publish([event]);
8+
});

0 commit comments

Comments
 (0)