@serenity-js/rest 2.32.5 → 3.0.0-rc.3

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,55 @@
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.3](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.2...v3.0.0-rc.3) (2021-12-29)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **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)
12
+
13
+
14
+
15
+
16
+
17
+ # [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)
18
+
19
+ **Note:** Version bump only for package @serenity-js/rest
20
+
21
+
22
+
23
+
24
+
25
+ # [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)
26
+
27
+ **Note:** Version bump only for package @serenity-js/rest
28
+
29
+
30
+
31
+
32
+
33
+ # [3.0.0-rc.0](https://github.com/serenity-js/serenity-js/compare/v2.32.5...v3.0.0-rc.0) (2021-12-08)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * **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)
39
+
40
+
41
+ ### Features
42
+
43
+ * **core:** question.about produces "props" that proxy the methods of the underlying model ([f771872](https://github.com/serenity-js/serenity-js/commit/f771872c56b487e404002c3800fc8f3baaed804f))
44
+
45
+
46
+ ### BREAKING CHANGES
47
+
48
+ * **core:** Introduced @serenity-js/web - a shared library for Serenity/JS Web integration
49
+ modules such as @serenity-js/protractor and @serenity-js/webdriverio. Dropped support for Node 12.
50
+
51
+
52
+
53
+
54
+
6
55
  ## [2.32.5](https://github.com/serenity-js/serenity-js/compare/v2.32.4...v2.32.5) (2021-12-08)
7
56
 
8
57
  **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,SAAI,GAAJ,IAAI,CAAkB;QACtB,WAAM,GAAN,MAAM,CAAiC;QAG1D,IAAI,CAAC,OAAO,GAAG,GAAI,IAAI,CAAC,kBAAkB,EAAG,OAAQ,IAAA,cAAS,EAAC,GAAI,IAAI,CAAC,WAAY,EAAG,EAAE,CAAC;IAC9F,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,KAAuC;QAC9C,OAAO,OAAO,CAAC,GAAG,CAAC;YACf,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC7E,IAAI,CAAC,MAAM,CAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAQ,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACzE,IAAI,CAAC,IAAI,CAAQ,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAU,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;SAChF,CAAC;YACF,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAEzB,MAAM,CAAC,MAAM,CACT,EAAE,EAC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ACD,OAAO,GAAG,CAAC;QACf,CAAC,EAAE,EAAE,CAAC,CACT,CAAC;IACN,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,OAAe;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED;;;OAGG;IACK,cAAc;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;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 { Adapter, Question } 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(): Question<number> & Adapter<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>(): Question<T> & Adapter<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): Question<string> & Adapter<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(): Question<Record<string, string>> & Adapter<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
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"LastResponse.js","sourceRoot":"","sources":["../../../src/screenplay/questions/LastResponse.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAE7C,4CAAyC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAa,YAAY;IAErB;;;;;OAKG;IACH,MAAM,CAAC,MAAM;QACT,OAAO,eAAQ,CAAC,KAAK,CAAS,iCAAiC,EAAE,KAAK,CAAC,EAAE;YACrE,OAAO,qBAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuDG;IACH,MAAM,CAAC,IAAI;QACP,OAAO,eAAQ,CAAC,KAAK,CAAI,+BAA+B,EAAE,KAAK,CAAC,EAAE;YAC9D,OAAO,qBAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuDG;IACH,MAAM,CAAC,IAAI;QACP,OAAO,eAAQ,CAAC,KAAK,CAAI,+BAA+B,EAAE,KAAK,CAAC,EAAE;YAC9D,OAAO,qBAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,eAAe,CAAI,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAS,CAAC,CAAC;QAClF,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,IAAY;QACtB,OAAO,eAAQ,CAAC,KAAK,CAAS,QAAS,IAAK,+BAA+B,EAAE,KAAK,CAAC,EAAE;YACjF,OAAO,qBAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACnF,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,OAAO;QACV,OAAO,eAAQ,CAAC,KAAK,CAAyB,kCAAkC,EAAE,KAAK,CAAC,EAAE;YACtF,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.5",
3
+ "version": "3.0.0-rc.3",
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.5",
50
+ "@serenity-js/core": "3.0.0-rc.3",
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.5",
54
+ "@documentation/esdoc-template": "3.0.0",
55
+ "@integration/testing-tools": "3.0.0",
56
+ "@serenity-js/assertions": "3.0.0-rc.3",
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": "d6dce465bdafee180a8f2af2a27b676c1654c853"
86
+ "gitHead": "69da7444e581c457e29e87edcd910ec06a069338"
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 { Adapter, Question } 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,7 +62,7 @@ export class LastResponse {
37
62
  *
38
63
  * @returns {@serenity-js/core/lib/screenplay~Question<number>}
39
64
  */
40
- static status(): Question<number> {
65
+ static status(): Question<number> & Adapter<number> {
41
66
  return Question.about<number>(`the status of the last response`, actor => {
42
67
  return CallAnApi.as(actor).mapLastResponse(response => response.status);
43
68
  });
@@ -99,7 +124,7 @@ 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> {
127
+ static body<T = any>(): Question<T> & Adapter<T> {
103
128
  return Question.about<T>(`the body of the last response`, actor => {
104
129
  return CallAnApi.as(actor).mapLastResponse<T>(response => response.data as T);
105
130
  });
@@ -112,7 +137,7 @@ 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> {
140
+ static header(name: string): Question<string> & Adapter<string> {
116
141
  return Question.about<string>(`the '${ name }' header of the last response`, actor => {
117
142
  return CallAnApi.as(actor).mapLastResponse(response => response.headers[name]);
118
143
  });
@@ -125,7 +150,7 @@ 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>> {
153
+ static headers(): Question<Record<string, string>> & Adapter<Record<string, string>> {
129
154
  return Question.about<Record<string, string>>(`the headers or the last response`, actor => {
130
155
  return CallAnApi.as(actor).mapLastResponse(response => response.headers);
131
156
  });