@serenity-js/rest 3.0.0-rc.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +80 -1851
- package/README.md +8 -10
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/models/DeleteRequest.d.ts +66 -0
- package/lib/models/DeleteRequest.d.ts.map +1 -0
- package/lib/models/DeleteRequest.js +73 -0
- package/lib/models/DeleteRequest.js.map +1 -0
- package/lib/models/GetRequest.d.ts +73 -0
- package/lib/models/GetRequest.d.ts.map +1 -0
- package/lib/models/GetRequest.js +80 -0
- package/lib/models/GetRequest.js.map +1 -0
- package/lib/models/HTTPRequest.d.ts +48 -0
- package/lib/models/HTTPRequest.d.ts.map +1 -0
- package/lib/{model → models}/HTTPRequest.js +14 -23
- package/lib/models/HTTPRequest.js.map +1 -0
- package/lib/models/HeadRequest.d.ts +58 -0
- package/lib/models/HeadRequest.d.ts.map +1 -0
- package/lib/models/HeadRequest.js +65 -0
- package/lib/models/HeadRequest.js.map +1 -0
- package/lib/models/OptionsRequest.d.ts +61 -0
- package/lib/models/OptionsRequest.d.ts.map +1 -0
- package/lib/models/OptionsRequest.js +68 -0
- package/lib/models/OptionsRequest.js.map +1 -0
- package/lib/models/PatchRequest.d.ts +65 -0
- package/lib/models/PatchRequest.d.ts.map +1 -0
- package/lib/models/PatchRequest.js +74 -0
- package/lib/models/PatchRequest.js.map +1 -0
- package/lib/models/PostRequest.d.ts +105 -0
- package/lib/models/PostRequest.d.ts.map +1 -0
- package/lib/models/PostRequest.js +114 -0
- package/lib/models/PostRequest.js.map +1 -0
- package/lib/models/PutRequest.d.ts +75 -0
- package/lib/models/PutRequest.d.ts.map +1 -0
- package/lib/models/PutRequest.js +84 -0
- package/lib/models/PutRequest.js.map +1 -0
- package/lib/{model → models}/index.d.ts +1 -0
- package/lib/models/index.d.ts.map +1 -0
- package/lib/{model → models}/index.js +5 -1
- package/lib/models/index.js.map +1 -0
- package/lib/screenplay/abilities/CallAnApi.d.ts +88 -99
- package/lib/screenplay/abilities/CallAnApi.d.ts.map +1 -0
- package/lib/screenplay/abilities/CallAnApi.js +94 -107
- package/lib/screenplay/abilities/CallAnApi.js.map +1 -1
- package/lib/screenplay/abilities/index.d.ts +1 -0
- package/lib/screenplay/abilities/index.d.ts.map +1 -0
- package/lib/screenplay/abilities/index.js +5 -1
- package/lib/screenplay/abilities/index.js.map +1 -1
- package/lib/screenplay/index.d.ts +1 -0
- package/lib/screenplay/index.d.ts.map +1 -0
- package/lib/screenplay/index.js +5 -1
- package/lib/screenplay/index.js.map +1 -1
- package/lib/screenplay/interactions/ChangeApiConfig.d.ts +96 -95
- package/lib/screenplay/interactions/ChangeApiConfig.d.ts.map +1 -0
- package/lib/screenplay/interactions/ChangeApiConfig.js +98 -107
- package/lib/screenplay/interactions/ChangeApiConfig.js.map +1 -1
- package/lib/screenplay/interactions/Send.d.ts +24 -41
- package/lib/screenplay/interactions/Send.d.ts.map +1 -0
- package/lib/screenplay/interactions/Send.js +37 -51
- package/lib/screenplay/interactions/Send.js.map +1 -1
- package/lib/screenplay/interactions/index.d.ts +1 -1
- package/lib/screenplay/interactions/index.d.ts.map +1 -0
- package/lib/screenplay/interactions/index.js +5 -2
- package/lib/screenplay/interactions/index.js.map +1 -1
- package/lib/screenplay/questions/LastResponse.d.ts +152 -98
- package/lib/screenplay/questions/LastResponse.d.ts.map +1 -0
- package/lib/screenplay/questions/LastResponse.js +149 -97
- package/lib/screenplay/questions/LastResponse.js.map +1 -1
- package/lib/screenplay/questions/index.d.ts +1 -0
- package/lib/screenplay/questions/index.d.ts.map +1 -0
- package/lib/screenplay/questions/index.js +5 -1
- package/lib/screenplay/questions/index.js.map +1 -1
- package/package.json +20 -43
- package/src/index.ts +1 -1
- package/src/models/DeleteRequest.ts +73 -0
- package/src/models/GetRequest.ts +80 -0
- package/src/{model → models}/HTTPRequest.ts +17 -26
- package/src/models/HeadRequest.ts +65 -0
- package/src/models/OptionsRequest.ts +68 -0
- package/src/models/PatchRequest.ts +75 -0
- package/src/models/PostRequest.ts +115 -0
- package/src/models/PutRequest.ts +85 -0
- package/src/screenplay/abilities/CallAnApi.ts +90 -108
- package/src/screenplay/interactions/ChangeApiConfig.ts +99 -111
- package/src/screenplay/interactions/Send.ts +46 -61
- package/src/screenplay/interactions/index.ts +0 -1
- package/src/screenplay/questions/LastResponse.ts +153 -100
- package/tsconfig.build.json +10 -0
- package/lib/model/DeleteRequest.d.ts +0 -63
- package/lib/model/DeleteRequest.js +0 -70
- package/lib/model/DeleteRequest.js.map +0 -1
- package/lib/model/GetRequest.d.ts +0 -70
- package/lib/model/GetRequest.js +0 -77
- package/lib/model/GetRequest.js.map +0 -1
- package/lib/model/HTTPRequest.d.ts +0 -56
- package/lib/model/HTTPRequest.js.map +0 -1
- package/lib/model/HeadRequest.d.ts +0 -55
- package/lib/model/HeadRequest.js +0 -62
- package/lib/model/HeadRequest.js.map +0 -1
- package/lib/model/OptionsRequest.d.ts +0 -58
- package/lib/model/OptionsRequest.js +0 -65
- package/lib/model/OptionsRequest.js.map +0 -1
- package/lib/model/PatchRequest.d.ts +0 -65
- package/lib/model/PatchRequest.js +0 -74
- package/lib/model/PatchRequest.js.map +0 -1
- package/lib/model/PostRequest.d.ts +0 -102
- package/lib/model/PostRequest.js +0 -111
- package/lib/model/PostRequest.js.map +0 -1
- package/lib/model/PutRequest.d.ts +0 -75
- package/lib/model/PutRequest.js +0 -84
- package/lib/model/PutRequest.js.map +0 -1
- package/lib/model/index.js.map +0 -1
- package/lib/screenplay/interactions/ChangeApiUrl.d.ts +0 -82
- package/lib/screenplay/interactions/ChangeApiUrl.js +0 -97
- package/lib/screenplay/interactions/ChangeApiUrl.js.map +0 -1
- package/src/model/DeleteRequest.ts +0 -71
- package/src/model/GetRequest.ts +0 -78
- package/src/model/HeadRequest.ts +0 -63
- package/src/model/OptionsRequest.ts +0 -66
- package/src/model/PatchRequest.ts +0 -76
- package/src/model/PostRequest.ts +0 -113
- package/src/model/PutRequest.ts +0 -86
- package/src/screenplay/interactions/ChangeApiUrl.ts +0 -97
- package/tsconfig.eslint.json +0 -10
- /package/src/{model → models}/index.ts +0 -0
|
@@ -1,47 +1,39 @@
|
|
|
1
|
-
import { Answerable, AnswersQuestions, Question, UsesAbilities } from '@serenity-js/core';
|
|
2
|
-
import {
|
|
1
|
+
import { Answerable, AnswersQuestions, Question, UsesAbilities, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { d } from '@serenity-js/core/lib/io';
|
|
3
3
|
import { AxiosRequestConfig } from 'axios';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @
|
|
7
|
-
*
|
|
8
|
-
* using the {@link Send} {@link @serenity-js/core/lib/screenplay~Interaction}
|
|
6
|
+
* HTTP Request sent by the {@apilink Actor}
|
|
7
|
+
* using the {@apilink Interaction|interaction} to {@apilink Send}
|
|
9
8
|
*
|
|
10
|
-
* @
|
|
11
|
-
* @extends {Question<Promise<AxiosRequestConfig>>}
|
|
9
|
+
* @group Models
|
|
12
10
|
*/
|
|
13
11
|
export abstract class HTTPRequest extends Question<Promise<AxiosRequestConfig>> {
|
|
14
12
|
|
|
15
13
|
private subject: string;
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
20
|
-
* @param {@serenity-js/core/lib/screenplay~Answerable<string>} [resourceUri]
|
|
16
|
+
* @param [resourceUri]
|
|
21
17
|
* URL to which the request should be sent
|
|
22
18
|
*
|
|
23
|
-
* @param
|
|
19
|
+
* @param [data]
|
|
24
20
|
* Request body to be sent as part of the Put, Post or Patch request
|
|
25
21
|
*
|
|
26
|
-
* @param {
|
|
22
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} [config]
|
|
27
23
|
* Axios request configuration, which can be used to override the defaults
|
|
28
|
-
* provided when the {@
|
|
24
|
+
* provided when the {@apilink Ability|ability} to {@apilink CallAnApi} is instantiated
|
|
29
25
|
*/
|
|
30
26
|
protected constructor(
|
|
31
27
|
protected readonly resourceUri?: Answerable<string>,
|
|
32
28
|
protected readonly data?: Answerable<any>,
|
|
33
|
-
protected readonly config?: Answerable<AxiosRequestConfig
|
|
29
|
+
protected readonly config?: Answerable<WithAnswerableProperties<AxiosRequestConfig>>,
|
|
34
30
|
) {
|
|
35
31
|
super();
|
|
36
|
-
this.subject = `${ this.requestDescription() } to ${
|
|
32
|
+
this.subject = `${ this.requestDescription() } to ${ d`${ this.resourceUri }` }`;
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
/**
|
|
40
|
-
* @
|
|
41
|
-
* Resolves the {@link Question} in the context of a given {@link @serenity-js/core/lib/screenplay/actor~Actor}
|
|
42
|
-
*
|
|
43
|
-
* @param {AnswersQuestions & UsesAbilities} actor
|
|
44
|
-
* @returns {Promise<AxiosRequestConfig>}
|
|
36
|
+
* @inheritDoc
|
|
45
37
|
*/
|
|
46
38
|
answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<AxiosRequestConfig> {
|
|
47
39
|
return Promise.all([
|
|
@@ -61,7 +53,7 @@ export abstract class HTTPRequest extends Question<Promise<AxiosRequestConfig>>
|
|
|
61
53
|
then(config =>
|
|
62
54
|
// eslint-disable-next-line unicorn/prefer-object-from-entries
|
|
63
55
|
Object.keys(config).reduce((acc, key) => {
|
|
64
|
-
if (config[key]) {
|
|
56
|
+
if (config[key] !== null && config[key] !== undefined ) {
|
|
65
57
|
acc[key] = config[key];
|
|
66
58
|
}
|
|
67
59
|
return acc;
|
|
@@ -70,17 +62,16 @@ export abstract class HTTPRequest extends Question<Promise<AxiosRequestConfig>>
|
|
|
70
62
|
}
|
|
71
63
|
|
|
72
64
|
/**
|
|
73
|
-
* @
|
|
74
|
-
* Changes the description of this question's subject.
|
|
75
|
-
*
|
|
76
|
-
* @param {string} subject
|
|
77
|
-
* @returns {Question<T>}
|
|
65
|
+
* @inheritDoc
|
|
78
66
|
*/
|
|
79
67
|
describedAs(subject: string): this {
|
|
80
68
|
this.subject = subject;
|
|
81
69
|
return this;
|
|
82
70
|
}
|
|
83
71
|
|
|
72
|
+
/**
|
|
73
|
+
* @inheritDoc
|
|
74
|
+
*/
|
|
84
75
|
toString(): string {
|
|
85
76
|
return this.subject;
|
|
86
77
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Answerable, Question, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
|
|
4
|
+
import { HTTPRequest } from './HTTPRequest';
|
|
5
|
+
|
|
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
|
+
export class HeadRequest extends HTTPRequest {
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configures the object with a destination URI.
|
|
37
|
+
*
|
|
38
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
39
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
40
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
41
|
+
*
|
|
42
|
+
* @param resourceUri
|
|
43
|
+
* The URI where the {@apilink Actor}
|
|
44
|
+
* should send the {@apilink HTTPRequest}
|
|
45
|
+
*/
|
|
46
|
+
static to(resourceUri: Answerable<string>): HeadRequest {
|
|
47
|
+
return new HeadRequest(resourceUri);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Overrides the default Axios request configuration provided
|
|
52
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
53
|
+
*
|
|
54
|
+
* #### Learn more
|
|
55
|
+
* - {@apilink Answerable}
|
|
56
|
+
* - {@apilink WithAnswerableProperties}
|
|
57
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
58
|
+
*
|
|
59
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
60
|
+
* Axios request configuration overrides
|
|
61
|
+
*/
|
|
62
|
+
using(config: Answerable<WithAnswerableProperties<AxiosRequestConfig>>): HeadRequest {
|
|
63
|
+
return new HeadRequest(this.resourceUri, undefined, Question.fromObject(config));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Answerable, Question, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
|
|
4
|
+
import { HTTPRequest } from './HTTPRequest';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The OPTIONS method requests information about the communication
|
|
8
|
+
* options available for the target resource, at either the origin
|
|
9
|
+
* server or an intervening intermediary. This method allows a client
|
|
10
|
+
* to determine the options and/or requirements associated with a
|
|
11
|
+
* resource, or the capabilities of a server, without implying a
|
|
12
|
+
* resource action.
|
|
13
|
+
*
|
|
14
|
+
* ## File download test
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
18
|
+
* import { CallAnApi, OptionsRequest, LastResponse, Send } from '@serenity-js/rest'
|
|
19
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
20
|
+
*
|
|
21
|
+
* await actorCalled('Apisitt')
|
|
22
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
23
|
+
* .attemptsTo(
|
|
24
|
+
* Send.a(OptionsRequest.to('/downloads/my-test-document.pdf')),
|
|
25
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
26
|
+
* Ensure.that(LastResponse.header('Allow'), equals('OPTIONS, GET, HEAD')),
|
|
27
|
+
* )
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* ## Learn more
|
|
31
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
|
|
32
|
+
* - https://tools.ietf.org/html/rfc7231#section-4.3.7
|
|
33
|
+
*
|
|
34
|
+
* @group Models
|
|
35
|
+
*/
|
|
36
|
+
export class OptionsRequest extends HTTPRequest {
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Configures the object with a destination URI.
|
|
40
|
+
*
|
|
41
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
42
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
43
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
44
|
+
*
|
|
45
|
+
* @param resourceUri
|
|
46
|
+
* The URI where the {@apilink Actor}
|
|
47
|
+
* should send the {@apilink HTTPRequest}
|
|
48
|
+
*/
|
|
49
|
+
static to(resourceUri: Answerable<string>): OptionsRequest {
|
|
50
|
+
return new OptionsRequest(resourceUri);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Overrides the default Axios request configuration provided
|
|
55
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
56
|
+
*
|
|
57
|
+
* #### Learn more
|
|
58
|
+
* - {@apilink Answerable}
|
|
59
|
+
* - {@apilink WithAnswerableProperties}
|
|
60
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
61
|
+
*
|
|
62
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
63
|
+
* Axios request configuration overrides
|
|
64
|
+
*/
|
|
65
|
+
using(config: Answerable<WithAnswerableProperties<AxiosRequestConfig>>): OptionsRequest {
|
|
66
|
+
return new OptionsRequest(this.resourceUri, undefined, Question.fromObject(config));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Answerable, Question, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
|
|
4
|
+
import { HTTPRequest } from './HTTPRequest';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The PATCH method requests that a set of changes described in the
|
|
8
|
+
* request entity be applied to the resource identified by the `resourceUri`.
|
|
9
|
+
*
|
|
10
|
+
* ## Add new resource to a collection
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
14
|
+
* import { CallAnApi, LastResponse, PatchRequest, Send } from '@serenity-js/rest'
|
|
15
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
16
|
+
*
|
|
17
|
+
* await actorCalled('Apisitt')
|
|
18
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
19
|
+
* .attemptsTo(
|
|
20
|
+
* Send.a(PatchRequest.to('/books/0-688-00230-7').with({
|
|
21
|
+
* lastReadOn: '2016-06-16',
|
|
22
|
+
* })),
|
|
23
|
+
* Ensure.that(LastResponse.status(), equals(204)),
|
|
24
|
+
* )
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ## Learn more
|
|
28
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH
|
|
29
|
+
* - https://tools.ietf.org/html/rfc5789
|
|
30
|
+
*
|
|
31
|
+
* @group Models
|
|
32
|
+
*/
|
|
33
|
+
export class PatchRequest extends HTTPRequest {
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configures the object with a destination URI.
|
|
37
|
+
*
|
|
38
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
39
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
40
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
41
|
+
*
|
|
42
|
+
* @param resourceUri
|
|
43
|
+
* The URI where the {@apilink Actor}
|
|
44
|
+
* should send the {@apilink HTTPRequest}
|
|
45
|
+
*/
|
|
46
|
+
static to(resourceUri: Answerable<string>): PatchRequest {
|
|
47
|
+
return new PatchRequest(resourceUri);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Configures the object with a request body.
|
|
52
|
+
*
|
|
53
|
+
* @param data
|
|
54
|
+
* Data to be sent to the `resourceUri`
|
|
55
|
+
*/
|
|
56
|
+
with(data: Answerable<any>): PatchRequest {
|
|
57
|
+
return new PatchRequest(this.resourceUri, data, this.config);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Overrides the default Axios request configuration provided
|
|
62
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
63
|
+
*
|
|
64
|
+
* #### Learn more
|
|
65
|
+
* - {@apilink Answerable}
|
|
66
|
+
* - {@apilink WithAnswerableProperties}
|
|
67
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
68
|
+
*
|
|
69
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
70
|
+
* Axios request configuration overrides
|
|
71
|
+
*/
|
|
72
|
+
using(config: Answerable<WithAnswerableProperties<AxiosRequestConfig>>): PatchRequest {
|
|
73
|
+
return new PatchRequest(this.resourceUri, this.data, Question.fromObject(config));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Answerable, Question, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
|
|
4
|
+
import { HTTPRequest } from './HTTPRequest';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The HTTP POST method requests that the origin server accepts
|
|
8
|
+
* the entity enclosed in the request as a new subordinate of the resource
|
|
9
|
+
* identified by the `resourceUri`.
|
|
10
|
+
*
|
|
11
|
+
* This means that the POST should be used when you want to create a child resource under
|
|
12
|
+
* a collection of resources.
|
|
13
|
+
*
|
|
14
|
+
* POST request is neither [safe](https://developer.mozilla.org/en-US/docs/Glossary/Safe),
|
|
15
|
+
* nor [idempotent](https://developer.mozilla.org/en-US/docs/Glossary/Idempotent).
|
|
16
|
+
* This means that if you retry a POST request N times,
|
|
17
|
+
* a correctly implemented HTTP REST API will create N resources with N different URIs.
|
|
18
|
+
*
|
|
19
|
+
* ## Add new resource to a collection
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
23
|
+
* import { CallAnApi, LastResponse, PostRequest, Send } from '@serenity-js/rest'
|
|
24
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
25
|
+
*
|
|
26
|
+
* await actorCalled('Apisitt')
|
|
27
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
28
|
+
* .attemptsTo(
|
|
29
|
+
* Send.a(PostRequest.to('/books').with({
|
|
30
|
+
* isbn: '0-688-00230-7',
|
|
31
|
+
* title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
|
|
32
|
+
* author: 'Robert M. Pirsig',
|
|
33
|
+
* })),
|
|
34
|
+
* Ensure.that(LastResponse.status(), equals(201)),
|
|
35
|
+
* Ensure.that(LastResponse.header('Location'), equals('/books/0-688-00230-7')),
|
|
36
|
+
* )
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* ## Submit an HTML form
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
43
|
+
* import { CallAnApi, LastResponse, PostRequest, Send } from '@serenity-js/rest'
|
|
44
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
45
|
+
* import { stringify } from 'querystring'
|
|
46
|
+
*
|
|
47
|
+
* const formData = stringify({
|
|
48
|
+
* name: actor.name,
|
|
49
|
+
* email: `${ actor.name }@example.com`,
|
|
50
|
+
* text: 'Your website is great! Learnt a lot :-)'
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* await actorCalled('Apisitt')
|
|
54
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
55
|
+
* .attemptsTo(
|
|
56
|
+
* Send.a(PostRequest.to('/feedback').with(postData).using({
|
|
57
|
+
* headers: {
|
|
58
|
+
* 'Content-Type': 'application/x-www-form-urlencoded',
|
|
59
|
+
* 'Content-Length': formData.length
|
|
60
|
+
* }
|
|
61
|
+
* })),
|
|
62
|
+
* Ensure.that(LastResponse.status(), equals(200)),
|
|
63
|
+
* Ensure.that(LastResponse.header('Location'), equals('/feedback/thank-you.html')),
|
|
64
|
+
* )
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* ## Learn more
|
|
68
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
|
|
69
|
+
* - https://tools.ietf.org/html/rfc7231#section-4.3.3
|
|
70
|
+
*
|
|
71
|
+
* @group Models
|
|
72
|
+
*/
|
|
73
|
+
export class PostRequest extends HTTPRequest {
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Configures the object with a destination URI.
|
|
77
|
+
*
|
|
78
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
79
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
80
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
81
|
+
*
|
|
82
|
+
* @param resourceUri
|
|
83
|
+
* The URI where the {@apilink Actor}
|
|
84
|
+
* should send the {@apilink HTTPRequest}
|
|
85
|
+
*/
|
|
86
|
+
static to(resourceUri: Answerable<string>): PostRequest {
|
|
87
|
+
return new PostRequest(resourceUri);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Configures the object with a request body.
|
|
92
|
+
*
|
|
93
|
+
* @param data
|
|
94
|
+
* Data to be sent to the `resourceUri`
|
|
95
|
+
*/
|
|
96
|
+
with(data: Answerable<any>): PostRequest {
|
|
97
|
+
return new PostRequest(this.resourceUri, data, this.config);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Overrides the default Axios request configuration provided
|
|
102
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
103
|
+
*
|
|
104
|
+
* #### Learn more
|
|
105
|
+
* - {@apilink Answerable}
|
|
106
|
+
* - {@apilink WithAnswerableProperties}
|
|
107
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
108
|
+
*
|
|
109
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
110
|
+
* Axios request configuration overrides
|
|
111
|
+
*/
|
|
112
|
+
using(config: Answerable<WithAnswerableProperties<AxiosRequestConfig>>): PostRequest {
|
|
113
|
+
return new PostRequest(this.resourceUri, this.data, Question.fromObject(config));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Answerable, Question, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
|
|
4
|
+
import { HTTPRequest } from './HTTPRequest';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The PUT method requests that the state of the target resource be
|
|
8
|
+
* created or replaced with the state defined by the representation
|
|
9
|
+
* enclosed in the request message payload.
|
|
10
|
+
*
|
|
11
|
+
* PUT request should be used when you want to create
|
|
12
|
+
* a new resource at a known `resourceUri` (e.g. `/books/0-688-00230-7`)
|
|
13
|
+
* or replace an existing resource at such `resourceUri`.
|
|
14
|
+
*
|
|
15
|
+
* PUT request is [idempotent](https://developer.mozilla.org/en-US/docs/Glossary/Idempotent):
|
|
16
|
+
* calling it once or several times successively has the same effect (that is no _side effect_).
|
|
17
|
+
*
|
|
18
|
+
* ## Create a new resource at a known location
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { actorCalled } from '@serenity-js/core';
|
|
22
|
+
* import { CallAnApi, LastResponse, PutRequest, Send } from '@serenity-js/rest';
|
|
23
|
+
* import { Ensure, equals } from '@serenity-js/assertions';
|
|
24
|
+
*
|
|
25
|
+
* await actorCalled('Apisit')
|
|
26
|
+
* .whoCan(CallAnApi.at('https://api.example.org/'))
|
|
27
|
+
* .attemptsTo(
|
|
28
|
+
* Send.a(PutRequest.to('/books/0-688-00230-7').with({
|
|
29
|
+
* isbn: '0-688-00230-7',
|
|
30
|
+
* title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
|
|
31
|
+
* author: 'Robert M. Pirsig',
|
|
32
|
+
* })),
|
|
33
|
+
* Ensure.that(LastResponse.status(), equals(201)),
|
|
34
|
+
* )
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* ## Learn more
|
|
38
|
+
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT
|
|
39
|
+
* - https://tools.ietf.org/html/rfc7231#section-4.3.4
|
|
40
|
+
*
|
|
41
|
+
* @group Models
|
|
42
|
+
*/
|
|
43
|
+
export class PutRequest extends HTTPRequest {
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Configures the object with a destination URI.
|
|
47
|
+
*
|
|
48
|
+
* When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
|
|
49
|
+
* it gets concatenated with the URL provided to the Axios instance
|
|
50
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
51
|
+
*
|
|
52
|
+
* @param resourceUri
|
|
53
|
+
* The URI where the {@apilink Actor}
|
|
54
|
+
* should send the {@apilink HTTPRequest}
|
|
55
|
+
*/
|
|
56
|
+
static to(resourceUri: Answerable<string>): PutRequest {
|
|
57
|
+
return new PutRequest(resourceUri);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Configures the object with a request body.
|
|
62
|
+
*
|
|
63
|
+
* @param data
|
|
64
|
+
* Data to be sent to the `resourceUri`
|
|
65
|
+
*/
|
|
66
|
+
with(data: Answerable<any>): PutRequest {
|
|
67
|
+
return new PutRequest(this.resourceUri, data, this.config);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Overrides the default Axios request configuration provided
|
|
72
|
+
* when the {@apilink Ability|ability} to {@apilink CallAnApi} was instantiated.
|
|
73
|
+
*
|
|
74
|
+
* #### Learn more
|
|
75
|
+
* - {@apilink Answerable}
|
|
76
|
+
* - {@apilink WithAnswerableProperties}
|
|
77
|
+
* - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
|
|
78
|
+
*
|
|
79
|
+
* @param {Answerable<WithAnswerableProperties<AxiosRequestConfig>>} config
|
|
80
|
+
* Axios request configuration overrides
|
|
81
|
+
*/
|
|
82
|
+
using(config: Answerable<WithAnswerableProperties<AxiosRequestConfig>>): PutRequest {
|
|
83
|
+
return new PutRequest(this.resourceUri, this.data, Question.fromObject(config));
|
|
84
|
+
}
|
|
85
|
+
}
|