@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
package/README.md
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
# Serenity/JS
|
|
2
2
|
|
|
3
|
-
[Serenity/JS](https://serenity-js
|
|
4
|
-
|
|
3
|
+
[](https://www.linkedin.com/company/serenity-js)
|
|
4
|
+
[](https://www.youtube.com/@serenity-js)
|
|
5
|
+
[](https://matrix.to/#/#serenity-js:gitter.im)
|
|
6
|
+
[](https://matrix.to/#/#serenity-js:gitter.im)
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
[Serenity/JS](https://serenity-js.org) is an innovative framework designed to make acceptance and regression testing
|
|
9
|
+
of complex software systems faster, more collaborative and easier to scale.
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
To get started, check out the comprehensive [Serenity/JS Handbook](https://serenity-js.org/handbook), [API documentation](https://serenity-js.org/api/core), and [Serenity/JS project templates on GitHub](https://serenity-js.org/handbook/getting-started#serenityjs-project-templates).
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
If you have any questions, join us on [Serenity/JS Community Chat](https://gitter.im/serenity-js/Lobby).
|
|
14
|
-
|
|
15
|
-
[](https://www.youtube.com/watch?v=djPMf-n93Rw)
|
|
13
|
+
If you have any questions or just want to say hello, join the [Serenity/JS Community Chat](https://matrix.to/#/#serenity-js:gitter.im).
|
|
16
14
|
|
|
17
15
|
## Serenity/JS REST
|
|
18
16
|
|
package/lib/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC"}
|
package/lib/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];
|
|
@@ -10,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./models"), exports);
|
|
14
18
|
__exportStar(require("./screenplay"), exports);
|
|
15
19
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Answerable, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { HTTPRequest } from './HTTPRequest';
|
|
4
|
+
/**
|
|
5
|
+
* The DELETE method requests that the origin server remove the
|
|
6
|
+
* association between the target resource and its current
|
|
7
|
+
* functionality.
|
|
8
|
+
*
|
|
9
|
+
* ## Create and then remove a resource
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
13
|
+
* import { CallAnApi, DeleteRequest, LastResponse, PostRequest, Send } from '@serenity-js/rest'
|
|
14
|
+
* import { Ensure, equals, startsWith } from '@serenity-js/assertions'
|
|
15
|
+
*
|
|
16
|
+
* await actorCalled('Apisitt')
|
|
17
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
18
|
+
* .attemptsTo(
|
|
19
|
+
* // create a new test user account
|
|
20
|
+
* Send.a(PostRequest.to('/users').with({
|
|
21
|
+
* login: 'tester',
|
|
22
|
+
* password: 'P@ssword1',
|
|
23
|
+
* }),
|
|
24
|
+
* Ensure.that(LastResponse.status(), equals(201)),
|
|
25
|
+
* Ensure.that(LastResponse.header('Location'), startsWith('/users')),
|
|
26
|
+
*
|
|
27
|
+
* // delete the test user account
|
|
28
|
+
* Send.a(DeleteRequest.to(LastResponse.header('Location'))),
|
|
29
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
30
|
+
* )
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ## Learn more
|
|
34
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE
|
|
35
|
+
* - https://tools.ietf.org/html/rfc7231#section-4.3.5
|
|
36
|
+
*
|
|
37
|
+
* @group Models
|
|
38
|
+
*/
|
|
39
|
+
export declare class DeleteRequest extends HTTPRequest {
|
|
40
|
+
/**
|
|
41
|
+
* Configures the object with a destination URI.
|
|
42
|
+
*
|
|
43
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
44
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
45
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
46
|
+
*
|
|
47
|
+
* @param resourceUri
|
|
48
|
+
* The URI where the {@apilink Actor}
|
|
49
|
+
* should send the {@apilink HTTPRequest}
|
|
50
|
+
*/
|
|
51
|
+
static to(resourceUri: Answerable<string>): DeleteRequest;
|
|
52
|
+
/**
|
|
53
|
+
* Overrides the default Axios request configuration provided
|
|
54
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
55
|
+
*
|
|
56
|
+
* #### Learn more
|
|
57
|
+
* - {@apilink Answerable}
|
|
58
|
+
* - {@apilink WithAnswerableProperties}
|
|
59
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
60
|
+
*
|
|
61
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
62
|
+
* Axios request configuration overrides
|
|
63
|
+
*/
|
|
64
|
+
using(config: Answerable<WithAnswerableProperties<AxiosRequestConfig>>): DeleteRequest;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=DeleteRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeleteRequest.d.ts","sourceRoot":"","sources":["../../src/models/DeleteRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAE1C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,aAAa;IAIzD;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,CAAC,GAAG,aAAa;CAGzF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeleteRequest = void 0;
|
|
4
|
+
const core_1 = require("@serenity-js/core");
|
|
5
|
+
const HTTPRequest_1 = require("./HTTPRequest");
|
|
6
|
+
/**
|
|
7
|
+
* The DELETE method requests that the origin server remove the
|
|
8
|
+
* association between the target resource and its current
|
|
9
|
+
* functionality.
|
|
10
|
+
*
|
|
11
|
+
* ## Create and then remove a resource
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
15
|
+
* import { CallAnApi, DeleteRequest, LastResponse, PostRequest, Send } from '@serenity-js/rest'
|
|
16
|
+
* import { Ensure, equals, startsWith } from '@serenity-js/assertions'
|
|
17
|
+
*
|
|
18
|
+
* await actorCalled('Apisitt')
|
|
19
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
20
|
+
* .attemptsTo(
|
|
21
|
+
* // create a new test user account
|
|
22
|
+
* Send.a(PostRequest.to('/users').with({
|
|
23
|
+
* login: 'tester',
|
|
24
|
+
* password: 'P@ssword1',
|
|
25
|
+
* }),
|
|
26
|
+
* Ensure.that(LastResponse.status(), equals(201)),
|
|
27
|
+
* Ensure.that(LastResponse.header('Location'), startsWith('/users')),
|
|
28
|
+
*
|
|
29
|
+
* // delete the test user account
|
|
30
|
+
* Send.a(DeleteRequest.to(LastResponse.header('Location'))),
|
|
31
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
32
|
+
* )
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* ## Learn more
|
|
36
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE
|
|
37
|
+
* - https://tools.ietf.org/html/rfc7231#section-4.3.5
|
|
38
|
+
*
|
|
39
|
+
* @group Models
|
|
40
|
+
*/
|
|
41
|
+
class DeleteRequest extends HTTPRequest_1.HTTPRequest {
|
|
42
|
+
/**
|
|
43
|
+
* Configures the object with a destination URI.
|
|
44
|
+
*
|
|
45
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
46
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
47
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
48
|
+
*
|
|
49
|
+
* @param resourceUri
|
|
50
|
+
* The URI where the {@apilink Actor}
|
|
51
|
+
* should send the {@apilink HTTPRequest}
|
|
52
|
+
*/
|
|
53
|
+
static to(resourceUri) {
|
|
54
|
+
return new DeleteRequest(resourceUri);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Overrides the default Axios request configuration provided
|
|
58
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
59
|
+
*
|
|
60
|
+
* #### Learn more
|
|
61
|
+
* - {@apilink Answerable}
|
|
62
|
+
* - {@apilink WithAnswerableProperties}
|
|
63
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
64
|
+
*
|
|
65
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
66
|
+
* Axios request configuration overrides
|
|
67
|
+
*/
|
|
68
|
+
using(config) {
|
|
69
|
+
return new DeleteRequest(this.resourceUri, undefined, core_1.Question.fromObject(config));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.DeleteRequest = DeleteRequest;
|
|
73
|
+
//# sourceMappingURL=DeleteRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeleteRequest.js","sourceRoot":"","sources":["../../src/models/DeleteRequest.ts"],"names":[],"mappings":";;;AAAA,4CAAmF;AAGnF,+CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,aAAc,SAAQ,yBAAW;IAE1C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,CAAC,WAA+B;QACrC,OAAO,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAgE;QAClE,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,eAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IACvF,CAAC;CACJ;AAhCD,sCAgCC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Answerable, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { HTTPRequest } from './HTTPRequest';
|
|
4
|
+
/**
|
|
5
|
+
* The HTTP GET method requests a representation of the specified resource.
|
|
6
|
+
* It is the most frequent type of request made by consumers of a typical HTTP API.
|
|
7
|
+
* For this reason it's important to test every known endpoint that responds to GET requests and ensure that it
|
|
8
|
+
* behaves correctly.
|
|
9
|
+
*
|
|
10
|
+
* Since the GET method is used to _retrieve_ data from a server, it should be implemented
|
|
11
|
+
* as [safe](https://developer.mozilla.org/en-US/docs/Glossary/Safe)
|
|
12
|
+
* and [idempotent](https://developer.mozilla.org/en-US/docs/Glossary/Idempotent).
|
|
13
|
+
* This means that an identical request can be made once or several times in a row with the same effect while leaving
|
|
14
|
+
* the server in the same state.
|
|
15
|
+
*
|
|
16
|
+
* ## Verify response to a GET request
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
20
|
+
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
21
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
22
|
+
*
|
|
23
|
+
* interface Book {
|
|
24
|
+
* title: string;
|
|
25
|
+
* author: string;
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* await actorCalled('Apisitt')
|
|
29
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
30
|
+
* .attemptsTo(
|
|
31
|
+
* Send.a(GetRequest.to('/books/0-688-00230-7')),
|
|
32
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
33
|
+
* Ensure.that(LastResponse.body<Book>(), equals({
|
|
34
|
+
* title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
|
|
35
|
+
* author: 'Robert M. Pirsig',
|
|
36
|
+
* })),
|
|
37
|
+
* )
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* ## Learn more
|
|
41
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET
|
|
42
|
+
* - https://tools.ietf.org/html/rfc7231#section-4.3.1
|
|
43
|
+
*
|
|
44
|
+
* @group Models
|
|
45
|
+
*/
|
|
46
|
+
export declare class GetRequest extends HTTPRequest {
|
|
47
|
+
/**
|
|
48
|
+
* Configures the object with a destination URI.
|
|
49
|
+
*
|
|
50
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
51
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
52
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
53
|
+
*
|
|
54
|
+
* @param resourceUri
|
|
55
|
+
* The URI where the {@apilink Actor}
|
|
56
|
+
* should send the {@apilink HTTPRequest}
|
|
57
|
+
*/
|
|
58
|
+
static to(resourceUri: Answerable<string>): GetRequest;
|
|
59
|
+
/**
|
|
60
|
+
* Overrides the default Axios request configuration provided
|
|
61
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
62
|
+
*
|
|
63
|
+
* #### Learn more
|
|
64
|
+
* - {@apilink Answerable}
|
|
65
|
+
* - {@apilink WithAnswerableProperties}
|
|
66
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
67
|
+
*
|
|
68
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
69
|
+
* Axios request configuration overrides
|
|
70
|
+
*/
|
|
71
|
+
using(config: Answerable<WithAnswerableProperties<AxiosRequestConfig>>): GetRequest;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=GetRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GetRequest.d.ts","sourceRoot":"","sources":["../../src/models/GetRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBAAa,UAAW,SAAQ,WAAW;IAEvC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU;IAItD;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,CAAC,GAAG,UAAU;CAGtF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetRequest = void 0;
|
|
4
|
+
const core_1 = require("@serenity-js/core");
|
|
5
|
+
const HTTPRequest_1 = require("./HTTPRequest");
|
|
6
|
+
/**
|
|
7
|
+
* The HTTP GET method requests a representation of the specified resource.
|
|
8
|
+
* It is the most frequent type of request made by consumers of a typical HTTP API.
|
|
9
|
+
* For this reason it's important to test every known endpoint that responds to GET requests and ensure that it
|
|
10
|
+
* behaves correctly.
|
|
11
|
+
*
|
|
12
|
+
* Since the GET method is used to _retrieve_ data from a server, it should be implemented
|
|
13
|
+
* as [safe](https://developer.mozilla.org/en-US/docs/Glossary/Safe)
|
|
14
|
+
* and [idempotent](https://developer.mozilla.org/en-US/docs/Glossary/Idempotent).
|
|
15
|
+
* This means that an identical request can be made once or several times in a row with the same effect while leaving
|
|
16
|
+
* the server in the same state.
|
|
17
|
+
*
|
|
18
|
+
* ## Verify response to a GET request
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
22
|
+
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
23
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
24
|
+
*
|
|
25
|
+
* interface Book {
|
|
26
|
+
* title: string;
|
|
27
|
+
* author: string;
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* await actorCalled('Apisitt')
|
|
31
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
32
|
+
* .attemptsTo(
|
|
33
|
+
* Send.a(GetRequest.to('/books/0-688-00230-7')),
|
|
34
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
35
|
+
* Ensure.that(LastResponse.body<Book>(), equals({
|
|
36
|
+
* title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
|
|
37
|
+
* author: 'Robert M. Pirsig',
|
|
38
|
+
* })),
|
|
39
|
+
* )
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ## Learn more
|
|
43
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET
|
|
44
|
+
* - https://tools.ietf.org/html/rfc7231#section-4.3.1
|
|
45
|
+
*
|
|
46
|
+
* @group Models
|
|
47
|
+
*/
|
|
48
|
+
class GetRequest extends HTTPRequest_1.HTTPRequest {
|
|
49
|
+
/**
|
|
50
|
+
* Configures the object with a destination URI.
|
|
51
|
+
*
|
|
52
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
53
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
54
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
55
|
+
*
|
|
56
|
+
* @param resourceUri
|
|
57
|
+
* The URI where the {@apilink Actor}
|
|
58
|
+
* should send the {@apilink HTTPRequest}
|
|
59
|
+
*/
|
|
60
|
+
static to(resourceUri) {
|
|
61
|
+
return new GetRequest(resourceUri);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Overrides the default Axios request configuration provided
|
|
65
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
66
|
+
*
|
|
67
|
+
* #### Learn more
|
|
68
|
+
* - {@apilink Answerable}
|
|
69
|
+
* - {@apilink WithAnswerableProperties}
|
|
70
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
71
|
+
*
|
|
72
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
73
|
+
* Axios request configuration overrides
|
|
74
|
+
*/
|
|
75
|
+
using(config) {
|
|
76
|
+
return new GetRequest(this.resourceUri, undefined, core_1.Question.fromObject(config));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.GetRequest = GetRequest;
|
|
80
|
+
//# sourceMappingURL=GetRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GetRequest.js","sourceRoot":"","sources":["../../src/models/GetRequest.ts"],"names":[],"mappings":";;;AAAA,4CAAmF;AAGnF,+CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAa,UAAW,SAAQ,yBAAW;IAEvC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,CAAC,WAA+B;QACrC,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAgE;QAClE,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,eAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IACpF,CAAC;CACJ;AAhCD,gCAgCC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Answerable, AnswersQuestions, Question, UsesAbilities, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
/**
|
|
4
|
+
* HTTP Request sent by the {@apilink Actor}
|
|
5
|
+
* using the {@apilink Interaction|interaction} to {@apilink Send}
|
|
6
|
+
*
|
|
7
|
+
* @group Models
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class HTTPRequest extends Question<Promise<AxiosRequestConfig>> {
|
|
10
|
+
protected readonly resourceUri?: Answerable<string>;
|
|
11
|
+
protected readonly data?: Answerable<any>;
|
|
12
|
+
protected readonly config?: Answerable<WithAnswerableProperties<AxiosRequestConfig>>;
|
|
13
|
+
private subject;
|
|
14
|
+
/**
|
|
15
|
+
* @param [resourceUri]
|
|
16
|
+
* URL to which the request should be sent
|
|
17
|
+
*
|
|
18
|
+
* @param [data]
|
|
19
|
+
* Request body to be sent as part of the Put, Post or Patch request
|
|
20
|
+
*
|
|
21
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} [config]
|
|
22
|
+
* Axios request configuration, which can be used to override the defaults
|
|
23
|
+
* provided when the {@apilink Ability|ability} to {@apilink CallAnApi} is instantiated
|
|
24
|
+
*/
|
|
25
|
+
protected constructor(resourceUri?: Answerable<string>, data?: Answerable<any>, config?: Answerable<WithAnswerableProperties<AxiosRequestConfig>>);
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<AxiosRequestConfig>;
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
describedAs(subject: string): this;
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
toString(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Determines the request method based on the name of the request class.
|
|
40
|
+
* For example: GetRequest => GET, PostRequest => POST, etc.
|
|
41
|
+
*/
|
|
42
|
+
private httpMethodName;
|
|
43
|
+
/**
|
|
44
|
+
* A human-readable description of the request, such as "a GET request", "an OPTIONS request", etc.
|
|
45
|
+
*/
|
|
46
|
+
private requestDescription;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=HTTPRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HTTPRequest.d.ts","sourceRoot":"","sources":["../../src/models/HTTPRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,QAAQ,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAEpH,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C;;;;;GAKG;AACH,8BAAsB,WAAY,SAAQ,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAgBvE,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC;IACnD,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;IAhBxF,OAAO,CAAC,OAAO,CAAS;IAExB;;;;;;;;;;OAUG;IACH,SAAS,aACc,WAAW,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,EAChC,IAAI,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,EACtB,MAAM,CAAC,EAAE,UAAU,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;IAMxF;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA0BhF;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAKlC;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAO7B"}
|
|
@@ -4,40 +4,32 @@ exports.HTTPRequest = void 0;
|
|
|
4
4
|
const core_1 = require("@serenity-js/core");
|
|
5
5
|
const io_1 = require("@serenity-js/core/lib/io");
|
|
6
6
|
/**
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
* using the {@link Send} {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
7
|
+
* HTTP Request sent by the {@apilink Actor}
|
|
8
|
+
* using the {@apilink Interaction|interaction} to {@apilink Send}
|
|
10
9
|
*
|
|
11
|
-
* @
|
|
12
|
-
* @extends {Question<Promise<AxiosRequestConfig>>}
|
|
10
|
+
* @group Models
|
|
13
11
|
*/
|
|
14
12
|
class HTTPRequest extends core_1.Question {
|
|
15
13
|
/**
|
|
16
|
-
* @
|
|
17
|
-
*
|
|
18
|
-
* @param {@serenity-js/core/lib/screenplay~Answerable<string>} [resourceUri]
|
|
14
|
+
* @param [resourceUri]
|
|
19
15
|
* URL to which the request should be sent
|
|
20
16
|
*
|
|
21
|
-
* @param
|
|
17
|
+
* @param [data]
|
|
22
18
|
* Request body to be sent as part of the Put, Post or Patch request
|
|
23
19
|
*
|
|
24
|
-
* @param {
|
|
20
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} [config]
|
|
25
21
|
* Axios request configuration, which can be used to override the defaults
|
|
26
|
-
* provided when the {@
|
|
22
|
+
* provided when the {@apilink Ability|ability} to {@apilink CallAnApi} is instantiated
|
|
27
23
|
*/
|
|
28
24
|
constructor(resourceUri, data, config) {
|
|
29
25
|
super();
|
|
30
26
|
this.resourceUri = resourceUri;
|
|
31
27
|
this.data = data;
|
|
32
28
|
this.config = config;
|
|
33
|
-
this.subject = `${this.requestDescription()} to ${(0, io_1.
|
|
29
|
+
this.subject = `${this.requestDescription()} to ${(0, io_1.d) `${this.resourceUri}`}`;
|
|
34
30
|
}
|
|
35
31
|
/**
|
|
36
|
-
* @
|
|
37
|
-
* Resolves the {@link Question} in the context of a given {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
38
|
-
*
|
|
39
|
-
* @param {AnswersQuestions & UsesAbilities} actor
|
|
40
|
-
* @returns {Promise<AxiosRequestConfig>}
|
|
32
|
+
* @inheritDoc
|
|
41
33
|
*/
|
|
42
34
|
answeredBy(actor) {
|
|
43
35
|
return Promise.all([
|
|
@@ -49,23 +41,22 @@ class HTTPRequest extends core_1.Question {
|
|
|
49
41
|
then(config =>
|
|
50
42
|
// eslint-disable-next-line unicorn/prefer-object-from-entries
|
|
51
43
|
Object.keys(config).reduce((acc, key) => {
|
|
52
|
-
if (config[key]) {
|
|
44
|
+
if (config[key] !== null && config[key] !== undefined) {
|
|
53
45
|
acc[key] = config[key];
|
|
54
46
|
}
|
|
55
47
|
return acc;
|
|
56
48
|
}, {}));
|
|
57
49
|
}
|
|
58
50
|
/**
|
|
59
|
-
* @
|
|
60
|
-
* Changes the description of this question's subject.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} subject
|
|
63
|
-
* @returns {Question<T>}
|
|
51
|
+
* @inheritDoc
|
|
64
52
|
*/
|
|
65
53
|
describedAs(subject) {
|
|
66
54
|
this.subject = subject;
|
|
67
55
|
return this;
|
|
68
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* @inheritDoc
|
|
59
|
+
*/
|
|
69
60
|
toString() {
|
|
70
61
|
return this.subject;
|
|
71
62
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HTTPRequest.js","sourceRoot":"","sources":["../../src/models/HTTPRequest.ts"],"names":[],"mappings":";;;AAAA,4CAAoH;AACpH,iDAA6C;AAG7C;;;;;GAKG;AACH,MAAsB,WAAY,SAAQ,eAAqC;IAI3E;;;;;;;;;;OAUG;IACH,YACuB,WAAgC,EAChC,IAAsB,EACtB,MAAiE;QAEpF,KAAK,EAAE,CAAC;QAJW,gBAAW,GAAX,WAAW,CAAqB;QAChC,SAAI,GAAJ,IAAI,CAAkB;QACtB,WAAM,GAAN,MAAM,CAA2D;QAGpF,IAAI,CAAC,OAAO,GAAG,GAAI,IAAI,CAAC,kBAAkB,EAAG,OAAQ,IAAA,MAAC,EAAA,GAAI,IAAI,CAAC,WAAY,EAAG,EAAE,CAAC;IACrF,CAAC;IAED;;OAEG;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,EACF,EAAE,GAAG,EAAE,IAAI,EAAE,EACb,MAAM,EACN,EAAE,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,CACpC,CACJ;YACD,IAAI,CAAC,MAAM,CAAC,EAAE;QACV,8DAA8D;QAC9D,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACpC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAG;gBACpD,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;aAC1B;YACD,OAAO,GAAG,CAAC;QACf,CAAC,EAAE,EAAE,CAAC,CACT,CAAC;IACN,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,OAAe;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,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;AAtFD,kCAsFC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Answerable, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { HTTPRequest } from './HTTPRequest';
|
|
4
|
+
/**
|
|
5
|
+
* The HTTP HEAD method requests the headers that are returned if the specified resource
|
|
6
|
+
* would be requested with an HTTP GET method.
|
|
7
|
+
* Such a request can be done before deciding to download a large resource to save bandwidth, for example.
|
|
8
|
+
*
|
|
9
|
+
* ## File download test
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
13
|
+
* import { CallAnApi, HeadRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
14
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
15
|
+
*
|
|
16
|
+
* await actorCalled('Apisitt')
|
|
17
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
18
|
+
* .attemptsTo(
|
|
19
|
+
* Send.a(HeadRequest.to('/downloads/my-test-document.pdf')),
|
|
20
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
21
|
+
* Ensure.that(LastResponse.header('Content-Length'), equals(256)), // assuming we know the size of the document
|
|
22
|
+
* )
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* ## Learn more
|
|
26
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD
|
|
27
|
+
* - https://tools.ietf.org/html/rfc7231#section-4.3.2
|
|
28
|
+
*
|
|
29
|
+
* @group Models
|
|
30
|
+
*/
|
|
31
|
+
export declare class HeadRequest extends HTTPRequest {
|
|
32
|
+
/**
|
|
33
|
+
* Configures the object with a destination URI.
|
|
34
|
+
*
|
|
35
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
36
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
37
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
38
|
+
*
|
|
39
|
+
* @param resourceUri
|
|
40
|
+
* The URI where the {@apilink Actor}
|
|
41
|
+
* should send the {@apilink HTTPRequest}
|
|
42
|
+
*/
|
|
43
|
+
static to(resourceUri: Answerable<string>): HeadRequest;
|
|
44
|
+
/**
|
|
45
|
+
* Overrides the default Axios request configuration provided
|
|
46
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
47
|
+
*
|
|
48
|
+
* #### Learn more
|
|
49
|
+
* - {@apilink Answerable}
|
|
50
|
+
* - {@apilink WithAnswerableProperties}
|
|
51
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
52
|
+
*
|
|
53
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
54
|
+
* Axios request configuration overrides
|
|
55
|
+
*/
|
|
56
|
+
using(config: Answerable<WithAnswerableProperties<AxiosRequestConfig>>): HeadRequest;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=HeadRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeadRequest.d.ts","sourceRoot":"","sources":["../../src/models/HeadRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,WAAY,SAAQ,WAAW;IAExC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,WAAW;IAIvD;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,CAAC,GAAG,WAAW;CAGvF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HeadRequest = void 0;
|
|
4
|
+
const core_1 = require("@serenity-js/core");
|
|
5
|
+
const HTTPRequest_1 = require("./HTTPRequest");
|
|
6
|
+
/**
|
|
7
|
+
* The HTTP HEAD method requests the headers that are returned if the specified resource
|
|
8
|
+
* would be requested with an HTTP GET method.
|
|
9
|
+
* Such a request can be done before deciding to download a large resource to save bandwidth, for example.
|
|
10
|
+
*
|
|
11
|
+
* ## File download test
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
15
|
+
* import { CallAnApi, HeadRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
16
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
17
|
+
*
|
|
18
|
+
* await actorCalled('Apisitt')
|
|
19
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
20
|
+
* .attemptsTo(
|
|
21
|
+
* Send.a(HeadRequest.to('/downloads/my-test-document.pdf')),
|
|
22
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
23
|
+
* Ensure.that(LastResponse.header('Content-Length'), equals(256)), // assuming we know the size of the document
|
|
24
|
+
* )
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ## Learn more
|
|
28
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD
|
|
29
|
+
* - https://tools.ietf.org/html/rfc7231#section-4.3.2
|
|
30
|
+
*
|
|
31
|
+
* @group Models
|
|
32
|
+
*/
|
|
33
|
+
class HeadRequest extends HTTPRequest_1.HTTPRequest {
|
|
34
|
+
/**
|
|
35
|
+
* Configures the object with a destination URI.
|
|
36
|
+
*
|
|
37
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
38
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
39
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
40
|
+
*
|
|
41
|
+
* @param resourceUri
|
|
42
|
+
* The URI where the {@apilink Actor}
|
|
43
|
+
* should send the {@apilink HTTPRequest}
|
|
44
|
+
*/
|
|
45
|
+
static to(resourceUri) {
|
|
46
|
+
return new HeadRequest(resourceUri);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Overrides the default Axios request configuration provided
|
|
50
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
51
|
+
*
|
|
52
|
+
* #### Learn more
|
|
53
|
+
* - {@apilink Answerable}
|
|
54
|
+
* - {@apilink WithAnswerableProperties}
|
|
55
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
56
|
+
*
|
|
57
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
58
|
+
* Axios request configuration overrides
|
|
59
|
+
*/
|
|
60
|
+
using(config) {
|
|
61
|
+
return new HeadRequest(this.resourceUri, undefined, core_1.Question.fromObject(config));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.HeadRequest = HeadRequest;
|
|
65
|
+
//# sourceMappingURL=HeadRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeadRequest.js","sourceRoot":"","sources":["../../src/models/HeadRequest.ts"],"names":[],"mappings":";;;AAAA,4CAAmF;AAGnF,+CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAa,WAAY,SAAQ,yBAAW;IAExC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,CAAC,WAA+B;QACrC,OAAO,IAAI,WAAW,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAgE;QAClE,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,eAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IACrF,CAAC;CACJ;AAhCD,kCAgCC"}
|