|
1 | 1 | 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"; |
3 | 6 | @binding()
|
4 | 7 | class AddCarToFleetSteps {
|
| 8 | + |
| 9 | + private car: Car | undefined; |
| 10 | + private events: Array<Event> = []; |
5 | 11 | @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 | + }; |
9 | 18 | }
|
10 | 19 |
|
11 | 20 | @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 | + })(); |
15 | 32 | }
|
16 | 33 |
|
17 | 34 | @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'); |
21 | 40 | }
|
22 | 41 | }
|
23 | 42 |
|
|
0 commit comments