@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.
Files changed (127) hide show
  1. package/CHANGELOG.md +80 -1851
  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,64 +1,47 @@
1
1
  import { Answerable, AnswersQuestions, CollectsArtifacts, Interaction, UsesAbilities } from '@serenity-js/core';
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  /**
4
- * @desc
5
- * Sends a {@link HTTPRequest} to a specified url.
6
- * The response to the request is made available via the {@link LastResponse}
7
- * {@link @serenity-js/core/lib/screenplay~Question}s.
4
+ * Sends a {@apilink HTTPRequest} to a specified url.
8
5
  *
9
- * @example <caption>Send a GET request</caption>
10
- * import { Actor } from '@serenity-js/core';
11
- * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
12
- * import { Ensure, equals } from '@serenity-js/assertions';
6
+ * The response to the request is made available via {@apilink LastResponse}.
13
7
  *
14
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
8
+ * ## Send a GET request
15
9
  *
16
- * actor.attemptsTo(
17
- * Send.a(GetRequest.to('/books/0-688-00230-7')),
18
- * Ensure.that(LastResponse.status(), equals(200)),
19
- * );
10
+ * ```ts
11
+ * import { actorCalled } from '@serenity-js/core'
12
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
13
+ * import { Ensure, equals } from '@serenity-js/assertions'
20
14
  *
21
- * @extends {Interaction}
15
+ * await actorCalled('Apisit')
16
+ * .whoCan(CallAnApi.at('https://api.example.org/'))
17
+ * .attemptsTo(
18
+ * Send.a(GetRequest.to('/books/0-688-00230-7')),
19
+ * Ensure.that(LastResponse.status(), equals(200)),
20
+ * )
21
+ * ```
22
+ *
23
+ * @group Activities
22
24
  */
23
25
  export declare class Send extends Interaction {
24
26
  private readonly request;
25
27
  /**
26
- * @desc
27
- * Instantiates a new {@link Send} {@link @serenity-js/core/lib/screenplay~Interaction}.
28
+ * Instantiates a new {@apilink Interaction|interaction} to {@apilink Send}.
28
29
  *
29
- * @param {@serenity-js/lib/core/screenplay~Answerable<AxiosRequestConfig>} request
30
- * @returns {@serenity-js/core/lib/screenplay~Interaction}
30
+ * #### Learn more
31
+ * - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
31
32
  *
32
- * @see {@link AxiosRequestConfig}
33
+ * @param request
33
34
  */
34
35
  static a(request: Answerable<AxiosRequestConfig>): Interaction;
35
36
  /**
36
- * @param {@serenity-js/core/lib/screenplay~Answerable<AxiosRequestConfig>} request
37
- *
38
- * @see {@link AxiosRequestConfig}
37
+ * @param request
39
38
  */
40
- constructor(request: Answerable<AxiosRequestConfig>);
39
+ protected constructor(request: Answerable<AxiosRequestConfig>);
41
40
  /**
42
- * @desc
43
- * Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
44
- * perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
45
- *
46
- * @param {UsesAbilities & CollectsArtifacts & AnswersQuestions} actor
47
- * @returns {Promise<void>}
48
- *
49
- * @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
50
- * @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
51
- * @see {@link @serenity-js/core/lib/screenplay/actor~CollectsArtifacts}
52
- * @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
41
+ * @inheritDoc
53
42
  */
54
43
  performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void>;
55
- /**
56
- * @desc
57
- * Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
58
- *
59
- * @returns {string}
60
- */
61
- toString(): string;
62
44
  private responseToArtifact;
63
45
  private requestToArtifactName;
64
46
  }
47
+ //# sourceMappingURL=Send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Send.d.ts","sourceRoot":"","sources":["../../../src/screenplay/interactions/Send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEhH,OAAO,EAAgB,kBAAkB,EAAgE,MAAM,OAAO,CAAC;AAIvH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,IAAK,SAAQ,WAAW;IAiBX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAf9C;;;;;;;OAOG;IACH,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC,GAAG,WAAW;IAI9D;;OAEG;IACH,SAAS,aAA8B,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC;IAI9E;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBrF,OAAO,CAAC,kBAAkB;IA0B1B,OAAO,CAAC,qBAAqB;CAGhC"}
@@ -3,61 +3,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Send = void 0;
4
4
  const core_1 = require("@serenity-js/core");
5
5
  const model_1 = require("@serenity-js/core/lib/model");
6
+ const axios_1 = require("axios");
6
7
  const abilities_1 = require("../abilities");
7
8
  /**
8
- * @desc
9
- * Sends a {@link HTTPRequest} to a specified url.
10
- * The response to the request is made available via the {@link LastResponse}
11
- * {@link @serenity-js/core/lib/screenplay~Question}s.
9
+ * Sends a {@apilink HTTPRequest} to a specified url.
12
10
  *
13
- * @example <caption>Send a GET request</caption>
14
- * import { Actor } from '@serenity-js/core';
15
- * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
16
- * import { Ensure, equals } from '@serenity-js/assertions';
11
+ * The response to the request is made available via {@apilink LastResponse}.
17
12
  *
18
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
13
+ * ## Send a GET request
19
14
  *
20
- * actor.attemptsTo(
21
- * Send.a(GetRequest.to('/books/0-688-00230-7')),
22
- * Ensure.that(LastResponse.status(), equals(200)),
23
- * );
15
+ * ```ts
16
+ * import { actorCalled } from '@serenity-js/core'
17
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
18
+ * import { Ensure, equals } from '@serenity-js/assertions'
24
19
  *
25
- * @extends {Interaction}
20
+ * await actorCalled('Apisit')
21
+ * .whoCan(CallAnApi.at('https://api.example.org/'))
22
+ * .attemptsTo(
23
+ * Send.a(GetRequest.to('/books/0-688-00230-7')),
24
+ * Ensure.that(LastResponse.status(), equals(200)),
25
+ * )
26
+ * ```
27
+ *
28
+ * @group Activities
26
29
  */
27
30
  class Send extends core_1.Interaction {
28
31
  /**
29
- * @param {@serenity-js/core/lib/screenplay~Answerable<AxiosRequestConfig>} request
32
+ * Instantiates a new {@apilink Interaction|interaction} to {@apilink Send}.
30
33
  *
31
- * @see {@link AxiosRequestConfig}
32
- */
33
- constructor(request) {
34
- super();
35
- this.request = request;
36
- }
37
- /**
38
- * @desc
39
- * Instantiates a new {@link Send} {@link @serenity-js/core/lib/screenplay~Interaction}.
40
- *
41
- * @param {@serenity-js/lib/core/screenplay~Answerable<AxiosRequestConfig>} request
42
- * @returns {@serenity-js/core/lib/screenplay~Interaction}
34
+ * #### Learn more
35
+ * - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
43
36
  *
44
- * @see {@link AxiosRequestConfig}
37
+ * @param request
45
38
  */
46
39
  static a(request) {
47
40
  return new Send(request);
48
41
  }
49
42
  /**
50
- * @desc
51
- * Makes the provided {@link @serenity-js/core/lib/screenplay/actor~Actor}
52
- * perform this {@link @serenity-js/core/lib/screenplay~Interaction}.
53
- *
54
- * @param {UsesAbilities & CollectsArtifacts & AnswersQuestions} actor
55
- * @returns {Promise<void>}
56
- *
57
- * @see {@link @serenity-js/core/lib/screenplay/actor~Actor}
58
- * @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
59
- * @see {@link @serenity-js/core/lib/screenplay/actor~CollectsArtifacts}
60
- * @see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions}
43
+ * @param request
44
+ */
45
+ constructor(request) {
46
+ super(`#actor sends ${request.toString()}`);
47
+ this.request = request;
48
+ }
49
+ /**
50
+ * @inheritDoc
61
51
  */
62
52
  performAs(actor) {
63
53
  const callAnApi = abilities_1.CallAnApi.as(actor);
@@ -67,26 +57,22 @@ class Send extends core_1.Interaction {
67
57
  actor.collect(this.responseToArtifact(resolvedUrl, response), this.requestToArtifactName(response.config.method, resolvedUrl));
68
58
  }));
69
59
  }
70
- /**
71
- * @desc
72
- * Generates a description to be used when reporting this {@link @serenity-js/core/lib/screenplay~Activity}.
73
- *
74
- * @returns {string}
75
- */
76
- toString() {
77
- return `#actor sends ${this.request.toString()}`;
78
- }
79
60
  responseToArtifact(targetUrl, response) {
80
- const request = response.config, requestAndResponse = {
61
+ const request = response.config;
62
+ const axiosRequestHeaders = request.headers;
63
+ const requestHeaders = axios_1.AxiosHeaders.from(axiosRequestHeaders).toJSON(true);
64
+ const axiosResponseHeaders = response.headers;
65
+ const responseHeaders = axios_1.AxiosHeaders.from(axiosResponseHeaders).toJSON(false);
66
+ const requestAndResponse = {
81
67
  request: {
82
68
  method: request.method,
83
69
  url: targetUrl,
84
- headers: request.headers,
70
+ headers: requestHeaders,
85
71
  data: request.data,
86
72
  },
87
73
  response: {
88
74
  status: response.status,
89
- headers: response.headers,
75
+ headers: responseHeaders,
90
76
  data: response.data,
91
77
  },
92
78
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Send.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/Send.ts"],"names":[],"mappings":";;;AAAA,4CAAgH;AAChH,uDAAsG;AAGtG,4CAAyC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,IAAK,SAAQ,kBAAW;IAejC;;;;OAIG;IACH,YAA6B,OAAuC;QAChE,KAAK,EAAE,CAAC;QADiB,YAAO,GAAP,OAAO,CAAgC;IAEpE,CAAC;IApBD;;;;;;;;OAQG;IACH,MAAM,CAAC,CAAC,CAAC,OAAuC;QAC5C,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAWD;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,KAA2D;QACjE,MAAM,SAAS,GAAG,qBAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;QAEtC,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;aAC5B,IAAI,CAAC,MAAM,CAAC,EAAE,CACX,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,QAAuB,EAAE,EAAE;YACvD,MAAM,WAAW,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAEjD,KAAK,CAAC,OAAO,CACT,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,QAAQ,CAAC,EAC9C,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAClE,CAAC;QACN,CAAC,CAAC,CACL,CAAC;IACV,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QACJ,OAAO,gBAAiB,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAG,EAAE,CAAC;IACvD,CAAC;IAEO,kBAAkB,CAAC,SAAiB,EAAE,QAAuB;QACjE,MACI,OAAO,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B,CAAC,MAAc,EAAE,GAAW;QACrD,OAAO,IAAI,YAAI,CAAC,GAAI,MAAM,CAAC,WAAW,EAAG,IAAK,GAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;CACJ;AArED,oBAqEC"}
@@ -1,3 +1,3 @@
1
1
  export * from './ChangeApiConfig';
2
- export * from './ChangeApiUrl';
3
2
  export * from './Send';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screenplay/interactions/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC"}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -11,6 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
17
  __exportStar(require("./ChangeApiConfig"), exports);
14
- __exportStar(require("./ChangeApiUrl"), exports);
15
18
  __exportStar(require("./Send"), exports);
16
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkC;AAClC,iDAA+B;AAC/B,yCAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/interactions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,yCAAuB"}
@@ -1,135 +1,189 @@
1
1
  import { QuestionAdapter } from '@serenity-js/core';
2
+ import { RawAxiosResponseHeaders } from 'axios';
2
3
  /**
3
- * @desc
4
- * Provides access to the properties of the last {@link AxiosResponse} object,
5
- * cached on the {@link CallAnApi} {@link @serenity-js/core/lib/screenplay~Ability}.
4
+ * Provides access to the properties of the last {@apilink AxiosResponse} object,
5
+ * cached on the {@apilink Ability|ability} to {@apilink CallAnApi}.
6
6
  *
7
- * @example <caption>Verify response to a GET request</caption>
8
- * import { Actor } from '@serenity-js/core';
9
- * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
10
- * import { Ensure, equals } from '@serenity-js/assertions';
7
+ * ## Verify response to a GET request
11
8
  *
12
- * interface Book {
13
- * title: string;
14
- * author: string
15
- * }
9
+ * ```ts
10
+ * import { actorCalled } from '@serenity-js/core'
11
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
12
+ * import { Ensure, equals } from '@serenity-js/assertions'
16
13
  *
17
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
14
+ * interface Book {
15
+ * title: string;
16
+ * author: string;
17
+ * }
18
18
  *
19
- * actor.attemptsTo(
20
- * Send.a(GetRequest.to('/books/0-688-00230-7')),
21
- * Ensure.that(LastResponse.status(), equals(200)),
22
- * Ensure.that(LastResponse.header('Content-Type'), equals('application/json')),
23
- * Ensure.that(LastResponse.body<Book>(), equals({
24
- * title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
25
- * author: 'Robert M. Pirsig',
26
- * })),
27
- * );
19
+ * await actorCalled('Apisit')
20
+ * .whoCan(CallAnApi.at('https://api.example.org/'))
21
+ * .attemptsTo(
22
+ * Send.a(GetRequest.to('/books/0-688-00230-7')),
23
+ * Ensure.that(LastResponse.status(), equals(200)),
24
+ * Ensure.that(LastResponse.header('Content-Type'), equals('application/json')),
25
+ * Ensure.that(LastResponse.body<Book>(), equals({
26
+ * title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
27
+ * author: 'Robert M. Pirsig',
28
+ * })),
29
+ * )
30
+ * ```
28
31
  *
29
- * @example <caption>Use Serenity/JS adapters to navigate complex response objects</caption>
30
- * import { Actor } from '@serenity-js/core';
31
- * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
32
- * import { Ensure, equals } from '@serenity-js/assertions';
32
+ * ## Use Serenity/JS adapters to navigate complex response objects
33
33
  *
34
- * interface Developer {
35
- * name: string;
36
- * id: string;
37
- * projects: Project[];
38
- * }
34
+ * ```ts
35
+ * import { actorCalled } from '@serenity-js/core'
36
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
37
+ * import { Ensure, equals } from '@serenity-js/assertions'
39
38
  *
40
- * interface Project {
41
- * name: string;
42
- * repoUrl: string;
43
- * }
39
+ * interface Developer {
40
+ * name: string;
41
+ * id: string;
42
+ * projects: Project[];
43
+ * }
44
44
  *
45
- * const actor = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
45
+ * interface Project {
46
+ * name: string;
47
+ * repoUrl: string;
48
+ * }
46
49
  *
47
- * actor.attemptsTo(
48
- * Send.a(GetRequest.to('/developers/jan-molak')),
49
- * Ensure.that(LastResponse.status(), equals(200)),
50
- * Ensure.that(LastResponse.body<Developer>().name, equals('Jan Molak')),
51
- * Ensure.that(LastResponse.body<Developer>().projects[0].name, equals('Serenity/JS')),
52
- * );
50
+ * await actorCalled('Apisitt')
51
+ * .whoCan(CallAnApi.at('https://api.example.org/'))
52
+ * .attemptsTo(
53
+ * Send.a(GetRequest.to('/developers/jan-molak')),
54
+ * Ensure.that(LastResponse.status(), equals(200)),
55
+ * Ensure.that(LastResponse.body<Developer>().name, equals('Jan Molak')),
56
+ * Ensure.that(LastResponse.body<Developer>().projects[0].name, equals('Serenity/JS')),
57
+ * )
58
+ * ```
59
+ *
60
+ * ## Learn more
61
+ * - [AxiosResponse](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L133-L140)
62
+ *
63
+ * @group Questions
53
64
  */
54
65
  export declare class LastResponse {
55
66
  /**
56
- * @desc
57
- * Enables asserting on the {@link LastResponse} status
67
+ * Retrieves the status code of the {@apilink LastResponse|last response}
58
68
  *
59
- * @returns {@serenity-js/core/lib/screenplay~Question<number>}
69
+ * #### Learn more
70
+ * - [HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
60
71
  */
61
72
  static status(): QuestionAdapter<number>;
62
73
  /**
63
- * @desc
64
- * Enables asserting on the {@link LastResponse} body
74
+ * Retrieves the body of the {@apilink LastResponse|last response}
75
+ *
76
+ * #### A type-safe approach using generics
65
77
  *
66
- * @example <caption>A type-safe approach using generics</caption>
67
- * interface Book {
68
- * title: string;
69
- * author: string
70
- * }
78
+ * ```ts
79
+ * import { actorCalled } from '@serenity-js/core'
80
+ * import { CallAnApi, LastResponse } from '@serenity-js/rest'
81
+ * import { Ensure, equals } from '@serenity-js/assertions'
71
82
  *
72
- * actor.attemptsTo(
83
+ * interface Book {
84
+ * title: string;
85
+ * author: string;
86
+ * }
87
+ *
88
+ * await actorCalled('Apisitt')
89
+ * .whoCan(CallAnApi.at('https://api.example.org/'))
90
+ * .attemptsTo(
73
91
  * // ...
92
+ *
93
+ * // note body<T>() parameterised with type "Book"
74
94
  * Ensure.that(LastResponse.body<Book>(), equals({
75
- * title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
76
- * author: 'Robert M. Pirsig',
95
+ * title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
96
+ * author: 'Robert M. Pirsig',
77
97
  * })),
78
- * );
98
+ * )
99
+ * ```
79
100
  *
80
- * @example <caption>A non-type-safe approach using `any`</caption>
81
- * actor.attemptsTo(
101
+ * ## A not type-safe approach using `any`
102
+ *
103
+ * ```ts
104
+ * import { actorCalled } from '@serenity-js/core'
105
+ * import { CallAnApi, LastResponse } from '@serenity-js/rest'
106
+ * import { Ensure, equals } from '@serenity-js/assertions'
107
+ *
108
+ * await actorCalled('Apisitt')
109
+ * .whoCan(CallAnApi.at('https://api.example.org/'))
110
+ * .attemptsTo(
82
111
  * // ...
112
+ *
113
+ * // note body<T>() parameterised with "any" or with no parameter is not type-safe!
83
114
  * Ensure.that(LastResponse.body<any>(), equals({
84
- * title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
85
- * author: 'Robert M. Pirsig',
115
+ * title: 'Zen and the Art of Motorcycle Maintenance: An Inquiry into Values',
116
+ * author: 'Robert M. Pirsig',
86
117
  * })),
87
- * );
88
- *
89
- * @example <caption>Retrieving an item at path using Property.of</caption>
90
- * import { Property } from '@serenity-js/core';
91
- *
92
- * actor.attemptsTo(
93
- * Ensure.that(
94
- * Property.of(LastResponse.body<Book>()).title,
95
- * equals('Zen and the Art of Motorcycle Maintenance: An Inquiry into Values'),
96
- * )
97
- * )
98
- *
99
- * @example <caption>Filtering response body using List</caption>
100
- * import { Property } from '@serenity-js/core';
101
- * import { property, startsWith } from '@serenity-js/assertions';
102
- *
103
- * actor.attemptsTo(
104
- * Ensure.that(
105
- * // imagine the API returns an array of books
106
- * List.of(LastResponse.body<Book[]>())
107
- * .where(Property.at<Book>().author, equals('Robert M. Pirsig'))
108
- * .first(),
109
- * property('title', startsWith('Zen and the Art of Motorcycle Maintenance')),
110
- * )
111
- * )
112
- *
113
- * @returns {@serenity-js/core/lib/screenplay~Question<any>}
114
- *
115
- * @see {@link @serenity-js/core/lib/screenplay/questions~Property}
116
- * @see {@link @serenity-js/core/lib/screenplay/questions~List}
118
+ * )
119
+ * ```
120
+ *
121
+ * ## Iterating over the items in the response body
122
+ *
123
+ * ```ts
124
+ * import { actorCalled } from '@serenity-js/core'
125
+ * import { CallAnApi, LastResponse } from '@serenity-js/rest'
126
+ * import { Ensure, equals } from '@serenity-js/assertions'
127
+ *
128
+ * interface Product {
129
+ * id: number;
130
+ * name: string;
131
+ * }
132
+ *
133
+ * await actorCalled('Apisitt')
134
+ * .whoCan(CallAnApi.at('https://api.example.org/'))
135
+ * .attemptsTo(
136
+ * Send.a(GetRequest.to(`/products`)),
137
+ * List.of<Product>(LastResponse.body<{ products: Product[] }>().products)
138
+ * .forEach(({ item, actor }) =>
139
+ * actor.attemptsTo(
140
+ * Send.a(GetRequest.to(`/products/${ item.id }`)),
141
+ * Ensure.that(LastResponse.body<Product>().id, equals(item.id)),
142
+ * )
143
+ * ),
144
+ * )
145
+ * ```
117
146
  */
118
147
  static body<T = any>(): QuestionAdapter<T>;
119
148
  /**
120
- * @desc
121
- * Enables asserting on one of the {@link LastResponse}'s headers
149
+ * Retrieves a header of the {@apilink LastResponse|last response}, identified by `name`
150
+ *
151
+ * ## Asserting on a header
122
152
  *
123
- * @param {string} name
124
- * @returns {@serenity-js/core/lib/screenplay~Question<string>}
153
+ * ```ts
154
+ * import { actorCalled } from '@serenity-js/core'
155
+ * import { CallAnApi, LastResponse } from '@serenity-js/rest'
156
+ * import { Ensure, equals } from '@serenity-js/assertions'
157
+ *
158
+ * await actorCalled('Apisitt')
159
+ * .whoCan(CallAnApi.at('https://api.example.org/'))
160
+ * .attemptsTo(
161
+ * Send.a(GetRequest.to(`/products`)),
162
+ * Ensure.that(LastResponse.header('Content-Type'), equals('application/json')),
163
+ * )
164
+ * ```
165
+ *
166
+ * @param name
125
167
  */
126
168
  static header(name: string): QuestionAdapter<string>;
127
169
  /**
128
- * @desc
129
- * Enables asserting on all of the {@link LastResponse}'s headers,
130
- * returned as an object where the keys represent header names.
170
+ * Retrieves all the headers of the {@apilink LastResponse|last response}.
171
+ *
172
+ * ## Asserting on a header
173
+ *
174
+ * ```ts
175
+ * import { actorCalled } from '@serenity-js/core'
176
+ * import { CallAnApi, LastResponse } from '@serenity-js/rest'
177
+ * import { Ensure, equals } from '@serenity-js/assertions'
131
178
  *
132
- * @returns {@serenity-js/core/lib/screenplay~Question<Record<string, string>>}
179
+ * await actorCalled('Apisitt')
180
+ * .whoCan(CallAnApi.at('https://api.example.org/'))
181
+ * .attemptsTo(
182
+ * Send.a(GetRequest.to(`/products`)),
183
+ * Ensure.that(LastResponse.headers()['Content-Type'], equals('application/json')),
184
+ * )
185
+ * ```
133
186
  */
134
- static headers(): QuestionAdapter<Record<string, string>>;
187
+ static headers(): QuestionAdapter<RawAxiosResponseHeaders>;
135
188
  }
189
+ //# sourceMappingURL=LastResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LastResponse.d.ts","sourceRoot":"","sources":["../../../src/screenplay/questions/LastResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AAIhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,qBAAa,YAAY;IAErB;;;;;OAKG;IACH,MAAM,CAAC,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC;IAMxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyEG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,GAAG,KAAK,eAAe,CAAC,CAAC,CAAC;IAM1C;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IAMpD;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,OAAO,IAAI,eAAe,CAAC,uBAAuB,CAAC;CAK7D"}