@athenna/http 5.34.0 → 5.36.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
|
@@ -109,7 +109,7 @@ export declare class TestResponse extends Macroable {
|
|
|
109
109
|
* response.assertBodyContainsAllKeys(['id', 'post']) // passes
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
|
-
assertBodyContainsAllKeys(keys: string[]):
|
|
112
|
+
assertBodyContainsAllKeys(keys: string[]): never;
|
|
113
113
|
/**
|
|
114
114
|
* Assert body to not contain all keys.
|
|
115
115
|
*
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Assert } from '@japa/assert';
|
|
10
|
-
import { Macroable } from '@athenna/common';
|
|
10
|
+
import { Json, Macroable } from '@athenna/common';
|
|
11
11
|
export class TestResponse extends Macroable {
|
|
12
12
|
constructor(assert, response) {
|
|
13
13
|
super();
|
|
@@ -85,7 +85,9 @@ export class TestResponse extends Macroable {
|
|
|
85
85
|
* ```
|
|
86
86
|
*/
|
|
87
87
|
assertBodyContainsKey(key) {
|
|
88
|
-
this.
|
|
88
|
+
const body = this.response.json();
|
|
89
|
+
const value = Json.get(body, key);
|
|
90
|
+
this.assert.assert(value !== undefined, `The body does not contain the key ${key}`);
|
|
89
91
|
}
|
|
90
92
|
/**
|
|
91
93
|
* Assert body to not contain a key.
|
|
@@ -104,7 +106,9 @@ export class TestResponse extends Macroable {
|
|
|
104
106
|
* ```
|
|
105
107
|
*/
|
|
106
108
|
assertBodyNotContainsKey(key) {
|
|
107
|
-
this.
|
|
109
|
+
const body = this.response.json();
|
|
110
|
+
const value = Json.get(body, key);
|
|
111
|
+
this.assert.assert(value === undefined, `The body contains the key ${key}`);
|
|
108
112
|
}
|
|
109
113
|
/**
|
|
110
114
|
* Assert body to contain all keys.
|
|
@@ -117,7 +121,17 @@ export class TestResponse extends Macroable {
|
|
|
117
121
|
* ```
|
|
118
122
|
*/
|
|
119
123
|
assertBodyContainsAllKeys(keys) {
|
|
120
|
-
this.
|
|
124
|
+
const body = this.response.json();
|
|
125
|
+
const seenKeys = new Set();
|
|
126
|
+
for (const key of keys) {
|
|
127
|
+
const value = Json.get(body, key);
|
|
128
|
+
if (value !== undefined) {
|
|
129
|
+
seenKeys.add(key);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (seenKeys.size !== keys.length) {
|
|
133
|
+
return this.assert.fail(`The body does not contain all keys: ${keys.join(', ')}`);
|
|
134
|
+
}
|
|
121
135
|
}
|
|
122
136
|
/**
|
|
123
137
|
* Assert body to not contain all keys.
|
|
@@ -136,7 +150,15 @@ export class TestResponse extends Macroable {
|
|
|
136
150
|
* ```
|
|
137
151
|
*/
|
|
138
152
|
assertBodyNotContainsAllKeys(keys) {
|
|
139
|
-
this.
|
|
153
|
+
const body = this.response.json();
|
|
154
|
+
const seenKeys = new Set();
|
|
155
|
+
for (const key of keys) {
|
|
156
|
+
const value = Json.get(body, key);
|
|
157
|
+
if (value !== undefined) {
|
|
158
|
+
seenKeys.add(key);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
this.assert.assert(!seenKeys.size, `The body contains keys: ${Array.from(seenKeys).join(', ')}`);
|
|
140
162
|
}
|
|
141
163
|
/**
|
|
142
164
|
* Assert body (array or object) to be deep equal to the expected value.
|