@serenity-js/rest 2.32.7 → 3.0.0-rc.10

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 CHANGED
@@ -3,6 +3,242 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-rc.10](https://github.com/serenity-js/serenity-js/compare/v2.33.0...v3.0.0-rc.10) (2022-02-03)
7
+
8
+
9
+
10
+ # [3.0.0-rc.9](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.8...v3.0.0-rc.9) (2022-02-01)
11
+
12
+
13
+
14
+ # [3.0.0-rc.8](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.7...v3.0.0-rc.8) (2022-01-28)
15
+
16
+
17
+
18
+ # [3.0.0-rc.7](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.6...v3.0.0-rc.7) (2022-01-28)
19
+
20
+
21
+ ### Features
22
+
23
+ * **core:** replaced `Adapter` with `QuestionAdapter` and introduced `Optional` ([8d84ad3](https://github.com/serenity-js/serenity-js/commit/8d84ad3863e3c726533d0f21934fb1e2fa8b3022)), closes [#1103](https://github.com/serenity-js/serenity-js/issues/1103)
24
+
25
+
26
+
27
+ # [3.0.0-rc.6](https://github.com/serenity-js/serenity-js/compare/v2.32.7...v3.0.0-rc.6) (2022-01-10)
28
+
29
+
30
+
31
+ # [3.0.0-rc.5](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.4...v3.0.0-rc.5) (2022-01-07)
32
+
33
+
34
+
35
+ # [3.0.0-rc.4](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.3...v3.0.0-rc.4) (2021-12-30)
36
+
37
+
38
+ ### Bug Fixes
39
+
40
+ * **core:** you can now retrieve the .length property of an Array wrapped in an Adapter<Array> ([c36e210](https://github.com/serenity-js/serenity-js/commit/c36e210c024052b96ba47e9663c7098e269c5688))
41
+
42
+
43
+
44
+ # [3.0.0-rc.3](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.2...v3.0.0-rc.3) (2021-12-29)
45
+
46
+
47
+ ### Bug Fixes
48
+
49
+ * **rest:** corrected LastResponse to wrap .status(), .body(), .header() and .headers() in Adapters ([aab8e93](https://github.com/serenity-js/serenity-js/commit/aab8e93a19005710d9f333756cdae5aa21c31058)), closes [#1082](https://github.com/serenity-js/serenity-js/issues/1082)
50
+
51
+
52
+
53
+ # [3.0.0-rc.2](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.1...v3.0.0-rc.2) (2021-12-09)
54
+
55
+
56
+
57
+ # [3.0.0-rc.1](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.0...v3.0.0-rc.1) (2021-12-09)
58
+
59
+
60
+
61
+ # [3.0.0-rc.0](https://github.com/serenity-js/serenity-js/compare/v2.32.5...v3.0.0-rc.0) (2021-12-08)
62
+
63
+
64
+ ### Bug Fixes
65
+
66
+ * **core:** 3.0 RC ([469d54e](https://github.com/serenity-js/serenity-js/commit/469d54e4f81ef430566b93852e3174826f8ef672)), closes [#805](https://github.com/serenity-js/serenity-js/issues/805)
67
+
68
+
69
+ ### Features
70
+
71
+ * **core:** question.about produces "props" that proxy the methods of the underlying model ([f771872](https://github.com/serenity-js/serenity-js/commit/f771872c56b487e404002c3800fc8f3baaed804f))
72
+
73
+
74
+ ### BREAKING CHANGES
75
+
76
+ * **core:** Introduced @serenity-js/web - a shared library for Serenity/JS Web integration
77
+ modules such as @serenity-js/protractor and @serenity-js/webdriverio. Dropped support for Node 12.
78
+
79
+
80
+
81
+
82
+
83
+ # [3.0.0-rc.9](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.8...v3.0.0-rc.9) (2022-02-01)
84
+
85
+ **Note:** Version bump only for package @serenity-js/rest
86
+
87
+
88
+
89
+
90
+
91
+ # [3.0.0-rc.8](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.7...v3.0.0-rc.8) (2022-01-28)
92
+
93
+ **Note:** Version bump only for package @serenity-js/rest
94
+
95
+
96
+
97
+
98
+
99
+ # [3.0.0-rc.7](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.6...v3.0.0-rc.7) (2022-01-28)
100
+
101
+
102
+ ### Features
103
+
104
+ * **core:** replaced `Adapter` with `QuestionAdapter` and introduced `Optional` ([8d84ad3](https://github.com/serenity-js/serenity-js/commit/8d84ad3863e3c726533d0f21934fb1e2fa8b3022)), closes [#1103](https://github.com/serenity-js/serenity-js/issues/1103)
105
+
106
+
107
+
108
+
109
+
110
+ # [3.0.0-rc.6](https://github.com/serenity-js/serenity-js/compare/v2.32.7...v3.0.0-rc.6) (2022-01-10)
111
+
112
+
113
+
114
+ # [3.0.0-rc.5](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.4...v3.0.0-rc.5) (2022-01-07)
115
+
116
+
117
+
118
+ # [3.0.0-rc.4](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.3...v3.0.0-rc.4) (2021-12-30)
119
+
120
+
121
+ ### Bug Fixes
122
+
123
+ * **core:** you can now retrieve the .length property of an Array wrapped in an Adapter<Array> ([c36e210](https://github.com/serenity-js/serenity-js/commit/c36e210c024052b96ba47e9663c7098e269c5688))
124
+
125
+
126
+
127
+ # [3.0.0-rc.3](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.2...v3.0.0-rc.3) (2021-12-29)
128
+
129
+
130
+ ### Bug Fixes
131
+
132
+ * **rest:** corrected LastResponse to wrap .status(), .body(), .header() and .headers() in Adapters ([aab8e93](https://github.com/serenity-js/serenity-js/commit/aab8e93a19005710d9f333756cdae5aa21c31058)), closes [#1082](https://github.com/serenity-js/serenity-js/issues/1082)
133
+
134
+
135
+
136
+ # [3.0.0-rc.2](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.1...v3.0.0-rc.2) (2021-12-09)
137
+
138
+
139
+
140
+ # [3.0.0-rc.1](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.0...v3.0.0-rc.1) (2021-12-09)
141
+
142
+
143
+
144
+ # [3.0.0-rc.0](https://github.com/serenity-js/serenity-js/compare/v2.32.5...v3.0.0-rc.0) (2021-12-08)
145
+
146
+
147
+ ### Bug Fixes
148
+
149
+ * **core:** 3.0 RC ([469d54e](https://github.com/serenity-js/serenity-js/commit/469d54e4f81ef430566b93852e3174826f8ef672)), closes [#805](https://github.com/serenity-js/serenity-js/issues/805)
150
+
151
+
152
+ ### Features
153
+
154
+ * **core:** question.about produces "props" that proxy the methods of the underlying model ([f771872](https://github.com/serenity-js/serenity-js/commit/f771872c56b487e404002c3800fc8f3baaed804f))
155
+
156
+
157
+ ### BREAKING CHANGES
158
+
159
+ * **core:** Introduced @serenity-js/web - a shared library for Serenity/JS Web integration
160
+ modules such as @serenity-js/protractor and @serenity-js/webdriverio. Dropped support for Node 12.
161
+
162
+
163
+
164
+
165
+
166
+ # [3.0.0-rc.5](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.4...v3.0.0-rc.5) (2022-01-07)
167
+
168
+ **Note:** Version bump only for package @serenity-js/rest
169
+
170
+
171
+
172
+
173
+
174
+ # [3.0.0-rc.4](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.3...v3.0.0-rc.4) (2021-12-30)
175
+
176
+
177
+ ### Bug Fixes
178
+
179
+ * **core:** you can now retrieve the .length property of an Array wrapped in an Adapter<Array> ([c36e210](https://github.com/serenity-js/serenity-js/commit/c36e210c024052b96ba47e9663c7098e269c5688))
180
+
181
+
182
+
183
+
184
+
185
+ # [3.0.0-rc.3](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.2...v3.0.0-rc.3) (2021-12-29)
186
+
187
+
188
+ ### Bug Fixes
189
+
190
+ * **rest:** corrected LastResponse to wrap .status(), .body(), .header() and .headers() in Adapters ([aab8e93](https://github.com/serenity-js/serenity-js/commit/aab8e93a19005710d9f333756cdae5aa21c31058)), closes [#1082](https://github.com/serenity-js/serenity-js/issues/1082)
191
+
192
+
193
+
194
+
195
+
196
+ # [3.0.0-rc.2](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.1...v3.0.0-rc.2) (2021-12-09)
197
+
198
+ **Note:** Version bump only for package @serenity-js/rest
199
+
200
+
201
+
202
+
203
+
204
+ # [3.0.0-rc.1](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.0...v3.0.0-rc.1) (2021-12-09)
205
+
206
+ **Note:** Version bump only for package @serenity-js/rest
207
+
208
+
209
+
210
+
211
+
212
+ # [3.0.0-rc.0](https://github.com/serenity-js/serenity-js/compare/v2.32.5...v3.0.0-rc.0) (2021-12-08)
213
+
214
+
215
+ ### Bug Fixes
216
+
217
+ * **core:** 3.0 RC ([469d54e](https://github.com/serenity-js/serenity-js/commit/469d54e4f81ef430566b93852e3174826f8ef672)), closes [#805](https://github.com/serenity-js/serenity-js/issues/805)
218
+
219
+
220
+ ### Features
221
+
222
+ * **core:** question.about produces "props" that proxy the methods of the underlying model ([f771872](https://github.com/serenity-js/serenity-js/commit/f771872c56b487e404002c3800fc8f3baaed804f))
223
+
224
+
225
+ ### BREAKING CHANGES
226
+
227
+ * **core:** Introduced @serenity-js/web - a shared library for Serenity/JS Web integration
228
+ modules such as @serenity-js/protractor and @serenity-js/webdriverio. Dropped support for Node 12.
229
+
230
+
231
+
232
+
233
+
234
+ # [2.33.0](https://github.com/serenity-js/serenity-js/compare/v2.32.7...v2.33.0) (2022-02-03)
235
+
236
+ **Note:** Version bump only for package @serenity-js/rest
237
+
238
+
239
+
240
+
241
+
6
242
  ## [2.32.7](https://github.com/serenity-js/serenity-js/compare/v2.32.6...v2.32.7) (2022-01-10)
7
243
 
8
244
  **Note:** Version bump only for package @serenity-js/rest
@@ -12,6 +12,7 @@ export declare abstract class HTTPRequest extends Question<Promise<AxiosRequestC
12
12
  protected readonly resourceUri?: Answerable<string>;
13
13
  protected readonly data?: Answerable<any>;
14
14
  protected readonly config?: Answerable<AxiosRequestConfig>;
15
+ private subject;
15
16
  /**
16
17
  * @protected
17
18
  *
@@ -34,6 +35,15 @@ export declare abstract class HTTPRequest extends Question<Promise<AxiosRequestC
34
35
  * @returns {Promise<AxiosRequestConfig>}
35
36
  */
36
37
  answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<AxiosRequestConfig>;
38
+ /**
39
+ * @desc
40
+ * Changes the description of this question's subject.
41
+ *
42
+ * @param {string} subject
43
+ * @returns {Question<T>}
44
+ */
45
+ describedAs(subject: string): this;
46
+ toString(): string;
37
47
  /**
38
48
  * Determines the request method based on the name of the request class.
39
49
  * For example: GetRequest => GET, PostRequest => POST, etc.
@@ -26,7 +26,7 @@ class HTTPRequest extends core_1.Question {
26
26
  * provided when the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} is instantiated
27
27
  */
28
28
  constructor(resourceUri, data, config) {
29
- super('');
29
+ super();
30
30
  this.resourceUri = resourceUri;
31
31
  this.data = data;
32
32
  this.config = config;
@@ -55,6 +55,20 @@ class HTTPRequest extends core_1.Question {
55
55
  return acc;
56
56
  }, {}));
57
57
  }
58
+ /**
59
+ * @desc
60
+ * Changes the description of this question's subject.
61
+ *
62
+ * @param {string} subject
63
+ * @returns {Question<T>}
64
+ */
65
+ describedAs(subject) {
66
+ this.subject = subject;
67
+ return this;
68
+ }
69
+ toString() {
70
+ return this.subject;
71
+ }
58
72
  /**
59
73
  * Determines the request method based on the name of the request class.
60
74
  * For example: GetRequest => GET, PostRequest => POST, etc.
@@ -1 +1 @@
1
- {"version":3,"file":"HTTPRequest.js","sourceRoot":"","sources":["../../src/model/HTTPRequest.ts"],"names":[],"mappings":";;;AAAA,4CAA0F;AAC1F,iDAAqD;AAGrD;;;;;;;GAOG;AACH,MAAsB,WAAY,SAAQ,eAAqC;IAE3E;;;;;;;;;;;;OAYG;IACH,YACuB,WAAgC,EAChC,IAAsB,EACtB,MAAuC;QAE1D,KAAK,CAAC,EAAE,CAAC,CAAC;QAJS,gBAAW,GAAX,WAAW,CAAqB;QAChC,SA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AC;IACtE,CAAC;IAED;;OAEG;IACK,kBAAkB;QACtB,MACI,MAAM,GAAG,CAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAE,EACpC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QAEnC,OAAO,GAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAI,IAAK,MAAO,UAAU,CAAC;IAC9E,CAAC;CACJ;AA7FD,kCA6FC"}
@@ -1,4 +1,4 @@
1
- import { Question } from '@serenity-js/core';
1
+ import { QuestionAdapter } from '@serenity-js/core';
2
2
  /**
3
3
  * @desc
4
4
  * Provides access to the properties of the last {@link AxiosResponse} object,
@@ -25,6 +25,31 @@ import { Question } from '@serenity-js/core';
25
25
  * author: 'Robert M. Pirsig',
26
26
  * })),
27
27
  * );
28
+ *
29
+ * @example <caption>Use Serenity/JS adapters to navigate complex response objects</caption>
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';
33
+ *
34
+ * interface Developer {
35
+ * name: string;
36
+ * id: string;
37
+ * projects: Project[];
38
+ * }
39
+ *
40
+ * interface Project {
41
+ * name: string;
42
+ * repoUrl: string;
43
+ * }
44
+ *
45
+ * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
46
+ *
47
+ * actor.attemptsTo(
48
+ * Send.a(GetRequest.to('/developers/jan-molak')),
49
+ * Ensure.that(LastResponse.status(), equals(200)),
50
+ * Ensure.that(LastResponse.body<Developer>().name, equals('Jan Molak')),
51
+ * Ensure.that(LastResponse.body<Developer>().projects[0].name, equals('Serenity/JS')),
52
+ * );
28
53
  */
29
54
  export declare class LastResponse {
30
55
  /**
@@ -33,7 +58,7 @@ export declare class LastResponse {
33
58
  *
34
59
  * @returns {@serenity-js/core/lib/screenplay~Question<number>}
35
60
  */
36
- static status(): Question<number>;
61
+ static status(): QuestionAdapter<number>;
37
62
  /**
38
63
  * @desc
39
64
  * Enables asserting on the {@link LastResponse} body
@@ -90,7 +115,7 @@ export declare class LastResponse {
90
115
  * @see {@link @serenity-js/core/lib/screenplay/questions~Property}
91
116
  * @see {@link @serenity-js/core/lib/screenplay/questions~List}
92
117
  */
93
- static body<T = any>(): Question<T>;
118
+ static body<T = any>(): QuestionAdapter<T>;
94
119
  /**
95
120
  * @desc
96
121
  * Enables asserting on one of the {@link LastResponse}'s headers
@@ -98,7 +123,7 @@ export declare class LastResponse {
98
123
  * @param {string} name
99
124
  * @returns {@serenity-js/core/lib/screenplay~Question<string>}
100
125
  */
101
- static header(name: string): Question<string>;
126
+ static header(name: string): QuestionAdapter<string>;
102
127
  /**
103
128
  * @desc
104
129
  * Enables asserting on all of the {@link LastResponse}'s headers,
@@ -106,5 +131,5 @@ export declare class LastResponse {
106
131
  *
107
132
  * @returns {@serenity-js/core/lib/screenplay~Question<Record<string, string>>}
108
133
  */
109
- static headers(): Question<Record<string, string>>;
134
+ static headers(): QuestionAdapter<Record<string, string>>;
110
135
  }
@@ -29,6 +29,31 @@ const abilities_1 = require("../abilities");
29
29
  * author: 'Robert M. Pirsig',
30
30
  * })),
31
31
  * );
32
+ *
33
+ * @example <caption>Use Serenity/JS adapters to navigate complex response objects</caption>
34
+ * import { Actor } from '@serenity-js/core';
35
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
36
+ * import { Ensure, equals } from '@serenity-js/assertions';
37
+ *
38
+ * interface Developer {
39
+ * name: string;
40
+ * id: string;
41
+ * projects: Project[];
42
+ * }
43
+ *
44
+ * interface Project {
45
+ * name: string;
46
+ * repoUrl: string;
47
+ * }
48
+ *
49
+ * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
50
+ *
51
+ * actor.attemptsTo(
52
+ * Send.a(GetRequest.to('/developers/jan-molak')),
53
+ * Ensure.that(LastResponse.status(), equals(200)),
54
+ * Ensure.that(LastResponse.body<Developer>().name, equals('Jan Molak')),
55
+ * Ensure.that(LastResponse.body<Developer>().projects[0].name, equals('Serenity/JS')),
56
+ * );
32
57
  */
33
58
  class LastResponse {
34
59
  /**
@@ -38,7 +63,7 @@ class LastResponse {
38
63
  * @returns {@serenity-js/core/lib/screenplay~Question<number>}
39
64
  */
40
65
  static status() {
41
- return core_1.Question.about(`the status of the last response`, actor => {
66
+ return core_1.Question.about(`the status of the last response`, async (actor) => {
42
67
  return abilities_1.CallAnApi.as(actor).mapLastResponse(response => response.status);
43
68
  });
44
69
  }
@@ -99,7 +124,7 @@ class LastResponse {
99
124
  * @see {@link @serenity-js/core/lib/screenplay/questions~List}
100
125
  */
101
126
  static body() {
102
- return core_1.Question.about(`the body of the last response`, actor => {
127
+ return core_1.Question.about(`the body of the last response`, async (actor) => {
103
128
  return abilities_1.CallAnApi.as(actor).mapLastResponse(response => response.data);
104
129
  });
105
130
  }
@@ -111,7 +136,7 @@ class LastResponse {
111
136
  * @returns {@serenity-js/core/lib/screenplay~Question<string>}
112
137
  */
113
138
  static header(name) {
114
- return core_1.Question.about(`the '${name}' header of the last response`, actor => {
139
+ return core_1.Question.about(`the '${name}' header of the last response`, async (actor) => {
115
140
  return abilities_1.CallAnApi.as(actor).mapLastResponse(response => response.headers[name]);
116
141
  });
117
142
  }
@@ -123,7 +148,7 @@ class LastResponse {
123
148
  * @returns {@serenity-js/core/lib/screenplay~Question<Record<string, string>>}
124
149
  */
125
150
  static headers() {
126
- return core_1.Question.about(`the headers or the last response`, actor => {
151
+ return core_1.Question.about(`the headers or the last response`, async (actor) => {
127
152
  return abilities_1.CallAnApi.as(actor).mapLastResponse(response => response.headers);
128
153
  });
129
154
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LastResponse.js","sourceRoot":"","sources":["../../../src/screenplay/questions/LastResponse.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;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O;QACV,OAAO,eAAQ,CAAC,KAAK,CAAyB,kCAAkC,EAAE,KAAK,EAAC,KAAK,EAAC,EAAE;YAC5F,OAAO,qBAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AArGD,oCAqGC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serenity-js/rest",
3
- "version": "2.32.7",
3
+ "version": "3.0.0-rc.10",
4
4
  "description": "Test REST APIs with Serenity/JS",
5
5
  "author": {
6
6
  "name": "Jan Molak",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "clean": "rimraf .nyc_output lib target",
32
- "lint": "eslint --ext ts --config ../../.eslintrc.js .",
32
+ "lint": "eslint --ext ts --config ../../.eslintrc.yml .",
33
33
  "lint:fix": "npm run lint -- --fix",
34
34
  "test": "nyc --report-dir ../../target/coverage/rest mocha --config ../../.mocharc.yml 'spec/**/*.spec.*'",
35
35
  "compile": "tsc --project tsconfig.json",
@@ -43,17 +43,17 @@
43
43
  "url": "https://github.com/serenity-js/serenity-js/issues"
44
44
  },
45
45
  "engines": {
46
- "node": "^12 || ^14 || ^16",
46
+ "node": "^14 || ^16",
47
47
  "npm": "^6 || ^7 || ^8"
48
48
  },
49
49
  "dependencies": {
50
- "@serenity-js/core": "2.32.7",
50
+ "@serenity-js/core": "3.0.0-rc.10",
51
51
  "axios": "^0.21.4"
52
52
  },
53
53
  "devDependencies": {
54
- "@documentation/esdoc-template": "2.0.0",
55
- "@integration/testing-tools": "2.0.0",
56
- "@serenity-js/assertions": "2.32.7",
54
+ "@documentation/esdoc-template": "3.0.0",
55
+ "@integration/testing-tools": "3.0.0",
56
+ "@serenity-js/assertions": "3.0.0-rc.10",
57
57
  "@types/chai": "^4.3.0",
58
58
  "@types/mocha": "^9.0.0",
59
59
  "axios-mock-adapter": "^1.20.0",
@@ -83,5 +83,5 @@
83
83
  "cache": true,
84
84
  "all": true
85
85
  },
86
- "gitHead": "93f54f9919b74d66f10cdd7acbadba5927d728f7"
86
+ "gitHead": "7e8570d412348980c22a6e189ebc4c4f0157919d"
87
87
  }
@@ -12,6 +12,8 @@ import { AxiosRequestConfig } from 'axios';
12
12
  */
13
13
  export abstract class HTTPRequest extends Question<Promise<AxiosRequestConfig>> {
14
14
 
15
+ private subject: string;
16
+
15
17
  /**
16
18
  * @protected
17
19
  *
@@ -30,7 +32,7 @@ export abstract class HTTPRequest extends Question<Promise<AxiosRequestConfig>>
30
32
  protected readonly data?: Answerable<any>,
31
33
  protected readonly config?: Answerable<AxiosRequestConfig>,
32
34
  ) {
33
- super('');
35
+ super();
34
36
  this.subject = `${ this.requestDescription() } to ${ formatted `${ this.resourceUri }` }`;
35
37
  }
36
38
 
@@ -67,6 +69,22 @@ export abstract class HTTPRequest extends Question<Promise<AxiosRequestConfig>>
67
69
  );
68
70
  }
69
71
 
72
+ /**
73
+ * @desc
74
+ * Changes the description of this question's subject.
75
+ *
76
+ * @param {string} subject
77
+ * @returns {Question<T>}
78
+ */
79
+ describedAs(subject: string): this {
80
+ this.subject = subject;
81
+ return this;
82
+ }
83
+
84
+ toString(): string {
85
+ return this.subject;
86
+ }
87
+
70
88
  /**
71
89
  * Determines the request method based on the name of the request class.
72
90
  * For example: GetRequest => GET, PostRequest => POST, etc.
@@ -1,4 +1,4 @@
1
- import { Question } from '@serenity-js/core';
1
+ import { Question, QuestionAdapter } from '@serenity-js/core';
2
2
 
3
3
  import { CallAnApi } from '../abilities';
4
4
 
@@ -28,6 +28,31 @@ import { CallAnApi } from '../abilities';
28
28
  * author: 'Robert M. Pirsig',
29
29
  * })),
30
30
  * );
31
+ *
32
+ * @example <caption>Use Serenity/JS adapters to navigate complex response objects</caption>
33
+ * import { Actor } from '@serenity-js/core';
34
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
35
+ * import { Ensure, equals } from '@serenity-js/assertions';
36
+ *
37
+ * interface Developer {
38
+ * name: string;
39
+ * id: string;
40
+ * projects: Project[];
41
+ * }
42
+ *
43
+ * interface Project {
44
+ * name: string;
45
+ * repoUrl: string;
46
+ * }
47
+ *
48
+ * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
49
+ *
50
+ * actor.attemptsTo(
51
+ * Send.a(GetRequest.to('/developers/jan-molak')),
52
+ * Ensure.that(LastResponse.status(), equals(200)),
53
+ * Ensure.that(LastResponse.body<Developer>().name, equals('Jan Molak')),
54
+ * Ensure.that(LastResponse.body<Developer>().projects[0].name, equals('Serenity/JS')),
55
+ * );
31
56
  */
32
57
  export class LastResponse {
33
58
 
@@ -37,8 +62,8 @@ export class LastResponse {
37
62
  *
38
63
  * @returns {@serenity-js/core/lib/screenplay~Question<number>}
39
64
  */
40
- static status(): Question<number> {
41
- return Question.about<number>(`the status of the last response`, actor => {
65
+ static status(): QuestionAdapter<number> {
66
+ return Question.about<number>(`the status of the last response`, async actor => {
42
67
  return CallAnApi.as(actor).mapLastResponse(response => response.status);
43
68
  });
44
69
  }
@@ -99,8 +124,8 @@ export class LastResponse {
99
124
  * @see {@link @serenity-js/core/lib/screenplay/questions~Property}
100
125
  * @see {@link @serenity-js/core/lib/screenplay/questions~List}
101
126
  */
102
- static body<T = any>(): Question<T> {
103
- return Question.about<T>(`the body of the last response`, actor => {
127
+ static body<T = any>(): QuestionAdapter<T> {
128
+ return Question.about<T>(`the body of the last response`, async actor => {
104
129
  return CallAnApi.as(actor).mapLastResponse<T>(response => response.data as T);
105
130
  });
106
131
  }
@@ -112,8 +137,8 @@ export class LastResponse {
112
137
  * @param {string} name
113
138
  * @returns {@serenity-js/core/lib/screenplay~Question<string>}
114
139
  */
115
- static header(name: string): Question<string> {
116
- return Question.about<string>(`the '${ name }' header of the last response`, actor => {
140
+ static header(name: string): QuestionAdapter<string> {
141
+ return Question.about<string>(`the '${ name }' header of the last response`, async actor => {
117
142
  return CallAnApi.as(actor).mapLastResponse(response => response.headers[name]);
118
143
  });
119
144
  }
@@ -125,8 +150,8 @@ export class LastResponse {
125
150
  *
126
151
  * @returns {@serenity-js/core/lib/screenplay~Question<Record<string, string>>}
127
152
  */
128
- static headers(): Question<Record<string, string>> {
129
- return Question.about<Record<string, string>>(`the headers or the last response`, actor => {
153
+ static headers(): QuestionAdapter<Record<string, string>> {
154
+ return Question.about<Record<string, string>>(`the headers or the last response`, async actor => {
130
155
  return CallAnApi.as(actor).mapLastResponse(response => response.headers);
131
156
  });
132
157
  }