diff --git a/package-lock.json b/package-lock.json index 81d73a7..0a67866 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/http", - "version": "5.34.0", + "version": "5.35.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/http", - "version": "5.34.0", + "version": "5.35.0", "license": "MIT", "devDependencies": { "@athenna/artisan": "^5.7.0", diff --git a/package.json b/package.json index 5bffbd0..1650e52 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/http", - "version": "5.34.0", + "version": "5.35.0", "description": "The Athenna Http server. Built on top of fastify.", "license": "MIT", "author": "João Lenon ", diff --git a/src/testing/plugins/request/TestResponse.ts b/src/testing/plugins/request/TestResponse.ts index e34e99a..4c84a0e 100644 --- a/src/testing/plugins/request/TestResponse.ts +++ b/src/testing/plugins/request/TestResponse.ts @@ -8,7 +8,7 @@ */ import { Assert } from '@japa/assert' -import { Macroable } from '@athenna/common' +import { Json, Macroable } from '@athenna/common' import type { Response } from 'light-my-request' export class TestResponse extends Macroable { @@ -104,7 +104,13 @@ export class TestResponse extends Macroable { * ``` */ public assertBodyContainsKey(key: string) { - this.assert.property(this.response.json(), key) + const body = this.response.json() + const value = Json.get(body, key) + + this.assert.assert( + value !== undefined, + `The body does not contain the key ${key}` + ) } /** @@ -124,7 +130,10 @@ export class TestResponse extends Macroable { * ``` */ public assertBodyNotContainsKey(key: string) { - this.assert.notProperty(this.response.json(), key) + const body = this.response.json() + const value = Json.get(body, key) + + this.assert.assert(value === undefined, `The body contains the key ${key}`) } /** @@ -138,7 +147,22 @@ export class TestResponse extends Macroable { * ``` */ public assertBodyContainsAllKeys(keys: string[]) { - this.assert.properties(this.response.json(), keys) + const body = this.response.json() + const seenKeys = new Set() + + for (const key of keys) { + const value = Json.get(body, key) + + if (value !== undefined) { + seenKeys.add(key) + } + } + + if (seenKeys.size !== keys.length) { + return this.assert.fail( + `The body does not contain all keys: ${keys.join(', ')}` + ) + } } /** @@ -158,7 +182,21 @@ export class TestResponse extends Macroable { * ``` */ public assertBodyNotContainsAllKeys(keys: string[]) { - this.assert.notAllProperties(this.response.json(), keys) + const body = this.response.json() + const seenKeys = new Set() + + for (const key of keys) { + const value = Json.get(body, key) + + if (value !== undefined) { + seenKeys.add(key) + } + } + + this.assert.assert( + seenKeys.size, + `The body contains keys: ${keys.join(', ')}` + ) } /**