mockaton 6.4.5 → 6.4.6

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/Tests.js CHANGED
@@ -165,7 +165,7 @@ async function runTests() {
165
165
  'api/alternative(comment-2).GET.200.json',
166
166
  JSON.stringify({ comment: 2 }))
167
167
 
168
- await test422WhenUpdatingNonExistingMockAlternative()
168
+ await testBadRequestWhenUpdatingNonExistingMockAlternative()
169
169
 
170
170
  await testAutogenerates500(
171
171
  '/api/alternative',
@@ -288,13 +288,15 @@ async function testItUpdatesDelayAndFile(url, file, expectedBody) {
288
288
  })
289
289
  }
290
290
 
291
- async function test422WhenUpdatingNonExistingMockAlternative() {
291
+ async function testBadRequestWhenUpdatingNonExistingMockAlternative() {
292
292
  await it('There are mocks for /api/the-route but not this one', async () => {
293
+ const missingFile = 'api/the-route(non-existing-variant).GET.200.json'
293
294
  const res = await request(API.edit, {
294
295
  method: 'PATCH',
295
- body: JSON.stringify({ [DF.file]: 'api/the-route(non-existing-variant).GET.200.json' })
296
+ body: JSON.stringify({ [DF.file]: missingFile })
296
297
  })
297
- equal(res.status, 422)
298
+ equal(res.status, 400)
299
+ equal(await res.text(), `Missing Mock: ${missingFile}`)
298
300
  })
299
301
  }
300
302
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "A deterministic server-side for developing and testing frontend clients",
4
4
  "type": "module",
5
- "version": "6.4.5",
5
+ "version": "6.4.6",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Api.js CHANGED
@@ -9,7 +9,7 @@ import { Config } from './Config.js'
9
9
  import { DF, API } from './ApiConstants.js'
10
10
  import { parseJSON } from './utils/http-request.js'
11
11
  import * as mockBrokersCollection from './mockBrokersCollection.js'
12
- import { sendOK, sendBadRequest, sendJSON, sendFile, sendUnprocessableContent } from './utils/http-response.js'
12
+ import { sendOK, sendBadRequest, sendJSON, sendFile } from './utils/http-response.js'
13
13
 
14
14
 
15
15
  export const apiGetRequests = new Map([
@@ -60,10 +60,9 @@ async function updateBroker(req, response) {
60
60
  const body = await parseJSON(req)
61
61
  const file = body[DF.file]
62
62
  const broker = mockBrokersCollection.getBrokerByFilename(file)
63
- if (!broker || !broker.mockExists(file)) {
64
- sendUnprocessableContent(response, `Missing Mock: ${file}`)
65
- return
66
- }
63
+ if (!broker || !broker.mockExists(file))
64
+ throw `Missing Mock: ${file}`
65
+
67
66
  if (DF.delayed in body)
68
67
  broker.updateDelay(body[DF.delayed])
69
68
  broker.updateFile(file)
@@ -51,7 +51,7 @@ export async function sendPartialContent(response, range, file) {
51
51
  export function sendBadRequest(response, error) {
52
52
  console.error(error)
53
53
  response.statusCode = 400
54
- response.end()
54
+ response.end(error)
55
55
  }
56
56
 
57
57
  export function sendNotFound(response) {
@@ -59,12 +59,6 @@ export function sendNotFound(response) {
59
59
  response.end()
60
60
  }
61
61
 
62
- export function sendUnprocessableContent(response, error) {
63
- console.error(error)
64
- response.statusCode = 422
65
- response.end()
66
- }
67
-
68
62
  export function sendInternalServerError(response, error) {
69
63
  console.error(error)
70
64
  response.statusCode = 500