@athenna/http 5.25.0 → 5.26.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/http",
3
- "version": "5.25.0",
3
+ "version": "5.26.0",
4
4
  "description": "The Athenna Http server. Built on top of fastify.",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -11,6 +11,10 @@ import { Macroable } from '@athenna/common';
11
11
  import type { InjectOptions } from '#src/types';
12
12
  import { TestResponse } from '#src/testing/plugins/request/TestResponse';
13
13
  export declare class TestRequest extends Macroable {
14
+ /**
15
+ * Headers that will be defined in all requests.
16
+ */
17
+ private headers;
14
18
  /**
15
19
  * Japa assert class instance.
16
20
  */
@@ -96,4 +100,16 @@ export declare class TestRequest extends Macroable {
96
100
  * ```
97
101
  */
98
102
  delete(url: string, options?: InjectOptions): Promise<TestResponse>;
103
+ /**
104
+ * Define the authorization access token into all requests.
105
+ *
106
+ * @example
107
+ * ```js
108
+ * const token ='Bearer ...'
109
+ * const response = await request.authorize(token).get('/users')
110
+ *
111
+ * response.assertStatusCode(200)
112
+ * ```
113
+ */
114
+ authorize(accessToken: string): this;
99
115
  }
@@ -13,6 +13,10 @@ import { TestResponse } from '#src/testing/plugins/request/TestResponse';
13
13
  export class TestRequest extends Macroable {
14
14
  constructor() {
15
15
  super(...arguments);
16
+ /**
17
+ * Headers that will be defined in all requests.
18
+ */
19
+ this.headers = {};
16
20
  /**
17
21
  * Japa assert class instance.
18
22
  */
@@ -35,7 +39,12 @@ export class TestRequest extends Macroable {
35
39
  * ```
36
40
  */
37
41
  async get(url, options = {}) {
38
- return Server.request({ url, method: 'GET', ...options }).then(res => this.createResponse(res));
42
+ return Server.request({
43
+ url,
44
+ method: 'GET',
45
+ ...this.headers,
46
+ ...options
47
+ }).then(res => this.createResponse(res));
39
48
  }
40
49
  /**
41
50
  * Make a HEAD request to the given URL and options.
@@ -48,7 +57,12 @@ export class TestRequest extends Macroable {
48
57
  * ```
49
58
  */
50
59
  async head(url, options = {}) {
51
- return Server.request({ url, method: 'HEAD', ...options }).then(res => this.createResponse(res));
60
+ return Server.request({
61
+ url,
62
+ method: 'HEAD',
63
+ ...this.headers,
64
+ ...options
65
+ }).then(res => this.createResponse(res));
52
66
  }
53
67
  /**
54
68
  * Make a OPTIONS request to the given URL and options.
@@ -61,7 +75,12 @@ export class TestRequest extends Macroable {
61
75
  * ```
62
76
  */
63
77
  async options(url, options = {}) {
64
- return Server.request({ url, method: 'OPTIONS', ...options }).then(res => this.createResponse(res));
78
+ return Server.request({
79
+ url,
80
+ method: 'OPTIONS',
81
+ ...this.headers,
82
+ ...options
83
+ }).then(res => this.createResponse(res));
65
84
  }
66
85
  /**
67
86
  * Make a POST request to the given URL and options.
@@ -74,7 +93,12 @@ export class TestRequest extends Macroable {
74
93
  * ```
75
94
  */
76
95
  async post(url, options = {}) {
77
- return Server.request({ url, method: 'POST', ...options }).then(res => this.createResponse(res));
96
+ return Server.request({
97
+ url,
98
+ method: 'POST',
99
+ ...this.headers,
100
+ ...options
101
+ }).then(res => this.createResponse(res));
78
102
  }
79
103
  /**
80
104
  * Make a PUT request to the given URL and options.
@@ -87,7 +111,12 @@ export class TestRequest extends Macroable {
87
111
  * ```
88
112
  */
89
113
  async put(url, options = {}) {
90
- return Server.request({ url, method: 'PUT', ...options }).then(res => this.createResponse(res));
114
+ return Server.request({
115
+ url,
116
+ method: 'PUT',
117
+ ...this.headers,
118
+ ...options
119
+ }).then(res => this.createResponse(res));
91
120
  }
92
121
  /**
93
122
  * Make a PATCH request to the given URL and options.
@@ -100,7 +129,12 @@ export class TestRequest extends Macroable {
100
129
  * ```
101
130
  */
102
131
  async patch(url, options = {}) {
103
- return Server.request({ url, method: 'PATCH', ...options }).then(res => this.createResponse(res));
132
+ return Server.request({
133
+ url,
134
+ method: 'PATCH',
135
+ ...this.headers,
136
+ ...options
137
+ }).then(res => this.createResponse(res));
104
138
  }
105
139
  /**
106
140
  * Make a DELETE request to the given URL and options.
@@ -113,6 +147,26 @@ export class TestRequest extends Macroable {
113
147
  * ```
114
148
  */
115
149
  async delete(url, options = {}) {
116
- return Server.request({ url, method: 'DELETE', ...options }).then(res => this.createResponse(res));
150
+ return Server.request({
151
+ url,
152
+ method: 'DELETE',
153
+ ...this.headers,
154
+ ...options
155
+ }).then(res => this.createResponse(res));
156
+ }
157
+ /**
158
+ * Define the authorization access token into all requests.
159
+ *
160
+ * @example
161
+ * ```js
162
+ * const token ='Bearer ...'
163
+ * const response = await request.authorize(token).get('/users')
164
+ *
165
+ * response.assertStatusCode(200)
166
+ * ```
167
+ */
168
+ authorize(accessToken) {
169
+ this.headers.authorization = accessToken;
170
+ return this;
117
171
  }
118
172
  }