/
api-level.steps.ts
32 lines (28 loc) · 1.33 KB
/
api-level.steps.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { equals } from '@serenity-js/assertions';
import { WithStage } from '@serenity-js/cucumber';
import { LocalServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server';
import { ChangeApiUrl, LastResponse } from '@serenity-js/rest';
import { After, Before, Then, When } from 'cucumber';
import { RequestCalculationOf, VerifyResultAt } from '../support/screenplay';
Before(function() {
return this.stage.theActorCalled('Apisitt').attemptsTo( // todo: change to Maggie
StartLocalServer.onRandomPort(),
ChangeApiUrl.to(LocalServer.url()),
// TakeNote.of(LocalServer.url()) // Question or Question<Promise>; Pass between actors
);
});
When(/^(.*) asks for the following calculation: (.*)$/, function(this: WithStage, actorName: string, expression: string) {
return this.stage.actor(actorName).attemptsTo(
RequestCalculationOf(expression),
);
});
Then(/(?:he|she|they) should get a result of ([\d-.]+)/, function(this: WithStage, expectedResult: string) {
return this.stage.theActorInTheSpotlight().attemptsTo(
VerifyResultAt(LastResponse.header('location'), equals({ result: Number(expectedResult) })),
);
});
After(function() {
return this.stage.theActorCalled('Apisitt').attemptsTo(
StopLocalServer.ifRunning(),
);
});