@athenna/http 5.25.0 → 5.27.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
|
@@ -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,15 @@ export class TestRequest extends Macroable {
|
|
|
35
39
|
* ```
|
|
36
40
|
*/
|
|
37
41
|
async get(url, options = {}) {
|
|
38
|
-
|
|
42
|
+
options.headers = {
|
|
43
|
+
...this.headers,
|
|
44
|
+
...options.headers
|
|
45
|
+
};
|
|
46
|
+
return Server.request({
|
|
47
|
+
url,
|
|
48
|
+
method: 'GET',
|
|
49
|
+
...options
|
|
50
|
+
}).then(res => this.createResponse(res));
|
|
39
51
|
}
|
|
40
52
|
/**
|
|
41
53
|
* Make a HEAD request to the given URL and options.
|
|
@@ -48,7 +60,15 @@ export class TestRequest extends Macroable {
|
|
|
48
60
|
* ```
|
|
49
61
|
*/
|
|
50
62
|
async head(url, options = {}) {
|
|
51
|
-
|
|
63
|
+
options.headers = {
|
|
64
|
+
...this.headers,
|
|
65
|
+
...options.headers
|
|
66
|
+
};
|
|
67
|
+
return Server.request({
|
|
68
|
+
url,
|
|
69
|
+
method: 'HEAD',
|
|
70
|
+
...options
|
|
71
|
+
}).then(res => this.createResponse(res));
|
|
52
72
|
}
|
|
53
73
|
/**
|
|
54
74
|
* Make a OPTIONS request to the given URL and options.
|
|
@@ -61,7 +81,15 @@ export class TestRequest extends Macroable {
|
|
|
61
81
|
* ```
|
|
62
82
|
*/
|
|
63
83
|
async options(url, options = {}) {
|
|
64
|
-
|
|
84
|
+
options.headers = {
|
|
85
|
+
...this.headers,
|
|
86
|
+
...options.headers
|
|
87
|
+
};
|
|
88
|
+
return Server.request({
|
|
89
|
+
url,
|
|
90
|
+
method: 'OPTIONS',
|
|
91
|
+
...options
|
|
92
|
+
}).then(res => this.createResponse(res));
|
|
65
93
|
}
|
|
66
94
|
/**
|
|
67
95
|
* Make a POST request to the given URL and options.
|
|
@@ -74,7 +102,15 @@ export class TestRequest extends Macroable {
|
|
|
74
102
|
* ```
|
|
75
103
|
*/
|
|
76
104
|
async post(url, options = {}) {
|
|
77
|
-
|
|
105
|
+
options.headers = {
|
|
106
|
+
...this.headers,
|
|
107
|
+
...options.headers
|
|
108
|
+
};
|
|
109
|
+
return Server.request({
|
|
110
|
+
url,
|
|
111
|
+
method: 'POST',
|
|
112
|
+
...options
|
|
113
|
+
}).then(res => this.createResponse(res));
|
|
78
114
|
}
|
|
79
115
|
/**
|
|
80
116
|
* Make a PUT request to the given URL and options.
|
|
@@ -87,7 +123,15 @@ export class TestRequest extends Macroable {
|
|
|
87
123
|
* ```
|
|
88
124
|
*/
|
|
89
125
|
async put(url, options = {}) {
|
|
90
|
-
|
|
126
|
+
options.headers = {
|
|
127
|
+
...this.headers,
|
|
128
|
+
...options.headers
|
|
129
|
+
};
|
|
130
|
+
return Server.request({
|
|
131
|
+
url,
|
|
132
|
+
method: 'PUT',
|
|
133
|
+
...options
|
|
134
|
+
}).then(res => this.createResponse(res));
|
|
91
135
|
}
|
|
92
136
|
/**
|
|
93
137
|
* Make a PATCH request to the given URL and options.
|
|
@@ -100,7 +144,15 @@ export class TestRequest extends Macroable {
|
|
|
100
144
|
* ```
|
|
101
145
|
*/
|
|
102
146
|
async patch(url, options = {}) {
|
|
103
|
-
|
|
147
|
+
options.headers = {
|
|
148
|
+
...this.headers,
|
|
149
|
+
...options.headers
|
|
150
|
+
};
|
|
151
|
+
return Server.request({
|
|
152
|
+
url,
|
|
153
|
+
method: 'PATCH',
|
|
154
|
+
...options
|
|
155
|
+
}).then(res => this.createResponse(res));
|
|
104
156
|
}
|
|
105
157
|
/**
|
|
106
158
|
* Make a DELETE request to the given URL and options.
|
|
@@ -113,6 +165,29 @@ export class TestRequest extends Macroable {
|
|
|
113
165
|
* ```
|
|
114
166
|
*/
|
|
115
167
|
async delete(url, options = {}) {
|
|
116
|
-
|
|
168
|
+
options.headers = {
|
|
169
|
+
...this.headers,
|
|
170
|
+
...options.headers
|
|
171
|
+
};
|
|
172
|
+
return Server.request({
|
|
173
|
+
url,
|
|
174
|
+
method: 'DELETE',
|
|
175
|
+
...options
|
|
176
|
+
}).then(res => this.createResponse(res));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Define the authorization access token into all requests.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```js
|
|
183
|
+
* const token ='Bearer ...'
|
|
184
|
+
* const response = await request.authorize(token).get('/users')
|
|
185
|
+
*
|
|
186
|
+
* response.assertStatusCode(200)
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
authorize(accessToken) {
|
|
190
|
+
this.headers.authorization = accessToken;
|
|
191
|
+
return this;
|
|
117
192
|
}
|
|
118
193
|
}
|