@centeredgesoft/runtime-mock-routes 2.9.1 → 2.9.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.
@@ -6,6 +6,7 @@ export interface RuntimeRequestMethodBody {
6
6
  body: any;
7
7
  status?: any;
8
8
  headers?: any;
9
+ raw?: boolean;
9
10
  }
10
11
  export interface RequestParameters {
11
12
  query: any;
@@ -191,6 +191,9 @@ const appFactory = (runtimeCollection) => {
191
191
  const template = handlebars_1.default.compile(body);
192
192
  const result = template(tokenParams);
193
193
  try {
194
+ if (method.raw) {
195
+ return res.send(result);
196
+ }
194
197
  const jsonResult = JSON.parse(result);
195
198
  return res.send(jsonResult);
196
199
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centeredgesoft/runtime-mock-routes",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/appV2.test.ts CHANGED
@@ -275,6 +275,36 @@ describe('Body as Function', () => {
275
275
  })
276
276
  });
277
277
 
278
+ describe('Body returns quoted JSON when sending raw', () => {
279
+ test('Return JSON stringified string with quotes', async () => {
280
+ const seed: RuntimeRequestCollection = {
281
+ "/test": {
282
+ path: "/test",
283
+ methods: {
284
+ GET: {
285
+ body: function(rp: RequestParameters) { return JSON.stringify(`"<p>Test</p>"`) },
286
+ status: 200,
287
+ headers: () => { return { 'Content-Type': 'application/json; charset=utf-8' } },
288
+ raw: true
289
+ }
290
+ }
291
+ }
292
+ }
293
+
294
+ const app = appFactory(seed);
295
+ expect(app).toBeDefined();
296
+
297
+ var response = await request(app).get('/test');
298
+
299
+ expect(response.body).toEqual(`"<p>Test</p>"`);
300
+ expect(response.body).toHaveLength(13)
301
+ expect(response.body[0]).toBe(`"`);
302
+ expect(response.body[1]).toBe(`<`);
303
+ expect(response.body[11]).toBe(`>`);
304
+ expect(response.body[12]).toBe(`"`);
305
+ })
306
+ });
307
+
278
308
  describe('Request Body is Simple Type', () => {
279
309
  test('Send in string as JSON', async () => {
280
310
  const seed: RuntimeRequestCollection = {
package/src/appV2.ts CHANGED
@@ -37,6 +37,7 @@ export interface RuntimeRequestMethodBody {
37
37
  body: any;
38
38
  status?: any;
39
39
  headers?: any;
40
+ raw?: boolean;
40
41
  }
41
42
 
42
43
  export interface RequestParameters {
@@ -218,7 +219,7 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
218
219
  const status = typeof method.status === 'function'
219
220
  ? method.status(tokenParams)
220
221
  : method.status
221
-
222
+
222
223
  res.status(status);
223
224
  }
224
225
 
@@ -252,6 +253,10 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
252
253
  const result = template(tokenParams)
253
254
 
254
255
  try {
256
+ if (method.raw) {
257
+ return res.send(result);
258
+ }
259
+
255
260
  const jsonResult = JSON.parse(result);
256
261
  return res.send(jsonResult);
257
262
  } catch (_) {