@serenity-js/rest 3.0.0-rc.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +80 -1851
- package/README.md +8 -10
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/models/DeleteRequest.d.ts +66 -0
- package/lib/models/DeleteRequest.d.ts.map +1 -0
- package/lib/models/DeleteRequest.js +73 -0
- package/lib/models/DeleteRequest.js.map +1 -0
- package/lib/models/GetRequest.d.ts +73 -0
- package/lib/models/GetRequest.d.ts.map +1 -0
- package/lib/models/GetRequest.js +80 -0
- package/lib/models/GetRequest.js.map +1 -0
- package/lib/models/HTTPRequest.d.ts +48 -0
- package/lib/models/HTTPRequest.d.ts.map +1 -0
- package/lib/{model → models}/HTTPRequest.js +14 -23
- package/lib/models/HTTPRequest.js.map +1 -0
- package/lib/models/HeadRequest.d.ts +58 -0
- package/lib/models/HeadRequest.d.ts.map +1 -0
- package/lib/models/HeadRequest.js +65 -0
- package/lib/models/HeadRequest.js.map +1 -0
- package/lib/models/OptionsRequest.d.ts +61 -0
- package/lib/models/OptionsRequest.d.ts.map +1 -0
- package/lib/models/OptionsRequest.js +68 -0
- package/lib/models/OptionsRequest.js.map +1 -0
- package/lib/models/PatchRequest.d.ts +65 -0
- package/lib/models/PatchRequest.d.ts.map +1 -0
- package/lib/models/PatchRequest.js +74 -0
- package/lib/models/PatchRequest.js.map +1 -0
- package/lib/models/PostRequest.d.ts +105 -0
- package/lib/models/PostRequest.d.ts.map +1 -0
- package/lib/models/PostRequest.js +114 -0
- package/lib/models/PostRequest.js.map +1 -0
- package/lib/models/PutRequest.d.ts +75 -0
- package/lib/models/PutRequest.d.ts.map +1 -0
- package/lib/models/PutRequest.js +84 -0
- package/lib/models/PutRequest.js.map +1 -0
- package/lib/{model → models}/index.d.ts +1 -0
- package/lib/models/index.d.ts.map +1 -0
- package/lib/{model → models}/index.js +5 -1
- package/lib/models/index.js.map +1 -0
- package/lib/screenplay/abilities/CallAnApi.d.ts +88 -99
- package/lib/screenplay/abilities/CallAnApi.d.ts.map +1 -0
- package/lib/screenplay/abilities/CallAnApi.js +94 -107
- package/lib/screenplay/abilities/CallAnApi.js.map +1 -1
- package/lib/screenplay/abilities/index.d.ts +1 -0
- package/lib/screenplay/abilities/index.d.ts.map +1 -0
- package/lib/screenplay/abilities/index.js +5 -1
- package/lib/screenplay/abilities/index.js.map +1 -1
- package/lib/screenplay/index.d.ts +1 -0
- package/lib/screenplay/index.d.ts.map +1 -0
- package/lib/screenplay/index.js +5 -1
- package/lib/screenplay/index.js.map +1 -1
- package/lib/screenplay/interactions/ChangeApiConfig.d.ts +96 -95
- package/lib/screenplay/interactions/ChangeApiConfig.d.ts.map +1 -0
- package/lib/screenplay/interactions/ChangeApiConfig.js +98 -107
- package/lib/screenplay/interactions/ChangeApiConfig.js.map +1 -1
- package/lib/screenplay/interactions/Send.d.ts +24 -41
- package/lib/screenplay/interactions/Send.d.ts.map +1 -0
- package/lib/screenplay/interactions/Send.js +37 -51
- package/lib/screenplay/interactions/Send.js.map +1 -1
- package/lib/screenplay/interactions/index.d.ts +1 -1
- package/lib/screenplay/interactions/index.d.ts.map +1 -0
- package/lib/screenplay/interactions/index.js +5 -2
- package/lib/screenplay/interactions/index.js.map +1 -1
- package/lib/screenplay/questions/LastResponse.d.ts +152 -98
- package/lib/screenplay/questions/LastResponse.d.ts.map +1 -0
- package/lib/screenplay/questions/LastResponse.js +149 -97
- package/lib/screenplay/questions/LastResponse.js.map +1 -1
- package/lib/screenplay/questions/index.d.ts +1 -0
- package/lib/screenplay/questions/index.d.ts.map +1 -0
- package/lib/screenplay/questions/index.js +5 -1
- package/lib/screenplay/questions/index.js.map +1 -1
- package/package.json +20 -43
- package/src/index.ts +1 -1
- package/src/models/DeleteRequest.ts +73 -0
- package/src/models/GetRequest.ts +80 -0
- package/src/{model → models}/HTTPRequest.ts +17 -26
- package/src/models/HeadRequest.ts +65 -0
- package/src/models/OptionsRequest.ts +68 -0
- package/src/models/PatchRequest.ts +75 -0
- package/src/models/PostRequest.ts +115 -0
- package/src/models/PutRequest.ts +85 -0
- package/src/screenplay/abilities/CallAnApi.ts +90 -108
- package/src/screenplay/interactions/ChangeApiConfig.ts +99 -111
- package/src/screenplay/interactions/Send.ts +46 -61
- package/src/screenplay/interactions/index.ts +0 -1
- package/src/screenplay/questions/LastResponse.ts +153 -100
- package/tsconfig.build.json +10 -0
- package/lib/model/DeleteRequest.d.ts +0 -63
- package/lib/model/DeleteRequest.js +0 -70
- package/lib/model/DeleteRequest.js.map +0 -1
- package/lib/model/GetRequest.d.ts +0 -70
- package/lib/model/GetRequest.js +0 -77
- package/lib/model/GetRequest.js.map +0 -1
- package/lib/model/HTTPRequest.d.ts +0 -56
- package/lib/model/HTTPRequest.js.map +0 -1
- package/lib/model/HeadRequest.d.ts +0 -55
- package/lib/model/HeadRequest.js +0 -62
- package/lib/model/HeadRequest.js.map +0 -1
- package/lib/model/OptionsRequest.d.ts +0 -58
- package/lib/model/OptionsRequest.js +0 -65
- package/lib/model/OptionsRequest.js.map +0 -1
- package/lib/model/PatchRequest.d.ts +0 -65
- package/lib/model/PatchRequest.js +0 -74
- package/lib/model/PatchRequest.js.map +0 -1
- package/lib/model/PostRequest.d.ts +0 -102
- package/lib/model/PostRequest.js +0 -111
- package/lib/model/PostRequest.js.map +0 -1
- package/lib/model/PutRequest.d.ts +0 -75
- package/lib/model/PutRequest.js +0 -84
- package/lib/model/PutRequest.js.map +0 -1
- package/lib/model/index.js.map +0 -1
- package/lib/screenplay/interactions/ChangeApiUrl.d.ts +0 -82
- package/lib/screenplay/interactions/ChangeApiUrl.js +0 -97
- package/lib/screenplay/interactions/ChangeApiUrl.js.map +0 -1
- package/src/model/DeleteRequest.ts +0 -71
- package/src/model/GetRequest.ts +0 -78
- package/src/model/HeadRequest.ts +0 -63
- package/src/model/OptionsRequest.ts +0 -66
- package/src/model/PatchRequest.ts +0 -76
- package/src/model/PostRequest.ts +0 -113
- package/src/model/PutRequest.ts +0 -86
- package/src/screenplay/interactions/ChangeApiUrl.ts +0 -97
- package/tsconfig.eslint.json +0 -10
- /package/src/{model → models}/index.ts +0 -0
|
@@ -1,64 +1,47 @@
|
|
|
1
1
|
import { Answerable, AnswersQuestions, CollectsArtifacts, Interaction, UsesAbilities } from '@serenity-js/core';
|
|
2
2
|
import { AxiosRequestConfig } from 'axios';
|
|
3
3
|
/**
|
|
4
|
-
* @
|
|
5
|
-
* Sends a {@link HTTPRequest} to a specified url.
|
|
6
|
-
* The response to the request is made available via the {@link LastResponse}
|
|
7
|
-
* {@link @serenity-js/core/lib/screenplay~Question}s.
|
|
4
|
+
* Sends a {@apilink HTTPRequest} to a specified url.
|
|
8
5
|
*
|
|
9
|
-
*
|
|
10
|
-
* import { Actor } from '@serenity-js/core';
|
|
11
|
-
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
12
|
-
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
6
|
+
* The response to the request is made available via {@apilink LastResponse}.
|
|
13
7
|
*
|
|
14
|
-
*
|
|
8
|
+
* ## Send a GET request
|
|
15
9
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
12
|
+
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
13
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
20
14
|
*
|
|
21
|
-
*
|
|
15
|
+
* await actorCalled('Apisit')
|
|
16
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
17
|
+
* .attemptsTo(
|
|
18
|
+
* Send.a(GetRequest.to('/books/0-688-00230-7')),
|
|
19
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
20
|
+
* )
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @group Activities
|
|
22
24
|
*/
|
|
23
25
|
export declare class Send extends Interaction {
|
|
24
26
|
private readonly request;
|
|
25
27
|
/**
|
|
26
|
-
* @
|
|
27
|
-
* Instantiates a new {@link Send} {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
28
|
+
* Instantiates a new {@apilink Interaction|interaction} to {@apilink Send}.
|
|
28
29
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
30
|
+
* #### Learn more
|
|
31
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
31
32
|
*
|
|
32
|
-
* @
|
|
33
|
+
* @param request
|
|
33
34
|
*/
|
|
34
35
|
static a(request: Answerable<AxiosRequestConfig>): Interaction;
|
|
35
36
|
/**
|
|
36
|
-
* @param
|
|
37
|
-
*
|
|
38
|
-
* @see {@link AxiosRequestConfig}
|
|
37
|
+
* @param request
|
|
39
38
|
*/
|
|
40
|
-
constructor(request: Answerable<AxiosRequestConfig>);
|
|
39
|
+
protected constructor(request: Answerable<AxiosRequestConfig>);
|
|
41
40
|
/**
|
|
42
|
-
* @
|
|
43
|
-
* Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
44
|
-
* perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
45
|
-
*
|
|
46
|
-
* @param {UsesAbilities & CollectsArtifacts & AnswersQuestions} actor
|
|
47
|
-
* @returns {Promise<void>}
|
|
48
|
-
*
|
|
49
|
-
* @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
50
|
-
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
51
|
-
* @see {@link @serenity-js/core/lib/screenplay/actor~CollectsArtifacts}
|
|
52
|
-
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
41
|
+
* @inheritDoc
|
|
53
42
|
*/
|
|
54
43
|
performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* @desc
|
|
57
|
-
* Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
|
|
58
|
-
*
|
|
59
|
-
* @returns {string}
|
|
60
|
-
*/
|
|
61
|
-
toString(): string;
|
|
62
44
|
private responseToArtifact;
|
|
63
45
|
private requestToArtifactName;
|
|
64
46
|
}
|
|
47
|
+
//# sourceMappingURL=Send.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Send.d.ts","sourceRoot":"","sources":["../../../src/screenplay/interactions/Send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEhH,OAAO,EAAgB,kBAAkB,EAAgE,MAAM,OAAO,CAAC;AAIvH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,IAAK,SAAQ,WAAW;IAiBX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAf9C;;;;;;;OAOG;IACH,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC,GAAG,WAAW;IAI9D;;OAEG;IACH,SAAS,aAA8B,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC;IAI9E;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBrF,OAAO,CAAC,kBAAkB;IA0B1B,OAAO,CAAC,qBAAqB;CAGhC"}
|
|
@@ -3,61 +3,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Send = void 0;
|
|
4
4
|
const core_1 = require("@serenity-js/core");
|
|
5
5
|
const model_1 = require("@serenity-js/core/lib/model");
|
|
6
|
+
const axios_1 = require("axios");
|
|
6
7
|
const abilities_1 = require("../abilities");
|
|
7
8
|
/**
|
|
8
|
-
* @
|
|
9
|
-
* Sends a {@link HTTPRequest} to a specified url.
|
|
10
|
-
* The response to the request is made available via the {@link LastResponse}
|
|
11
|
-
* {@link @serenity-js/core/lib/screenplay~Question}s.
|
|
9
|
+
* Sends a {@apilink HTTPRequest} to a specified url.
|
|
12
10
|
*
|
|
13
|
-
*
|
|
14
|
-
* import { Actor } from '@serenity-js/core';
|
|
15
|
-
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
16
|
-
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
11
|
+
* The response to the request is made available via {@apilink LastResponse}.
|
|
17
12
|
*
|
|
18
|
-
*
|
|
13
|
+
* ## Send a GET request
|
|
19
14
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
17
|
+
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
18
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
24
19
|
*
|
|
25
|
-
*
|
|
20
|
+
* await actorCalled('Apisit')
|
|
21
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
22
|
+
* .attemptsTo(
|
|
23
|
+
* Send.a(GetRequest.to('/books/0-688-00230-7')),
|
|
24
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @group Activities
|
|
26
29
|
*/
|
|
27
30
|
class Send extends core_1.Interaction {
|
|
28
31
|
/**
|
|
29
|
-
* @
|
|
32
|
+
* Instantiates a new {@apilink Interaction|interaction} to {@apilink Send}.
|
|
30
33
|
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
constructor(request) {
|
|
34
|
-
super();
|
|
35
|
-
this.request = request;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @desc
|
|
39
|
-
* Instantiates a new {@link Send} {@link @serenity-js/core/lib/screenplay~Interaction}.
|
|
40
|
-
*
|
|
41
|
-
* @param {@serenity-js/lib/core/screenplay~Answerable<AxiosRequestConfig>} request
|
|
42
|
-
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
34
|
+
* #### Learn more
|
|
35
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
43
36
|
*
|
|
44
|
-
* @
|
|
37
|
+
* @param request
|
|
45
38
|
*/
|
|
46
39
|
static a(request) {
|
|
47
40
|
return new Send(request);
|
|
48
41
|
}
|
|
49
42
|
/**
|
|
50
|
-
* @
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* @
|
|
58
|
-
* @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
|
|
59
|
-
* @see {@link @serenity-js/core/lib/screenplay/actor~CollectsArtifacts}
|
|
60
|
-
* @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
|
|
43
|
+
* @param request
|
|
44
|
+
*/
|
|
45
|
+
constructor(request) {
|
|
46
|
+
super(`#actor sends ${request.toString()}`);
|
|
47
|
+
this.request = request;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @inheritDoc
|
|
61
51
|
*/
|
|
62
52
|
performAs(actor) {
|
|
63
53
|
const callAnApi = abilities_1.CallAnApi.as(actor);
|
|
@@ -67,26 +57,22 @@ class Send extends core_1.Interaction {
|
|
|
67
57
|
actor.collect(this.responseToArtifact(resolvedUrl, response), this.requestToArtifactName(response.config.method, resolvedUrl));
|
|
68
58
|
}));
|
|
69
59
|
}
|
|
70
|
-
/**
|
|
71
|
-
* @desc
|
|
72
|
-
* Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
|
|
73
|
-
*
|
|
74
|
-
* @returns {string}
|
|
75
|
-
*/
|
|
76
|
-
toString() {
|
|
77
|
-
return `#actor sends ${this.request.toString()}`;
|
|
78
|
-
}
|
|
79
60
|
responseToArtifact(targetUrl, response) {
|
|
80
|
-
const request = response.config
|
|
61
|
+
const request = response.config;
|
|
62
|
+
const axiosRequestHeaders = request.headers;
|
|
63
|
+
const requestHeaders = axios_1.AxiosHeaders.from(axiosRequestHeaders).toJSON(true);
|
|
64
|
+
const axiosResponseHeaders = response.headers;
|
|
65
|
+
const responseHeaders = axios_1.AxiosHeaders.from(axiosResponseHeaders).toJSON(false);
|
|
66
|
+
const requestAndResponse = {
|
|
81
67
|
request: {
|
|
82
68
|
method: request.method,
|
|
83
69
|
url: targetUrl,
|
|
84
|
-
headers:
|
|
70
|
+
headers: requestHeaders,
|
|
85
71
|
data: request.data,
|
|
86
72
|
},
|
|
87
73
|
response: {
|
|
88
74
|
status: response.status,
|
|
89
|
-
headers:
|
|
75
|
+
headers: responseHeaders,
|
|
90
76
|
data: response.data,
|
|
91
77
|
},
|
|
92
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Send.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/Send.ts"],"names":[],"mappings":";;;AAAA,4CAAgH;AAChH,uDAAsG;
|
|
1
|
+
{"version":3,"file":"Send.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/Send.ts"],"names":[],"mappings":";;;AAAA,4CAAgH;AAChH,uDAAsG;AACtG,iCAAuH;AAEvH,4CAAyC;AAEzC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,IAAK,SAAQ,kBAAW;IAEjC;;;;;;;OAOG;IACH,MAAM,CAAC,CAAC,CAAC,OAAuC;QAC5C,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,YAAuC,OAAuC;QAC1E,KAAK,CAAC,gBAAiB,OAAO,CAAC,QAAQ,EAAG,EAAE,CAAC,CAAC;QADX,YAAO,GAAP,OAAO,CAAgC;IAE9E,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,KAA2D;QACjE,MAAM,SAAS,GAAG,qBAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;QAEtC,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;aAC5B,IAAI,CAAC,MAAM,CAAC,EAAE,CACX,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,QAAuB,EAAE,EAAE;YACvD,MAAM,WAAW,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAEjD,KAAK,CAAC,OAAO,CACT,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,QAAQ,CAAC,EAC9C,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAClE,CAAC;QACN,CAAC,CAAC,CACL,CAAC;IACV,CAAC;IAEO,kBAAkB,CAAC,SAAiB,EAAE,QAAuB;QACjE,MAAM,OAAO,GAAuB,QAAQ,CAAC,MAAM,CAAC;QAEpD,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;QAC5C,MAAM,cAAc,GAA8C,oBAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,CAAC,IAAI,CAA8C,CAAC;QAEnK,MAAM,oBAAoB,GAAmD,QAAQ,CAAC,OAAO,CAAC;QAC9F,MAAM,eAAe,GAAG,oBAAY,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,KAAK,CAA4B,CAAC;QAEzG,MAAM,kBAAkB,GAAuB;YAC3C,OAAO,EAAE;gBACL,MAAM,EAAM,OAAO,CAAC,MAAM;gBAC1B,GAAG,EAAS,SAAS;gBACrB,OAAO,EAAK,cAAc;gBAC1B,IAAI,EAAQ,OAAO,CAAC,IAAI;aAC3B;YACD,QAAQ,EAAE;gBACN,MAAM,EAAM,QAAQ,CAAC,MAAM;gBAC3B,OAAO,EAAK,eAAkF;gBAC9F,IAAI,EAAQ,QAAQ,CAAC,IAAI;aAC5B;SACJ,CAAC;QAEF,OAAO,2BAAmB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IAC5D,CAAC;IAEO,qBAAqB,CAAC,MAAc,EAAE,GAAW;QACrD,OAAO,IAAI,YAAI,CAAC,GAAI,MAAM,CAAC,WAAW,EAAG,IAAK,GAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;CACJ;AArED,oBAqEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screenplay/interactions/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,6 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./ChangeApiConfig"), exports);
|
|
14
|
-
__exportStar(require("./ChangeApiUrl"), exports);
|
|
15
18
|
__exportStar(require("./Send"), exports);
|
|
16
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,yCAAuB"}
|
|
@@ -1,135 +1,189 @@
|
|
|
1
1
|
import { QuestionAdapter } from '@serenity-js/core';
|
|
2
|
+
import { RawAxiosResponseHeaders } from 'axios';
|
|
2
3
|
/**
|
|
3
|
-
* @
|
|
4
|
-
*
|
|
5
|
-
* cached on the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability}.
|
|
4
|
+
* Provides access to the properties of the last {@apilink AxiosResponse} object,
|
|
5
|
+
* cached on the {@apilink Ability|ability} to {@apilink CallAnApi}.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* import { Actor } from '@serenity-js/core';
|
|
9
|
-
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
10
|
-
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
7
|
+
* ## Verify response to a GET request
|
|
11
8
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
11
|
+
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
12
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
16
13
|
*
|
|
17
|
-
*
|
|
14
|
+
* interface Book {
|
|
15
|
+
* title: string;
|
|
16
|
+
* author: string;
|
|
17
|
+
* }
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
19
|
+
* await actorCalled('Apisit')
|
|
20
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
21
|
+
* .attemptsTo(
|
|
22
|
+
* Send.a(GetRequest.to('/books/0-688-00230-7')),
|
|
23
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
24
|
+
* Ensure.that(LastResponse.header('Content-Type'), equals('application/json')),
|
|
25
|
+
* Ensure.that(LastResponse.body<Book>(), equals({
|
|
26
|
+
* title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
|
|
27
|
+
* author: 'Robert M. Pirsig',
|
|
28
|
+
* })),
|
|
29
|
+
* )
|
|
30
|
+
* ```
|
|
28
31
|
*
|
|
29
|
-
*
|
|
30
|
-
* import { Actor } from '@serenity-js/core';
|
|
31
|
-
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
32
|
-
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
32
|
+
* ## Use Serenity/JS adapters to navigate complex response objects
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* }
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
36
|
+
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
37
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
39
|
+
* interface Developer {
|
|
40
|
+
* name: string;
|
|
41
|
+
* id: string;
|
|
42
|
+
* projects: Project[];
|
|
43
|
+
* }
|
|
44
44
|
*
|
|
45
|
-
*
|
|
45
|
+
* interface Project {
|
|
46
|
+
* name: string;
|
|
47
|
+
* repoUrl: string;
|
|
48
|
+
* }
|
|
46
49
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
50
|
+
* await actorCalled('Apisitt')
|
|
51
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
52
|
+
* .attemptsTo(
|
|
53
|
+
* Send.a(GetRequest.to('/developers/jan-molak')),
|
|
54
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
55
|
+
* Ensure.that(LastResponse.body<Developer>().name, equals('Jan Molak')),
|
|
56
|
+
* Ensure.that(LastResponse.body<Developer>().projects[0].name, equals('Serenity/JS')),
|
|
57
|
+
* )
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* ## Learn more
|
|
61
|
+
* - [AxiosResponse](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L133-L140)
|
|
62
|
+
*
|
|
63
|
+
* @group Questions
|
|
53
64
|
*/
|
|
54
65
|
export declare class LastResponse {
|
|
55
66
|
/**
|
|
56
|
-
* @
|
|
57
|
-
* Enables asserting on the {@link LastResponse} status
|
|
67
|
+
* Retrieves the status code of the {@apilink LastResponse|last response}
|
|
58
68
|
*
|
|
59
|
-
*
|
|
69
|
+
* #### Learn more
|
|
70
|
+
* - [HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
|
|
60
71
|
*/
|
|
61
72
|
static status(): QuestionAdapter<number>;
|
|
62
73
|
/**
|
|
63
|
-
* @
|
|
64
|
-
*
|
|
74
|
+
* Retrieves the body of the {@apilink LastResponse|last response}
|
|
75
|
+
*
|
|
76
|
+
* #### A type-safe approach using generics
|
|
65
77
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* }
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
80
|
+
* import { CallAnApi, LastResponse } from '@serenity-js/rest'
|
|
81
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
71
82
|
*
|
|
72
|
-
*
|
|
83
|
+
* interface Book {
|
|
84
|
+
* title: string;
|
|
85
|
+
* author: string;
|
|
86
|
+
* }
|
|
87
|
+
*
|
|
88
|
+
* await actorCalled('Apisitt')
|
|
89
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
90
|
+
* .attemptsTo(
|
|
73
91
|
* // ...
|
|
92
|
+
*
|
|
93
|
+
* // note body<T>() parameterised with type "Book"
|
|
74
94
|
* Ensure.that(LastResponse.body<Book>(), equals({
|
|
75
|
-
*
|
|
76
|
-
*
|
|
95
|
+
* title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
|
|
96
|
+
* author: 'Robert M. Pirsig',
|
|
77
97
|
* })),
|
|
78
|
-
*
|
|
98
|
+
* )
|
|
99
|
+
* ```
|
|
79
100
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
101
|
+
* ## A not type-safe approach using `any`
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
105
|
+
* import { CallAnApi, LastResponse } from '@serenity-js/rest'
|
|
106
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
107
|
+
*
|
|
108
|
+
* await actorCalled('Apisitt')
|
|
109
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
110
|
+
* .attemptsTo(
|
|
82
111
|
* // ...
|
|
112
|
+
*
|
|
113
|
+
* // note body<T>() parameterised with "any" or with no parameter is not type-safe!
|
|
83
114
|
* Ensure.that(LastResponse.body<any>(), equals({
|
|
84
|
-
*
|
|
85
|
-
*
|
|
115
|
+
* title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
|
|
116
|
+
* author: 'Robert M. Pirsig',
|
|
86
117
|
* })),
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @see {@link @serenity-js/core/lib/screenplay/questions~Property}
|
|
116
|
-
* @see {@link @serenity-js/core/lib/screenplay/questions~List}
|
|
118
|
+
* )
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* ## Iterating over the items in the response body
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
125
|
+
* import { CallAnApi, LastResponse } from '@serenity-js/rest'
|
|
126
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
127
|
+
*
|
|
128
|
+
* interface Product {
|
|
129
|
+
* id: number;
|
|
130
|
+
* name: string;
|
|
131
|
+
* }
|
|
132
|
+
*
|
|
133
|
+
* await actorCalled('Apisitt')
|
|
134
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
135
|
+
* .attemptsTo(
|
|
136
|
+
* Send.a(GetRequest.to(`/products`)),
|
|
137
|
+
* List.of<Product>(LastResponse.body<{ products: Product[] }>().products)
|
|
138
|
+
* .forEach(({ item, actor }) =>
|
|
139
|
+
* actor.attemptsTo(
|
|
140
|
+
* Send.a(GetRequest.to(`/products/${ item.id }`)),
|
|
141
|
+
* Ensure.that(LastResponse.body<Product>().id, equals(item.id)),
|
|
142
|
+
* )
|
|
143
|
+
* ),
|
|
144
|
+
* )
|
|
145
|
+
* ```
|
|
117
146
|
*/
|
|
118
147
|
static body<T = any>(): QuestionAdapter<T>;
|
|
119
148
|
/**
|
|
120
|
-
* @
|
|
121
|
-
*
|
|
149
|
+
* Retrieves a header of the {@apilink LastResponse|last response}, identified by `name`
|
|
150
|
+
*
|
|
151
|
+
* ## Asserting on a header
|
|
122
152
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
155
|
+
* import { CallAnApi, LastResponse } from '@serenity-js/rest'
|
|
156
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
157
|
+
*
|
|
158
|
+
* await actorCalled('Apisitt')
|
|
159
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
160
|
+
* .attemptsTo(
|
|
161
|
+
* Send.a(GetRequest.to(`/products`)),
|
|
162
|
+
* Ensure.that(LastResponse.header('Content-Type'), equals('application/json')),
|
|
163
|
+
* )
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @param name
|
|
125
167
|
*/
|
|
126
168
|
static header(name: string): QuestionAdapter<string>;
|
|
127
169
|
/**
|
|
128
|
-
* @
|
|
129
|
-
*
|
|
130
|
-
*
|
|
170
|
+
* Retrieves all the headers of the {@apilink LastResponse|last response}.
|
|
171
|
+
*
|
|
172
|
+
* ## Asserting on a header
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
176
|
+
* import { CallAnApi, LastResponse } from '@serenity-js/rest'
|
|
177
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
131
178
|
*
|
|
132
|
-
*
|
|
179
|
+
* await actorCalled('Apisitt')
|
|
180
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
181
|
+
* .attemptsTo(
|
|
182
|
+
* Send.a(GetRequest.to(`/products`)),
|
|
183
|
+
* Ensure.that(LastResponse.headers()['Content-Type'], equals('application/json')),
|
|
184
|
+
* )
|
|
185
|
+
* ```
|
|
133
186
|
*/
|
|
134
|
-
static headers(): QuestionAdapter<
|
|
187
|
+
static headers(): QuestionAdapter<RawAxiosResponseHeaders>;
|
|
135
188
|
}
|
|
189
|
+
//# sourceMappingURL=LastResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LastResponse.d.ts","sourceRoot":"","sources":["../../../src/screenplay/questions/LastResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AAIhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,qBAAa,YAAY;IAErB;;;;;OAKG;IACH,MAAM,CAAC,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC;IAMxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyEG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,GAAG,KAAK,eAAe,CAAC,CAAC,CAAC;IAM1C;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IAMpD;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,OAAO,IAAI,eAAe,CAAC,uBAAuB,CAAC;CAK7D"}
|