@serenity-js/rest 3.0.0-rc.9 → 3.0.1

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +81 -1852
  2. package/README.md +8 -10
  3. package/lib/index.d.ts +2 -1
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.js +6 -2
  6. package/lib/index.js.map +1 -1
  7. package/lib/models/DeleteRequest.d.ts +66 -0
  8. package/lib/models/DeleteRequest.d.ts.map +1 -0
  9. package/lib/models/DeleteRequest.js +73 -0
  10. package/lib/models/DeleteRequest.js.map +1 -0
  11. package/lib/models/GetRequest.d.ts +73 -0
  12. package/lib/models/GetRequest.d.ts.map +1 -0
  13. package/lib/models/GetRequest.js +80 -0
  14. package/lib/models/GetRequest.js.map +1 -0
  15. package/lib/models/HTTPRequest.d.ts +48 -0
  16. package/lib/models/HTTPRequest.d.ts.map +1 -0
  17. package/lib/{model → models}/HTTPRequest.js +14 -23
  18. package/lib/models/HTTPRequest.js.map +1 -0
  19. package/lib/models/HeadRequest.d.ts +58 -0
  20. package/lib/models/HeadRequest.d.ts.map +1 -0
  21. package/lib/models/HeadRequest.js +65 -0
  22. package/lib/models/HeadRequest.js.map +1 -0
  23. package/lib/models/OptionsRequest.d.ts +61 -0
  24. package/lib/models/OptionsRequest.d.ts.map +1 -0
  25. package/lib/models/OptionsRequest.js +68 -0
  26. package/lib/models/OptionsRequest.js.map +1 -0
  27. package/lib/models/PatchRequest.d.ts +65 -0
  28. package/lib/models/PatchRequest.d.ts.map +1 -0
  29. package/lib/models/PatchRequest.js +74 -0
  30. package/lib/models/PatchRequest.js.map +1 -0
  31. package/lib/models/PostRequest.d.ts +105 -0
  32. package/lib/models/PostRequest.d.ts.map +1 -0
  33. package/lib/models/PostRequest.js +114 -0
  34. package/lib/models/PostRequest.js.map +1 -0
  35. package/lib/models/PutRequest.d.ts +75 -0
  36. package/lib/models/PutRequest.d.ts.map +1 -0
  37. package/lib/models/PutRequest.js +84 -0
  38. package/lib/models/PutRequest.js.map +1 -0
  39. package/lib/{model → models}/index.d.ts +1 -0
  40. package/lib/models/index.d.ts.map +1 -0
  41. package/lib/{model → models}/index.js +5 -1
  42. package/lib/models/index.js.map +1 -0
  43. package/lib/screenplay/abilities/CallAnApi.d.ts +88 -99
  44. package/lib/screenplay/abilities/CallAnApi.d.ts.map +1 -0
  45. package/lib/screenplay/abilities/CallAnApi.js +94 -107
  46. package/lib/screenplay/abilities/CallAnApi.js.map +1 -1
  47. package/lib/screenplay/abilities/index.d.ts +1 -0
  48. package/lib/screenplay/abilities/index.d.ts.map +1 -0
  49. package/lib/screenplay/abilities/index.js +5 -1
  50. package/lib/screenplay/abilities/index.js.map +1 -1
  51. package/lib/screenplay/index.d.ts +1 -0
  52. package/lib/screenplay/index.d.ts.map +1 -0
  53. package/lib/screenplay/index.js +5 -1
  54. package/lib/screenplay/index.js.map +1 -1
  55. package/lib/screenplay/interactions/ChangeApiConfig.d.ts +96 -95
  56. package/lib/screenplay/interactions/ChangeApiConfig.d.ts.map +1 -0
  57. package/lib/screenplay/interactions/ChangeApiConfig.js +98 -107
  58. package/lib/screenplay/interactions/ChangeApiConfig.js.map +1 -1
  59. package/lib/screenplay/interactions/Send.d.ts +24 -41
  60. package/lib/screenplay/interactions/Send.d.ts.map +1 -0
  61. package/lib/screenplay/interactions/Send.js +37 -51
  62. package/lib/screenplay/interactions/Send.js.map +1 -1
  63. package/lib/screenplay/interactions/index.d.ts +1 -1
  64. package/lib/screenplay/interactions/index.d.ts.map +1 -0
  65. package/lib/screenplay/interactions/index.js +5 -2
  66. package/lib/screenplay/interactions/index.js.map +1 -1
  67. package/lib/screenplay/questions/LastResponse.d.ts +152 -98
  68. package/lib/screenplay/questions/LastResponse.d.ts.map +1 -0
  69. package/lib/screenplay/questions/LastResponse.js +149 -97
  70. package/lib/screenplay/questions/LastResponse.js.map +1 -1
  71. package/lib/screenplay/questions/index.d.ts +1 -0
  72. package/lib/screenplay/questions/index.d.ts.map +1 -0
  73. package/lib/screenplay/questions/index.js +5 -1
  74. package/lib/screenplay/questions/index.js.map +1 -1
  75. package/package.json +20 -43
  76. package/src/index.ts +1 -1
  77. package/src/models/DeleteRequest.ts +73 -0
  78. package/src/models/GetRequest.ts +80 -0
  79. package/src/{model → models}/HTTPRequest.ts +17 -26
  80. package/src/models/HeadRequest.ts +65 -0
  81. package/src/models/OptionsRequest.ts +68 -0
  82. package/src/models/PatchRequest.ts +75 -0
  83. package/src/models/PostRequest.ts +115 -0
  84. package/src/models/PutRequest.ts +85 -0
  85. package/src/screenplay/abilities/CallAnApi.ts +90 -108
  86. package/src/screenplay/interactions/ChangeApiConfig.ts +99 -111
  87. package/src/screenplay/interactions/Send.ts +46 -61
  88. package/src/screenplay/interactions/index.ts +0 -1
  89. package/src/screenplay/questions/LastResponse.ts +153 -100
  90. package/tsconfig.build.json +10 -0
  91. package/lib/model/DeleteRequest.d.ts +0 -63
  92. package/lib/model/DeleteRequest.js +0 -70
  93. package/lib/model/DeleteRequest.js.map +0 -1
  94. package/lib/model/GetRequest.d.ts +0 -70
  95. package/lib/model/GetRequest.js +0 -77
  96. package/lib/model/GetRequest.js.map +0 -1
  97. package/lib/model/HTTPRequest.d.ts +0 -56
  98. package/lib/model/HTTPRequest.js.map +0 -1
  99. package/lib/model/HeadRequest.d.ts +0 -55
  100. package/lib/model/HeadRequest.js +0 -62
  101. package/lib/model/HeadRequest.js.map +0 -1
  102. package/lib/model/OptionsRequest.d.ts +0 -58
  103. package/lib/model/OptionsRequest.js +0 -65
  104. package/lib/model/OptionsRequest.js.map +0 -1
  105. package/lib/model/PatchRequest.d.ts +0 -65
  106. package/lib/model/PatchRequest.js +0 -74
  107. package/lib/model/PatchRequest.js.map +0 -1
  108. package/lib/model/PostRequest.d.ts +0 -102
  109. package/lib/model/PostRequest.js +0 -111
  110. package/lib/model/PostRequest.js.map +0 -1
  111. package/lib/model/PutRequest.d.ts +0 -75
  112. package/lib/model/PutRequest.js +0 -84
  113. package/lib/model/PutRequest.js.map +0 -1
  114. package/lib/model/index.js.map +0 -1
  115. package/lib/screenplay/interactions/ChangeApiUrl.d.ts +0 -82
  116. package/lib/screenplay/interactions/ChangeApiUrl.js +0 -97
  117. package/lib/screenplay/interactions/ChangeApiUrl.js.map +0 -1
  118. package/src/model/DeleteRequest.ts +0 -71
  119. package/src/model/GetRequest.ts +0 -78
  120. package/src/model/HeadRequest.ts +0 -63
  121. package/src/model/OptionsRequest.ts +0 -66
  122. package/src/model/PatchRequest.ts +0 -76
  123. package/src/model/PostRequest.ts +0 -113
  124. package/src/model/PutRequest.ts +0 -86
  125. package/src/screenplay/interactions/ChangeApiUrl.ts +0 -97
  126. package/tsconfig.eslint.json +0 -10
  127. /package/src/{model → models}/index.ts +0 -0
@@ -1,78 +0,0 @@
1
- import { Answerable } from '@serenity-js/core';
2
- import { AxiosRequestConfig } from 'axios';
3
-
4
- import { HTTPRequest } from './HTTPRequest';
5
-
6
- /**
7
- * @desc
8
- * The HTTP GET method requests a representation of the specified resource.
9
- * It is the most frequent type of request made by consumers of a typical HTTP API.
10
- * For this reason it's important to test every known endpoint that responds to GET requests and ensure that it
11
- * behaves correctly.
12
- *
13
- * Since the GET method is used to _retrieve_ data from a server, it should be implemented
14
- * as [safe](https://developer.mozilla.org/en-US/docs/Glossary/Safe)
15
- * and [idempotent](https://developer.mozilla.org/en-US/docs/Glossary/Idempotent).
16
- * This means that an identical request can be made once or several times in a row with the same effect while leaving
17
- * the server in the same state.
18
- *
19
- * @example <caption>Verify response to a GET request</caption>
20
- * import { Actor } from '@serenity-js/core';
21
- * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
22
- * import { Ensure, equals } from '@serenity-js/assertions';
23
- *
24
- * interface Book {
25
- * title: string;
26
- * author: string;
27
- * }
28
- *
29
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
30
- *
31
- * actor.attemptsTo(
32
- * Send.a(GetRequest.to('/books/0-688-00230-7')),
33
- * Ensure.that(LastResponse.status(), equals(200)),
34
- * Ensure.that(LastResponse.body<Book>(), equals({
35
- * title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
36
- * author: 'Robert M. Pirsig',
37
- * })),
38
- * );
39
- *
40
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET
41
- * @see https://tools.ietf.org/html/rfc7231#section-4.3.1
42
- *
43
- * @extends {HTTPRequest}
44
- */
45
- export class GetRequest extends HTTPRequest {
46
-
47
- /**
48
- * @desc
49
- * Configures the object with a destination URI.
50
- *
51
- * When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
52
- * it gets concatenated with the URL provided to the Axios instance
53
- * when the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
54
- *
55
- * @param {@serenity-js/core/lib/screenplay~Answerable<string>} resourceUri
56
- * The URI where the {@link @serenity-js/core/lib/screenplay/actor~Actor}
57
- * should send the {@link HTTPRequest}.
58
- *
59
- * @returns {GetRequest}
60
- */
61
- static to(resourceUri: Answerable<string>): GetRequest {
62
- return new GetRequest(resourceUri);
63
- }
64
-
65
- /**
66
- * @desc
67
- * Overrides the default Axios request configuration provided
68
- * when {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
69
- *
70
- * @param {@serenity-js/core/lib/screenplay~Answerable<AxiosRequestConfig>} config
71
- * Axios request configuration overrides
72
- *
73
- * @returns {GetRequest}
74
- */
75
- using(config: Answerable<AxiosRequestConfig>): GetRequest {
76
- return new GetRequest(this.resourceUri, undefined, config);
77
- }
78
- }
@@ -1,63 +0,0 @@
1
- import { Answerable } from '@serenity-js/core';
2
- import { AxiosRequestConfig } from 'axios';
3
-
4
- import { HTTPRequest } from './HTTPRequest';
5
-
6
- /**
7
- * @desc
8
- * The HTTP HEAD method requests the headers that are returned if the specified resource
9
- * would be requested with an HTTP GET method.
10
- * Such a request can be done before deciding to download a large resource to save bandwidth, for example.
11
- *
12
- * @example <caption>File download test</caption>
13
- * import { Actor } from '@serenity-js/core';
14
- * import { CallAnApi, HeadRequest, LastResponse, Send } from '@serenity-js/rest'
15
- * import { Ensure, equals } from '@serenity-js/assertions';
16
- *
17
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
18
- *
19
- * actor.attemptsTo(
20
- * Send.a(HeadRequest.to('/downloads/my-test-document.pdf')),
21
- * Ensure.that(LastResponse.status(), equals(200)),
22
- * Ensure.that(LastResponse.header('Content-Length'), equals(256)), // assuming we know the size of the document
23
- * );
24
- *
25
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD
26
- * @see https://tools.ietf.org/html/rfc7231#section-4.3.2
27
- *
28
- * @extends {HTTPRequest}
29
- */
30
- export class HeadRequest extends HTTPRequest {
31
-
32
- /**
33
- * @desc
34
- * Configures the object with a destination URI.
35
- *
36
- * When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
37
- * it gets concatenated with the URL provided to the Axios instance
38
- * when the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
39
- *
40
- * @param {@serenity-js/core/lib/screenplay~Answerable<string>} resourceUri
41
- * The URI where the {@link @serenity-js/core/lib/screenplay/actor~Actor}
42
- * should send the {@link HTTPRequest}.
43
- *
44
- * @returns {HeadRequest}
45
- */
46
- static to(resourceUri: Answerable<string>): HeadRequest {
47
- return new HeadRequest(resourceUri);
48
- }
49
-
50
- /**
51
- * @desc
52
- * Overrides the default Axios request configuration provided
53
- * when {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
54
- *
55
- * @param {@serenity-js/core/lib/screenplay~Answerable<AxiosRequestConfig>} config
56
- * Axios request configuration overrides
57
- *
58
- * @returns {HeadRequest}
59
- */
60
- using(config: Answerable<AxiosRequestConfig>): HeadRequest {
61
- return new HeadRequest(this.resourceUri, undefined, config);
62
- }
63
- }
@@ -1,66 +0,0 @@
1
- import { Answerable } from '@serenity-js/core';
2
- import { AxiosRequestConfig } from 'axios';
3
-
4
- import { HTTPRequest } from './HTTPRequest';
5
-
6
- /**
7
- * @desc
8
- * The OPTIONS method requests information about the communication
9
- * options available for the target resource, at either the origin
10
- * server or an intervening intermediary. This method allows a client
11
- * to determine the options and/or requirements associated with a
12
- * resource, or the capabilities of a server, without implying a
13
- * resource action.
14
- *
15
- * @example <caption>File download test</caption>
16
- * import { Actor } from '@serenity-js/core';
17
- * import { CallAnApi, OptionsRequest, LastResponse, Send } from '@serenity-js/rest'
18
- * import { Ensure, equals } from '@serenity-js/assertions';
19
- *
20
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
21
- *
22
- * actor.attemptsTo(
23
- * Send.a(OptionsRequest.to('/downloads/my-test-document.pdf')),
24
- * Ensure.that(LastResponse.status(), equals(200)),
25
- * Ensure.that(LastResponse.header('Allow'), equals('OPTIONS, GET, HEAD')),
26
- * );
27
- *
28
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
29
- * @see https://tools.ietf.org/html/rfc7231#section-4.3.7
30
- *
31
- * @extends {HTTPRequest}
32
- */
33
- export class OptionsRequest extends HTTPRequest {
34
-
35
- /**
36
- * @desc
37
- * Configures the object with a destination URI.
38
- *
39
- * When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
40
- * it gets concatenated with the URL provided to the Axios instance
41
- * when the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
42
- *
43
- * @param {@serenity-js/core/lib/screenplay~Answerable<string>} resourceUri
44
- * The URI where the {@link @serenity-js/core/lib/screenplay/actor~Actor}
45
- * should send the {@link HTTPRequest}.
46
- *
47
- * @returns {OptionsRequest}
48
- */
49
- static to(resourceUri: Answerable<string>): OptionsRequest {
50
- return new OptionsRequest(resourceUri);
51
- }
52
-
53
- /**
54
- * @desc
55
- * Overrides the default Axios request configuration provided
56
- * when {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
57
- *
58
- * @param {@serenity-js/core/lib/screenplay~Answerable<AxiosRequestConfig>} config
59
- * Axios request configuration overrides
60
- *
61
- * @returns {OptionsRequest}
62
- */
63
- using(config: Answerable<AxiosRequestConfig>): OptionsRequest {
64
- return new OptionsRequest(this.resourceUri, undefined, config);
65
- }
66
- }
@@ -1,76 +0,0 @@
1
- import { Answerable } from '@serenity-js/core';
2
- import { AxiosRequestConfig } from 'axios';
3
-
4
- import { HTTPRequest } from './HTTPRequest';
5
-
6
- /**
7
- * @desc
8
- * The PATCH method requests that a set of changes described in the
9
- * request entity be applied to the resource identified by the `resourceUri`.
10
- *
11
- * @example <caption>Add new resource to a collection</caption>
12
- * import { Actor } from '@serenity-js/core';
13
- * import { CallAnApi, LastResponse, PatchRequest, Send } from '@serenity-js/rest'
14
- * import { Ensure, equals } from '@serenity-js/assertions';
15
- *
16
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
17
- *
18
- * actor.attemptsTo(
19
- * Send.a(PatchRequest.to('/books/0-688-00230-7').with({
20
- * lastReadOn: '2016-06-16',
21
- * })),
22
- * Ensure.that(LastResponse.status(), equals(204)),
23
- * );
24
- *
25
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH
26
- * @see https://tools.ietf.org/html/rfc5789
27
- *
28
- * @extends {HTTPRequest}
29
- */
30
- export class PatchRequest extends HTTPRequest {
31
-
32
- /**
33
- * @desc
34
- * Configures the object with a destination URI.
35
- *
36
- * When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
37
- * it gets concatenated with the URL provided to the Axios instance
38
- * when the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
39
- *
40
- * @param {@serenity-js/core/lib/screenplay~Answerable<string>} resourceUri
41
- * The URI where the {@link @serenity-js/core/lib/screenplay/actor~Actor}
42
- * should send the {@link HTTPRequest}.
43
- *
44
- * @returns {PatchRequest}
45
- */
46
- static to(resourceUri: Answerable<string>): PatchRequest {
47
- return new PatchRequest(resourceUri);
48
- }
49
-
50
- /**
51
- * @desc
52
- * Configures the object with a request body.
53
- *
54
- * @param {@serenity-js/core/lib/screenplay~Answerable<any>} data
55
- * Data to be sent to the `resourceUri`
56
- *
57
- * @returns {PatchRequest}
58
- */
59
- with(data: Answerable<any>): PatchRequest {
60
- return new PatchRequest(this.resourceUri, data, this.config);
61
- }
62
-
63
- /**
64
- * @desc
65
- * Overrides the default Axios request configuration provided
66
- * when {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
67
- *
68
- * @param {@serenity-js/core/lib/screenplay~Answerable<AxiosRequestConfig>} config
69
- * Axios request configuration overrides
70
- *
71
- * @returns {PatchRequest}
72
- */
73
- using(config: Answerable<AxiosRequestConfig>): PatchRequest {
74
- return new PatchRequest(this.resourceUri, this.data, config);
75
- }
76
- }
@@ -1,113 +0,0 @@
1
- import { Answerable } from '@serenity-js/core';
2
- import { AxiosRequestConfig } from 'axios';
3
-
4
- import { HTTPRequest } from './HTTPRequest';
5
-
6
- /**
7
- * @desc
8
- * The HTTP POST method requests that the origin server accepts
9
- * the entity enclosed in the request as a new subordinate of the resource
10
- * identified by the `resourceUri`.
11
- *
12
- * This means that the POST should be used when you want to create a child resource under
13
- * a collection of resources.
14
- *
15
- * POST request is neither [safe](https://developer.mozilla.org/en-US/docs/Glossary/Safe),
16
- * nor [idempotent](https://developer.mozilla.org/en-US/docs/Glossary/Idempotent).
17
- * This means that if you retry a POST request N times,
18
- * a correctly implemented HTTP REST API will create N resources with N different URIs.
19
- *
20
- * @example <caption>Add new resource to a collection</caption>
21
- * import { Actor } from '@serenity-js/core';
22
- * import { CallAnApi, LastResponse, PostRequest, Send } from '@serenity-js/rest'
23
- * import { Ensure, equals } from '@serenity-js/assertions';
24
- *
25
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
26
- *
27
- * actor.attemptsTo(
28
- * Send.a(PostRequest.to('/books').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
- * Ensure.that(LastResponse.header('Location'), equals('/books/0-688-00230-7')),
35
- * );
36
- *
37
- * @example <caption>Submit a HTML form</caption>
38
- * import { Actor } from '@serenity-js/core';
39
- * import { CallAnApi, LastResponse, PostRequest, Send } from '@serenity-js/rest'
40
- * import { Ensure, equals } from '@serenity-js/assertions';
41
- * import { stringify } from 'querystring';
42
- *
43
- * const
44
- * actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com')),
45
- * formData = stringify({
46
- * name: actor.name,
47
- * email: `${ actor.name }@example.com`,
48
- * text: 'Your website is great! Learnt a lot :-)'
49
- * });
50
- *
51
- * actor.attemptsTo(
52
- * Send.a(PostRequest.to('/feedback').with(postData).using({
53
- * headers: {
54
- * 'Content-Type': 'application/x-www-form-urlencoded',
55
- * 'Content-Length': formData.length
56
- * }
57
- * })),
58
- * Ensure.that(LastResponse.status(), equals(200)),
59
- * Ensure.that(LastResponse.header('Location'), equals('/feedback/thank-you.html')),
60
- * );
61
- *
62
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
63
- * @see https://tools.ietf.org/html/rfc7231#section-4.3.3
64
- *
65
- * @extends {HTTPRequest}
66
- */
67
- export class PostRequest extends HTTPRequest {
68
-
69
- /**
70
- * @desc
71
- * Configures the object with a destination URI.
72
- *
73
- * When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
74
- * it gets concatenated with the URL provided to the Axios instance
75
- * when the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
76
- *
77
- * @param {@serenity-js/core/lib/screenplay~Answerable<string>} resourceUri
78
- * The URI where the {@link @serenity-js/core/lib/screenplay/actor~Actor}
79
- * should send the {@link HTTPRequest}.
80
- *
81
- * @returns {PostRequest}
82
- */
83
- static to(resourceUri: Answerable<string>): PostRequest {
84
- return new PostRequest(resourceUri);
85
- }
86
-
87
- /**
88
- * @desc
89
- * Configures the object with a request body.
90
- *
91
- * @param {@serenity-js/core/lib/screenplay~Answerable<any>} data
92
- * Data to be sent to the `resourceUri`
93
- *
94
- * @returns {PostRequest}
95
- */
96
- with(data: Answerable<any>): PostRequest {
97
- return new PostRequest(this.resourceUri, data, this.config);
98
- }
99
-
100
- /**
101
- * @desc
102
- * Overrides the default Axios request configuration provided
103
- * when {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
104
- *
105
- * @param {@serenity-js/core/lib/screenplay~Answerable<AxiosRequestConfig>} config
106
- * Axios request configuration overrides
107
- *
108
- * @returns {PostRequest}
109
- */
110
- using(config: Answerable<AxiosRequestConfig>): PostRequest {
111
- return new PostRequest(this.resourceUri, this.data, config);
112
- }
113
- }
@@ -1,86 +0,0 @@
1
- import { Answerable } from '@serenity-js/core';
2
- import { AxiosRequestConfig } from 'axios';
3
-
4
- import { HTTPRequest } from './HTTPRequest';
5
-
6
- /**
7
- * @desc
8
- * The PUT method requests that the state of the target resource be
9
- * created or replaced with the state defined by the representation
10
- * enclosed in the request message payload.
11
- *
12
- * PUT request should be used when you want to create
13
- * a new resource at a known `resourceUri` (e.g. `/books/0-688-00230-7`)
14
- * or replace an existing resource at such `resourceUri`.
15
- *
16
- * PUT request is [idempotent](https://developer.mozilla.org/en-US/docs/Glossary/Idempotent):
17
- * calling it once or several times successively has the same effect (that is no _side effect_).
18
- *
19
- * @example <caption>Create a new resource at a known location</caption>
20
- * import { Actor } from '@serenity-js/core';
21
- * import { CallAnApi, LastResponse, PutRequest, Send } from '@serenity-js/rest'
22
- * import { Ensure, equals } from '@serenity-js/assertions';
23
- *
24
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
25
- *
26
- * actor.attemptsTo(
27
- * Send.a(PutRequest.to('/books/0-688-00230-7').with({
28
- * isbn: '0-688-00230-7',
29
- * title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
30
- * author: 'Robert M. Pirsig',
31
- * })),
32
- * Ensure.that(LastResponse.status(), equals(201)),
33
- * );
34
- *
35
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT
36
- * @see https://tools.ietf.org/html/rfc7231#section-4.3.4
37
- *
38
- * @extends {HTTPRequest}
39
- */
40
- export class PutRequest extends HTTPRequest {
41
-
42
- /**
43
- * @desc
44
- * Configures the object with a destination URI.
45
- *
46
- * When the `resourceUri` is not a fully qualified URL but a path, such as `/products/2`,
47
- * it gets concatenated with the URL provided to the Axios instance
48
- * when the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
49
- *
50
- * @param {@serenity-js/core/lib/screenplay~Answerable<string>} resourceUri
51
- * The URI where the {@link @serenity-js/core/lib/screenplay/actor~Actor}
52
- * should send the {@link HTTPRequest}.
53
- *
54
- * @returns {PutRequest}
55
- */
56
- static to(resourceUri: Answerable<string>): PutRequest {
57
- return new PutRequest(resourceUri);
58
- }
59
-
60
- /**
61
- * @desc
62
- * Configures the object with a request body.
63
- *
64
- * @param {@serenity-js/core/lib/screenplay~Answerable<any>} data
65
- * Data to be sent to the `resourceUri`
66
- *
67
- * @returns {PutRequest}
68
- */
69
- with(data: Answerable<any>): PutRequest {
70
- return new PutRequest(this.resourceUri, data, this.config);
71
- }
72
-
73
- /**
74
- * @desc
75
- * Overrides the default Axios request configuration provided
76
- * when {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability} was instantiated.
77
- *
78
- * @param {@serenity-js/core/lib/screenplay~Answerable<AxiosRequestConfig>} config
79
- * Axios request configuration overrides
80
- *
81
- * @returns {PutRequest}
82
- */
83
- using(config: Answerable<AxiosRequestConfig>): PutRequest {
84
- return new PutRequest(this.resourceUri, this.data, config);
85
- }
86
- }
@@ -1,97 +0,0 @@
1
- import { Answerable, AnswersQuestions, CollectsArtifacts, Interaction, UsesAbilities } from '@serenity-js/core';
2
-
3
- import { CallAnApi } from '../abilities';
4
-
5
- /**
6
- * @desc
7
- * Changes the base URL the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability}
8
- * has been configured with. Useful when we don't know the URL before the test is started,
9
- * for example when the URL is dynamically generated and needs to be read from the website under test.
10
- *
11
- * @example <caption>Changing the API URL</caption>
12
- * import { Actor } from '@serenity-js/core';
13
- * import { Navigate, Target, Text } from '@serenity-js/protractor';
14
- * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
15
- * import { protractor, by } from 'protractor';
16
- *
17
- * import axios from 'axios';
18
- *
19
- * const actor = Actor.named('Apisit').whoCan(
20
- * BrowseTheWeb.using(protractor.browser),
21
- *
22
- * // Note: no default base URL is given when the axios instance is created
23
- * CallAnApi.using(axios.create()),
24
- * );
25
- *
26
- * // Let's imagine that the website under test displays
27
- * // a dynamically generated API URL we'd like to use
28
- * const ApiDetailsWidget = {
29
- * Url: Target.the('API URL').located(by.id('api-url')),
30
- * }
31
- *
32
- * actor.attemptsTo(
33
- * Navigate.to('/profile'),
34
- *
35
- * // We change the API URL based on the text displayed in the widget
36
- * // (although we could change it to some arbitrary string too).
37
- * ChangeApiUrl.to(Text.of(ApiDetailsWidget.Url)),
38
- *
39
- * // Any subsequent request will be sent to the newly set URL
40
- * Send.a(GetRequest.to('/projects')),
41
- * Ensure.that(LastResponse.status(), equals(200)),
42
- * );
43
- *
44
- * @deprecated Use ChangeApiConfig.setUrlTo(newUrl) instead
45
- *
46
- * @see {@link ChangeApiConfig}
47
- *
48
- * @extends {@serenity-js/core/lib/screenplay~Interaction}
49
- */
50
- export class ChangeApiUrl extends Interaction {
51
-
52
- /**
53
- * @desc
54
- * Instantiates a new {@link ChangeApiUrl} {@link @serenity-js/core/lib/screenplay~Interaction}.
55
- *
56
- * @param {@serenity-js/core/lib/screenplay~Answerable<string>} newApiUrl
57
- * @returns {@serenity-js/core/lib/screenplay~Interaction}
58
- */
59
- static to(newApiUrl: Answerable<string>): Interaction {
60
- return new ChangeApiUrl(newApiUrl);
61
- }
62
-
63
- /**
64
- * @param {@serenity-js/core/lib/screenplay~Answerable<string>} newApiUrl
65
- */
66
- constructor(private readonly newApiUrl: Answerable<string>) {
67
- super();
68
- }
69
-
70
- /**
71
- * @desc
72
- * Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
73
- * perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
74
- *
75
- * @param {UsesAbilities & CollectsArtifacts & AnswersQuestions} actor
76
- * @returns {Promise<void>}
77
- *
78
- * @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
79
- * @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
80
- * @see {@link @serenity-js/core/lib/screenplay/actor~CollectsArtifacts}
81
- * @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
82
- */
83
- performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void> {
84
- return actor.answer(this.newApiUrl)
85
- .then(newApiUrl => CallAnApi.as(actor).modifyConfig(config => config.baseURL = newApiUrl));
86
- }
87
-
88
- /**
89
- * @desc
90
- * Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
91
- *
92
- * @returns {string}
93
- */
94
- toString(): string {
95
- return `#actor changes the API URL to ${ this.newApiUrl.toString() }`;
96
- }
97
- }
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig",
3
- "include": [
4
- "src/**/*.ts",
5
- "spec/**/*.ts"
6
- ],
7
- "exclude": [
8
- "node_modules"
9
- ]
10
- }
File without changes