@tryghost/express-test 0.4.1 → 0.4.2

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.
@@ -122,6 +122,11 @@ class ExpectRequest extends Request {
122
122
  const {error} = assertion;
123
123
 
124
124
  error.message = `Expected statusCode ${assertion.expected}, got statusCode ${response.statusCode} ${error.contextString}`;
125
+
126
+ if (response.body && response.body.errors && response.body.errors[0].message) {
127
+ error.message += `\n${response.body.errors[0].message}`;
128
+ }
129
+
125
130
  error.actual = response.statusCode;
126
131
 
127
132
  assert.equal(response.statusCode, assertion.expected, error);
package/lib/request.js CHANGED
@@ -1,13 +1,14 @@
1
1
  const {default: reqresnext} = require('reqresnext');
2
2
  const {CookieAccessInfo} = require('cookiejar');
3
3
  const {parse} = require('url');
4
- const {isJSON} = require('./utils');
4
+ const {isJSON, convertKeysToLowerCase} = require('./utils');
5
5
 
6
6
  class RequestOptions {
7
7
  constructor({method, url, headers, body} = {}) {
8
8
  this.method = method || 'GET';
9
9
  this.url = url || '/';
10
- this.headers = headers || {};
10
+ // TODO: remove convertKeysToLowerCase utility once https://github.com/antongolub/reqresnext/issues/33 is fixed
11
+ this.headers = convertKeysToLowerCase(headers) || {};
11
12
  this.body = body;
12
13
  }
13
14
 
@@ -29,7 +30,8 @@ class Request {
29
30
  }
30
31
 
31
32
  header(name, value) {
32
- this.reqOptions.headers[name] = value;
33
+ // TODO: remove toLowerCase once https://github.com/antongolub/reqresnext/issues/33 is fixed
34
+ this.reqOptions.headers[name.toLowerCase()] = value;
33
35
  return this;
34
36
  }
35
37
 
@@ -67,7 +69,7 @@ class Request {
67
69
  const {req, res} = reqresnext(Object.assign({}, reqOptions, {app}), {app});
68
70
 
69
71
  // This is needed to make error handling work
70
- // @TODO: submit this upstream in reqresnext
72
+ // @TODO: remove once https://github.com/antongolub/reqresnext/issues/31 is solved
71
73
  req.socket.destroy = () => { };
72
74
  return {req, res};
73
75
  }
package/lib/utils.js CHANGED
@@ -9,3 +9,13 @@ module.exports.makeMessageFromMatchMessage = function makeMessageFromMatchMessag
9
9
  messageLines.splice(0, 1, errorMessage);
10
10
  return messageLines.join('\n');
11
11
  };
12
+
13
+ module.exports.convertKeysToLowerCase = function (map) {
14
+ const newMap = {};
15
+
16
+ for (const key in map) {
17
+ newMap[key.toLowerCase()] = map[key];
18
+ }
19
+
20
+ return newMap;
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/express-test",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "repository": "https://github.com/TryGhost/framework/tree/main/packages/express-test",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -30,5 +30,5 @@
30
30
  "cookiejar": "^2.1.3",
31
31
  "reqresnext": "^1.6.6"
32
32
  },
33
- "gitHead": "79e0c67a94342496f84870a200eab7e4e74e4dbc"
33
+ "gitHead": "fdec1082aa5efa81196205cbcd8a31c61b50c8fa"
34
34
  }