88 */
99
1010import { Assert } from '@japa/assert'
11- import { Macroable } from '@athenna/common'
11+ import { Json , Macroable } from '@athenna/common'
1212import type { Response } from 'light-my-request'
1313
1414export class TestResponse extends Macroable {
@@ -104,7 +104,13 @@ export class TestResponse extends Macroable {
104104 * ```
105105 */
106106 public assertBodyContainsKey ( key : string ) {
107- this . assert . property ( this . response . json ( ) , key )
107+ const body = this . response . json ( )
108+ const value = Json . get ( body , key )
109+
110+ this . assert . assert (
111+ value !== undefined ,
112+ `The body does not contain the key ${ key } `
113+ )
108114 }
109115
110116 /**
@@ -124,7 +130,10 @@ export class TestResponse extends Macroable {
124130 * ```
125131 */
126132 public assertBodyNotContainsKey ( key : string ) {
127- this . assert . notProperty ( this . response . json ( ) , key )
133+ const body = this . response . json ( )
134+ const value = Json . get ( body , key )
135+
136+ this . assert . assert ( value === undefined , `The body contains the key ${ key } ` )
128137 }
129138
130139 /**
@@ -138,7 +147,22 @@ export class TestResponse extends Macroable {
138147 * ```
139148 */
140149 public assertBodyContainsAllKeys ( keys : string [ ] ) {
141- this . assert . properties ( this . response . json ( ) , keys )
150+ const body = this . response . json ( )
151+ const seenKeys = new Set ( )
152+
153+ for ( const key of keys ) {
154+ const value = Json . get ( body , key )
155+
156+ if ( value !== undefined ) {
157+ seenKeys . add ( key )
158+ }
159+ }
160+
161+ if ( seenKeys . size !== keys . length ) {
162+ return this . assert . fail (
163+ `The body does not contain all keys: ${ keys . join ( ', ' ) } `
164+ )
165+ }
142166 }
143167
144168 /**
@@ -158,7 +182,21 @@ export class TestResponse extends Macroable {
158182 * ```
159183 */
160184 public assertBodyNotContainsAllKeys ( keys : string [ ] ) {
161- this . assert . notAllProperties ( this . response . json ( ) , keys )
185+ const body = this . response . json ( )
186+ const seenKeys = new Set ( )
187+
188+ for ( const key of keys ) {
189+ const value = Json . get ( body , key )
190+
191+ if ( value !== undefined ) {
192+ seenKeys . add ( key )
193+ }
194+ }
195+
196+ this . assert . assert (
197+ seenKeys . size ,
198+ `The body contains keys: ${ keys . join ( ', ' ) } `
199+ )
162200 }
163201
164202 /**
0 commit comments