@serenity-js/rest 3.0.0-rc.9 → 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 -1859
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screenplay/abilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,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];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/screenplay/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
package/lib/screenplay/index.js
CHANGED
|
@@ -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];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/screenplay/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/screenplay/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,iDAA+B;AAC/B,8CAA4B"}
|
|
@@ -1,112 +1,113 @@
|
|
|
1
1
|
import { Answerable, Interaction } from '@serenity-js/core';
|
|
2
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
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
3
|
+
* Changes configuration of the {@apilink Ability|ability} to {@apilink CallAnApi}
|
|
4
|
+
* that the {@apilink Actor|actor} executing this {@apilink Interaction|interaction} has been configured with.
|
|
5
|
+
*
|
|
6
|
+
* ## Changing API URL for all subsequent requests
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
10
|
+
* import { By Navigate, PageElement, Text } from '@serenity-js/web';
|
|
11
|
+
* import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
12
|
+
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
13
|
+
*
|
|
14
|
+
* import * as axios from 'axios';
|
|
15
|
+
*
|
|
16
|
+
* // Let's imagine that the website under test displays
|
|
17
|
+
* // a dynamically generated API URL that we would like to use
|
|
18
|
+
* const ApiDetailsWidget = {
|
|
19
|
+
* url: () => PageElement.located(By.id('api-url')).describedAs('API URL'),
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* await actorCalled('Apisitt')
|
|
23
|
+
* .whoCan(
|
|
24
|
+
* BrowseTheWeb.using(protractor.browser),
|
|
25
|
+
*
|
|
26
|
+
* // Note: no default base URL is given when the axios instance is created
|
|
27
|
+
* CallAnApi.using(axios.create()),
|
|
28
|
+
* )
|
|
29
|
+
* .attemptsTo(
|
|
30
|
+
* Navigate.to('/profile'),
|
|
31
|
+
*
|
|
32
|
+
* // We change the API URL based on the text displayed in the widget
|
|
33
|
+
* // (although we could change it to some arbitrary string too).
|
|
34
|
+
* ChangeApiConfig.setUrlTo(Text.of(ApiDetailsWidget.url())),
|
|
35
|
+
*
|
|
36
|
+
* // Any subsequent request will be sent to the newly set URL
|
|
37
|
+
* Send.a(GetRequest.to('/projects')),
|
|
38
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
39
|
+
* )
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ## Changing API port for all subsequent requests
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
46
|
+
* import { LocalServer, ManageALocalServer, StartLocalServer } from '@serenity-js/local-server'
|
|
47
|
+
* import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
48
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
49
|
+
*
|
|
50
|
+
* await actorCalled('Apisitt')
|
|
51
|
+
* .whoCan(
|
|
52
|
+
* ManageALocalServer.runningAHttpListener(someServer),
|
|
53
|
+
* CallAnApi.at('http://localhost'),
|
|
54
|
+
* )
|
|
55
|
+
* .attemptsTo(
|
|
56
|
+
* StartALocalServer.onRandomPort(),
|
|
57
|
+
* ChangeApiConfig.setPortTo(LocalServer.port()),
|
|
58
|
+
* Send.a(GetRequest.to('/api')),
|
|
59
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
60
|
+
* )
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* ## Setting a header for all subsequent requests
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { actorCalled, Question } from '@serenity-js/core'
|
|
67
|
+
* import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
68
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
69
|
+
*
|
|
70
|
+
* // A sample Question reading a Node process environment variable
|
|
71
|
+
* const EnvVar = (var_name: string) =>
|
|
72
|
+
* Question.about(`${ name } environment variable`, actor => process.env[var_name]);
|
|
73
|
+
*
|
|
74
|
+
* await actorCalled('Apisitt')
|
|
75
|
+
* .whoCan(
|
|
76
|
+
* CallAnApi.at('http://localhost'),
|
|
77
|
+
* )
|
|
78
|
+
* .attemptsTo(
|
|
79
|
+
* ChangeApiConfig.setHeader('Authorization', EnvVar('TOKEN')),
|
|
80
|
+
* Send.a(GetRequest.to('/api')),
|
|
81
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
82
|
+
* )
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @group Activities
|
|
78
86
|
*/
|
|
79
87
|
export declare class ChangeApiConfig {
|
|
80
88
|
/**
|
|
81
|
-
* @
|
|
82
|
-
*
|
|
83
|
-
* to change the base URL of their {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability}
|
|
89
|
+
* Instructs the {@apilink Actor|actor} to change the base URL
|
|
90
|
+
* of their {@apilink Ability|ability} to {@apilink CallAnApi}
|
|
84
91
|
*
|
|
85
|
-
* @param
|
|
86
|
-
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
92
|
+
* @param newApiUrl
|
|
87
93
|
*/
|
|
88
94
|
static setUrlTo(newApiUrl: Answerable<string>): Interaction;
|
|
89
95
|
/**
|
|
90
|
-
* @
|
|
91
|
-
*
|
|
92
|
-
* to change the port configured in the base URL of their {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability}
|
|
96
|
+
* Instructs the {@apilink Actor|actor} to change the port configured in the base URL
|
|
97
|
+
* of their {@apilink Ability|ability} to {@apilink CallAnApi}
|
|
93
98
|
*
|
|
94
|
-
* @param
|
|
95
|
-
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
99
|
+
* @param newApiPort
|
|
96
100
|
*/
|
|
97
101
|
static setPortTo(newApiPort: Answerable<number>): Interaction;
|
|
98
102
|
/**
|
|
99
|
-
* @
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* and set a HTTP request header for any subsequent {@link HTTPRequest}
|
|
104
|
-
* issued via {@link Send}.
|
|
105
|
-
*
|
|
106
|
-
* @param {@serenity-js/core/lib/screenplay~Answerable<string>} name
|
|
107
|
-
* @param {@serenity-js/core/lib/screenplay~Answerable<string>} value
|
|
103
|
+
* Instructs the {@apilink Actor|actor} to change the configuration of the {@apilink AxiosInstance}
|
|
104
|
+
* used by their {@apilink Ability|ability} to {@apilink CallAnApi}
|
|
105
|
+
* and set an HTTP request header for any subsequent {@apilink HTTPRequest|HTTPRequests}
|
|
106
|
+
* issued via {@apilink Send}.
|
|
108
107
|
*
|
|
109
|
-
* @
|
|
108
|
+
* @param name
|
|
109
|
+
* @param value
|
|
110
110
|
*/
|
|
111
111
|
static setHeader(name: Answerable<string>, value: Answerable<string>): Interaction;
|
|
112
112
|
}
|
|
113
|
+
//# sourceMappingURL=ChangeApiConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChangeApiConfig.d.ts","sourceRoot":"","sources":["../../../src/screenplay/interactions/ChangeApiConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0C,WAAW,EAA6B,MAAM,mBAAmB,CAAC;AAK/H;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AACH,qBAAa,eAAe;IAExB;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,WAAW;IAI3D;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,WAAW;IAI7D;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,WAAW;CAGrF"}
|
|
@@ -5,117 +5,117 @@ const core_1 = require("@serenity-js/core");
|
|
|
5
5
|
const url_1 = require("url");
|
|
6
6
|
const abilities_1 = require("../abilities");
|
|
7
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
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
8
|
+
* Changes configuration of the {@apilink Ability|ability} to {@apilink CallAnApi}
|
|
9
|
+
* that the {@apilink Actor|actor} executing this {@apilink Interaction|interaction} has been configured with.
|
|
10
|
+
*
|
|
11
|
+
* ## Changing API URL for all subsequent requests
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
15
|
+
* import { By Navigate, PageElement, Text } from '@serenity-js/web';
|
|
16
|
+
* import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
17
|
+
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
18
|
+
*
|
|
19
|
+
* import * as axios from 'axios';
|
|
20
|
+
*
|
|
21
|
+
* // Let's imagine that the website under test displays
|
|
22
|
+
* // a dynamically generated API URL that we would like to use
|
|
23
|
+
* const ApiDetailsWidget = {
|
|
24
|
+
* url: () => PageElement.located(By.id('api-url')).describedAs('API URL'),
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* await actorCalled('Apisitt')
|
|
28
|
+
* .whoCan(
|
|
29
|
+
* BrowseTheWeb.using(protractor.browser),
|
|
30
|
+
*
|
|
31
|
+
* // Note: no default base URL is given when the axios instance is created
|
|
32
|
+
* CallAnApi.using(axios.create()),
|
|
33
|
+
* )
|
|
34
|
+
* .attemptsTo(
|
|
35
|
+
* Navigate.to('/profile'),
|
|
36
|
+
*
|
|
37
|
+
* // We change the API URL based on the text displayed in the widget
|
|
38
|
+
* // (although we could change it to some arbitrary string too).
|
|
39
|
+
* ChangeApiConfig.setUrlTo(Text.of(ApiDetailsWidget.url())),
|
|
40
|
+
*
|
|
41
|
+
* // Any subsequent request will be sent to the newly set URL
|
|
42
|
+
* Send.a(GetRequest.to('/projects')),
|
|
43
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
44
|
+
* )
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* ## Changing API port for all subsequent requests
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
51
|
+
* import { LocalServer, ManageALocalServer, StartLocalServer } from '@serenity-js/local-server'
|
|
52
|
+
* import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
53
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
54
|
+
*
|
|
55
|
+
* await actorCalled('Apisitt')
|
|
56
|
+
* .whoCan(
|
|
57
|
+
* ManageALocalServer.runningAHttpListener(someServer),
|
|
58
|
+
* CallAnApi.at('http://localhost'),
|
|
59
|
+
* )
|
|
60
|
+
* .attemptsTo(
|
|
61
|
+
* StartALocalServer.onRandomPort(),
|
|
62
|
+
* ChangeApiConfig.setPortTo(LocalServer.port()),
|
|
63
|
+
* Send.a(GetRequest.to('/api')),
|
|
64
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
65
|
+
* )
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* ## Setting a header for all subsequent requests
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { actorCalled, Question } from '@serenity-js/core'
|
|
72
|
+
* import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
73
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
74
|
+
*
|
|
75
|
+
* // A sample Question reading a Node process environment variable
|
|
76
|
+
* const EnvVar = (var_name: string) =>
|
|
77
|
+
* Question.about(`${ name } environment variable`, actor => process.env[var_name]);
|
|
78
|
+
*
|
|
79
|
+
* await actorCalled('Apisitt')
|
|
80
|
+
* .whoCan(
|
|
81
|
+
* CallAnApi.at('http://localhost'),
|
|
82
|
+
* )
|
|
83
|
+
* .attemptsTo(
|
|
84
|
+
* ChangeApiConfig.setHeader('Authorization', EnvVar('TOKEN')),
|
|
85
|
+
* Send.a(GetRequest.to('/api')),
|
|
86
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
87
|
+
* )
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @group Activities
|
|
83
91
|
*/
|
|
84
92
|
class ChangeApiConfig {
|
|
85
93
|
/**
|
|
86
|
-
* @
|
|
87
|
-
*
|
|
88
|
-
* to change the base URL of their {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability}
|
|
94
|
+
* Instructs the {@apilink Actor|actor} to change the base URL
|
|
95
|
+
* of their {@apilink Ability|ability} to {@apilink CallAnApi}
|
|
89
96
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
97
|
+
* @param newApiUrl
|
|
92
98
|
*/
|
|
93
99
|
static setUrlTo(newApiUrl) {
|
|
94
100
|
return new ChangeApiConfigSetUrl(newApiUrl);
|
|
95
101
|
}
|
|
96
102
|
/**
|
|
97
|
-
* @
|
|
98
|
-
*
|
|
99
|
-
* to change the port configured in the base URL of their {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability}
|
|
103
|
+
* Instructs the {@apilink Actor|actor} to change the port configured in the base URL
|
|
104
|
+
* of their {@apilink Ability|ability} to {@apilink CallAnApi}
|
|
100
105
|
*
|
|
101
|
-
* @param
|
|
102
|
-
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
106
|
+
* @param newApiPort
|
|
103
107
|
*/
|
|
104
108
|
static setPortTo(newApiPort) {
|
|
105
109
|
return new ChangeApiConfigSetPort(newApiPort);
|
|
106
110
|
}
|
|
107
111
|
/**
|
|
108
|
-
* @
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* and set a HTTP request header for any subsequent {@link HTTPRequest}
|
|
113
|
-
* issued via {@link Send}.
|
|
112
|
+
* Instructs the {@apilink Actor|actor} to change the configuration of the {@apilink AxiosInstance}
|
|
113
|
+
* used by their {@apilink Ability|ability} to {@apilink CallAnApi}
|
|
114
|
+
* and set an HTTP request header for any subsequent {@apilink HTTPRequest|HTTPRequests}
|
|
115
|
+
* issued via {@apilink Send}.
|
|
114
116
|
*
|
|
115
|
-
* @param
|
|
116
|
-
* @param
|
|
117
|
-
*
|
|
118
|
-
* @returns {@serenity-js/core/lib/screenplay~Interaction}
|
|
117
|
+
* @param name
|
|
118
|
+
* @param value
|
|
119
119
|
*/
|
|
120
120
|
static setHeader(name, value) {
|
|
121
121
|
return new ChangeApiConfigSetHeader(name, value);
|
|
@@ -127,23 +127,20 @@ exports.ChangeApiConfig = ChangeApiConfig;
|
|
|
127
127
|
*/
|
|
128
128
|
class ChangeApiConfigSetUrl extends core_1.Interaction {
|
|
129
129
|
constructor(newApiUrl) {
|
|
130
|
-
super();
|
|
130
|
+
super((0, core_1.d) `#actor changes API url configuration to ${newApiUrl}`);
|
|
131
131
|
this.newApiUrl = newApiUrl;
|
|
132
132
|
}
|
|
133
133
|
performAs(actor) {
|
|
134
134
|
return actor.answer(this.newApiUrl)
|
|
135
135
|
.then(newApiUrl => abilities_1.CallAnApi.as(actor).modifyConfig(config => config.baseURL = newApiUrl));
|
|
136
136
|
}
|
|
137
|
-
toString() {
|
|
138
|
-
return `#actor changes API URL configuration to ${this.newApiUrl}`;
|
|
139
|
-
}
|
|
140
137
|
}
|
|
141
138
|
/**
|
|
142
139
|
* @package
|
|
143
140
|
*/
|
|
144
141
|
class ChangeApiConfigSetPort extends core_1.Interaction {
|
|
145
142
|
constructor(newPort) {
|
|
146
|
-
super();
|
|
143
|
+
super(`#actor changes API port configuration to ${newPort}`);
|
|
147
144
|
this.newPort = newPort;
|
|
148
145
|
}
|
|
149
146
|
performAs(actor) {
|
|
@@ -162,9 +159,6 @@ class ChangeApiConfigSetPort extends core_1.Interaction {
|
|
|
162
159
|
}
|
|
163
160
|
}));
|
|
164
161
|
}
|
|
165
|
-
toString() {
|
|
166
|
-
return `#actor changes API port configuration to ${this.newPort}`;
|
|
167
|
-
}
|
|
168
162
|
}
|
|
169
163
|
/**
|
|
170
164
|
* @package
|
|
@@ -173,7 +167,7 @@ class ChangeApiConfigSetPort extends core_1.Interaction {
|
|
|
173
167
|
*/
|
|
174
168
|
class ChangeApiConfigSetHeader extends core_1.Interaction {
|
|
175
169
|
constructor(name, value) {
|
|
176
|
-
super();
|
|
170
|
+
super(`#actor changes API URL and sets header "${name}" to "${value}"`);
|
|
177
171
|
this.name = name;
|
|
178
172
|
this.value = value;
|
|
179
173
|
}
|
|
@@ -193,8 +187,5 @@ class ChangeApiConfigSetHeader extends core_1.Interaction {
|
|
|
193
187
|
});
|
|
194
188
|
});
|
|
195
189
|
}
|
|
196
|
-
toString() {
|
|
197
|
-
return `#actor changes API URL and sets header "${this.name}" to "${this.value}"`;
|
|
198
|
-
}
|
|
199
190
|
}
|
|
200
191
|
//# sourceMappingURL=ChangeApiConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChangeApiConfig.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/ChangeApiConfig.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ChangeApiConfig.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/ChangeApiConfig.ts"],"names":[],"mappings":";;;AAAA,4CAA+H;AAC/H,6BAA0B;AAE1B,4CAAyC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AACH,MAAa,eAAe;IAExB;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,SAA6B;QACzC,OAAO,IAAI,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAChD,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