Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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; Pass between actors
);
});
class Actors implements DressingRoom {
prepare(actor: Actor): Actor {
return actor.whoCan(
ManageALocalServer.runningAHttpListener(handler()),
CallAnApi.using(axios.create()),
);
}
}
Nadia = stage(new Actors()).theActorCalled('Nadia');
return expect(Nadia.attemptsTo(
StartLocalServer.onRandomPort(),
Ensure.that(LocalServer.url(), startsWith('http://127.0.0.1')),
Send.a(GetRequest.to(LocalServer.url())),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body(), equals('Hello World!')),
)).to.be.fulfilled; // tslint:disable-line:no-unused-expression
});
prepare(actor: Actor): Actor {
return actor.whoCan(
ManageALocalServer.runningAHttpListener(handler()),
CallAnApi.using(axios.create()),
);
}
}
Nadia = stage(new Actors()).theActorCalled('Nadia');
return expect(Nadia.attemptsTo(
StartLocalServer.onRandomPort(),
Ensure.that(LocalServer.url(), startsWith('http://127.0.0.1')),
Send.a(GetRequest.to(LocalServer.url())),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body(), equals('Hello World!')),
)).to.be.fulfilled; // tslint:disable-line:no-unused-expression
});
export const VerifyResultAt = (url: Answerable, expectation: Expectation>) =>
Task.where(`#actor verifies result at ${ url }`,
Send.a(GetRequest.to(url)),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body(), expectation),
);
export const RequestCalculationOf = (expression: string) =>
Task.where(`#actor requests calculation of ${ expression }`,
Send.a(
PostRequest.to('/api/calculations').with(expression).using({ headers: { 'Content-Type': 'text/plain' }}),
),
Ensure.that(LastResponse.status(), equals(201)),
Ensure.that(LastResponse.header('location'), startsWith('/api/calculations/')),
);
export const VerifyResultAt = (url: Answerable, expectation: Expectation>) =>
Task.where(`#actor verifies result at ${ url }`,
Send.a(GetRequest.to(url)),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body(), expectation),
);
export const RequestCalculationOf = (expression: string) =>
Task.where(`#actor requests calculation of ${ expression }`,
Send.a(
PostRequest.to('/api/calculations').with(expression).using({ headers: { 'Content-Type': 'text/plain' }}),
),
Ensure.that(LastResponse.status(), equals(201)),
Ensure.that(LastResponse.header('location'), startsWith('/api/calculations/')),
);
export const VerifyResultAt = (url: Answerable, expectation: Expectation>) =>
Task.where(`#actor verifies result at ${ url }`,
Send.a(GetRequest.to(url)),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body(), expectation),
);
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) })),
);
});
export const RequestCalculationOf = (expression: string) =>
Task.where(`#actor requests calculation of ${ expression }`,
Send.a(
PostRequest.to('/api/calculations').with(expression).using({ headers: { 'Content-Type': 'text/plain' }}),
),
Ensure.that(LastResponse.status(), equals(201)),
Ensure.that(LastResponse.header('location'), startsWith('/api/calculations/')),
);