Skip to content

Commit 91dafc3

Browse files
committed
Add Step definition for AddCarToFleet
1 parent 4e8ebee commit 91dafc3

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

packages/be/features/step_definitions/AddCarToFleetSteps.ts

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
11
import { binding, given, then, when } from "cucumber-tsflow";
2-
2+
import { Car } from '@app/shared/types/fleet-management/car/car';
3+
import { addCarToFleet } from "@app/shared/commands/fleet-management/add-car-to-fleet";
4+
import { handleAddCarToFleet } from "@server/command-handlers/fleet-management/car/handle-add-car-to-fleet";
5+
import { Event } from "@event-engine/messaging/event";
36
@binding()
47
class AddCarToFleetSteps {
8+
9+
private car: Car | undefined;
10+
private events: Array<Event> = [];
511
@given('car is BMW model 1er')
6-
public givenCarWithBrandAndModel (): string {
7-
// Write code here that turns the phrase above into concrete actions
8-
return 'pending';
12+
public givenCarWithBrandAndModel (): void {
13+
this.car = {
14+
'vehicleId': 'f832125e-4a4f-4cef-963c-c783a73a52fe',
15+
'brand' : 'BMW',
16+
'model': '1er'
17+
};
918
}
1019

1120
@when(/I add the car to the fleet/)
12-
public addsCarToFleet(): string {
13-
// Write code here that turns the phrase above into concrete actions
14-
return 'pending';
21+
public addsCarToFleet(): void {
22+
const car = this.car;
23+
if (car === undefined) {
24+
25+
return;
26+
}
27+
const command = addCarToFleet({...car});
28+
(async () => {
29+
for await (const event of handleAddCarToFleet(car, command))
30+
this.events.push(event);
31+
})();
1532
}
1633

1734
@then(/an incomplete car should be added/)
18-
public thenIncompleteCarAdded(): string {
19-
// Write code here that turns the phrase above into concrete actions
20-
return 'pending';
35+
public thenIncompleteCarAdded(): void {
36+
expect(this.events).toHaveLength(1);
37+
const receivedEvent = this.events.pop();
38+
39+
expect(receivedEvent?.name).toBe('FleetManagement.Car.IncompleteCarAdded');
2140
}
2241
}
2342

packages/be/features/tsconfig.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
{
2-
"compilerOptions": {
3-
"moduleResolution": "node",
4-
"experimentalDecorators": true
5-
}
6-
}
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"moduleResolution": "node",
5+
"experimentalDecorators": true
6+
},
7+
"include": ["step_definitions/**/*.ts"]
8+
}

packages/be/nodemon.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"watch": ["src", "../shared"],
2+
"watch": ["src", "features", "../shared"],
33
"ext": "ts,json",
44
"ignore": ["src/**/*.spec.ts", "../shared/**/*.spec.ts"],
55
"exec": "npx ts-node -r tsconfig-paths/register src/main.ts"

packages/be/tsconfig.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
},
99
{
1010
"path": "./tsconfig.spec.json"
11+
},
12+
{
13+
"path": "./features/tsconfig.json"
1114
}
1215
],
1316
"compilerOptions": {
14-
"esModuleInterop": true
17+
"esModuleInterop": true,
18+
"moduleResolution": "node",
19+
"experimentalDecorators": true
1520
}
1621
}

0 commit comments

Comments
 (0)