@athenna/http 5.33.0 → 5.35.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.33.0",
3
+ "version": "5.35.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>",
@@ -162,13 +162,14 @@ export class HttpKernel {
162
162
  debug('Not able to register http request logger. Enable it in your http.logger.enabled configuration.');
163
163
  return;
164
164
  }
165
- const { channel, isToLogRequest } = Config.get('http.logger');
165
+ const channel = Config.get('http.logger.channel', 'request');
166
+ const isToLogRequest = Config.get('http.logger.isToLogRequest');
166
167
  Server.terminate(ctx => {
167
168
  if (!isToLogRequest) {
168
- return Log.channelOrVanilla(channel || 'request').info(ctx);
169
+ return Log.channelOrVanilla(channel).info(ctx);
169
170
  }
170
171
  if (isToLogRequest(ctx)) {
171
- return Log.channelOrVanilla(channel || 'request').info(ctx);
172
+ return Log.channelOrVanilla(channel).info(ctx);
172
173
  }
173
174
  });
174
175
  }
@@ -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[]): void;
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.assert.property(this.response.json(), key);
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.assert.notProperty(this.response.json(), key);
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.assert.properties(this.response.json(), keys);
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.assert.notAllProperties(this.response.json(), keys);
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: ${keys.join(', ')}`);
140
162
  }
141
163
  /**
142
164
  * Assert body (array or object) to be deep equal to the expected value.