express-mock-server 3.3.0 → 3.4.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.
Files changed (44) hide show
  1. package/dist/api/control.js +2 -2
  2. package/dist/api/control.js.map +1 -1
  3. package/dist/api/recording/api-recorder.js +3 -5
  4. package/dist/api/recording/api-recorder.js.map +1 -1
  5. package/dist/api/recording/index.js.map +1 -1
  6. package/dist/api/websocket/index.js.map +1 -1
  7. package/dist/app.js.map +1 -1
  8. package/dist/config.js.map +1 -1
  9. package/dist/constants.js +1 -1
  10. package/dist/constants.js.map +1 -1
  11. package/dist/core/matchers/MatchItem.js.map +1 -1
  12. package/dist/core/matchers/MatchingResult.js +1 -1
  13. package/dist/core/matchers/MatchingResult.js.map +1 -1
  14. package/dist/core/matchers/http-post-matcher.js.map +1 -1
  15. package/dist/core/matchers/query-string-matcher.js +3 -3
  16. package/dist/core/matchers/query-string-matcher.js.map +1 -1
  17. package/dist/core/request-handler.js +41 -5
  18. package/dist/core/request-handler.js.map +1 -1
  19. package/dist/core/sources-parser.js.map +1 -1
  20. package/dist/core/sources-parser.spec.js.map +1 -1
  21. package/dist/core/sources-router.js +11 -11
  22. package/dist/core/sources-router.js.map +1 -1
  23. package/dist/core/utils.js.map +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/lib/api/control.js +5 -5
  26. package/lib/api/recording/api-recorder.js +6 -6
  27. package/lib/api/recording/index.js +1 -1
  28. package/lib/api/websocket/index.js +5 -5
  29. package/lib/config.js +1 -1
  30. package/lib/constants.js +1 -1
  31. package/lib/core/matchers/MatchingResult.js +1 -1
  32. package/lib/core/matchers/http-post-matcher.js +1 -1
  33. package/lib/core/matchers/query-string-matcher.js +4 -4
  34. package/lib/core/request-handler.js +50 -7
  35. package/lib/core/sources-parser.js +8 -8
  36. package/lib/core/sources-parser.spec.js +6 -6
  37. package/lib/core/sources-router.js +12 -12
  38. package/lib/core/utils.js +1 -1
  39. package/lib/index.js +5 -4
  40. package/package.json +15 -15
  41. package/test/image.jpg +0 -0
  42. package/test/mock-api.spec.js +14 -0
  43. package/test/sources.js +37 -21
  44. package/test/urls.js +1 -0
package/test/sources.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import urls from './urls';
2
2
  import responseKey, { responseKeyParam } from './responsekey';
3
+ import path from 'path';
3
4
 
4
5
  const q1q2q3FilledQs = [
5
6
  { name: 'q1', values: ['.*'] },
6
7
  { name: 'q2', values: ['.*'] },
7
- { name: 'q3', values: ['.*'] }
8
+ { name: 'q3', values: ['.*'] },
8
9
  ];
9
10
 
10
11
  const q1filledQs = [{ name: 'q1', values: ['1'] }];
@@ -23,41 +24,41 @@ const sources = [
23
24
  method: 'GET',
24
25
  path: urls.items,
25
26
  statusCode: 200,
26
- key: responseKey.qsOptionalEmpty
27
+ key: responseKey.qsOptionalEmpty,
27
28
  }),
28
29
  createSource({
29
30
  method: 'GET',
30
31
  path: urls.items,
31
32
  statusCode: 200,
32
33
  key: responseKey.qsOptionalQ1Q2Q3Filed,
33
- queryStringParameters: q1q2q3FilledQs
34
+ queryStringParameters: q1q2q3FilledQs,
34
35
  }),
35
36
  createSource({
36
37
  method: 'GET',
37
38
  path: urls.items,
38
39
  statusCode: 200,
39
40
  key: responseKey.qsOptionalQ1filled,
40
- queryStringParameters: q1filledQs
41
+ queryStringParameters: q1filledQs,
41
42
  }),
42
43
  // item
43
44
  createSource({
44
45
  method: 'GET',
45
46
  path: urls.item,
46
47
  statusCode: 200,
47
- key: responseKey.urlParamBase
48
+ key: responseKey.urlParamBase,
48
49
  }),
49
50
  createSource({
50
51
  method: 'GET',
51
52
  path: urls.itemHardId,
52
53
  statusCode: 200,
53
- key: responseKey.urlParamHardId
54
+ key: responseKey.urlParamHardId,
54
55
  }),
55
56
  createSource({
56
57
  method: 'GET',
57
58
  path: urls.items,
58
59
  statusCode: 200,
59
60
  key: responseKey.qsMultiQ1,
60
- queryStringParameters: [{ name: 'q1', values: ['1', '2', '3'] }]
61
+ queryStringParameters: [{ name: 'q1', values: ['1', '2', '3'] }],
61
62
  }),
62
63
 
63
64
  // dynamic response
@@ -67,9 +68,24 @@ const sources = [
67
68
  path: urls.dynamicResponse,
68
69
  statusCode: 200,
69
70
  key: responseKey.dynamicResponse,
70
- queryStringParameters: dynamicResponseQs
71
+ queryStringParameters: dynamicResponseQs,
71
72
  }),
72
- ]
73
+
74
+ // response with file
75
+ {
76
+ request: {
77
+ method: 'GET',
78
+ path: urls.itemsLogo,
79
+ },
80
+ response: {
81
+ statusCode: 200,
82
+ file: {
83
+ type: 'image/jpg',
84
+ path: path.join(__dirname, 'image.jpg'),
85
+ },
86
+ },
87
+ },
88
+ ],
73
89
  ];
74
90
 
75
91
  export default sources;
@@ -82,7 +98,7 @@ function createDynamicSource({
82
98
  path,
83
99
  statusCode,
84
100
  key,
85
- queryStringParameters = null
101
+ queryStringParameters = null,
86
102
  }) {
87
103
  let body = {};
88
104
  body[responseKeyParam] = key;
@@ -95,22 +111,22 @@ function createDynamicSource({
95
111
  body: {
96
112
  type: 'JSON',
97
113
  value: JSON.stringify({
98
- bodyParam1: 'bodyValue1'
114
+ bodyParam1: 'bodyValue1',
99
115
  }),
100
- matchType: 'ONLY_MATCHING_FIELDS'
101
- }
116
+ matchType: 'ONLY_MATCHING_FIELDS',
117
+ },
102
118
  },
103
- response: function(urlParams, qsParams, bodyParams) {
119
+ response: function (urlParams, qsParams, bodyParams) {
104
120
  body['requestParams'] = {
105
121
  qsParams,
106
122
  bodyParams,
107
- urlParams
123
+ urlParams,
108
124
  };
109
125
  return {
110
126
  statusCode,
111
- body: JSON.stringify(body)
127
+ body: JSON.stringify(body),
112
128
  };
113
- }
129
+ },
114
130
  };
115
131
  }
116
132
 
@@ -123,7 +139,7 @@ export function createSource({
123
139
  statusCode,
124
140
  delay,
125
141
  key,
126
- queryStringParameters = null
142
+ queryStringParameters = null,
127
143
  }) {
128
144
  let body = {};
129
145
  body[responseKeyParam] = key;
@@ -132,12 +148,12 @@ export function createSource({
132
148
  request: {
133
149
  method,
134
150
  path,
135
- queryStringParameters
151
+ queryStringParameters,
136
152
  },
137
153
  response: {
138
154
  delay,
139
155
  statusCode,
140
- body: JSON.stringify(body)
141
- }
156
+ body: JSON.stringify(body),
157
+ },
142
158
  };
143
159
  }
package/test/urls.js CHANGED
@@ -3,6 +3,7 @@ const urls = {
3
3
  error: '/error',
4
4
  notFound: '/not-found',
5
5
  items: '/items',
6
+ itemsLogo: '/items/logo',
6
7
  item: '/item/:id',
7
8
  itemHardId: '/item/hardId',
8
9
  dynamicResponseBase: '/dynamic/response/',