mockaton 0.9.7 → 0.9.8
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/Api.js +1 -2
- package/MockBroker.js +1 -2
- package/MockDispatcher.js +1 -1
- package/Tests.js +9 -5
- package/package.json +1 -1
package/Api.js
CHANGED
|
@@ -72,8 +72,7 @@ async function updateBroker(req, response) {
|
|
|
72
72
|
const broker = mockBrokersCollection.getBrokerByFilename(body[DF.file])
|
|
73
73
|
if (DF.delayed in body)
|
|
74
74
|
broker.updateDelay(body[DF.delayed])
|
|
75
|
-
|
|
76
|
-
broker.updateFile(body[DF.file])
|
|
75
|
+
broker.updateFile(body[DF.file])
|
|
77
76
|
sendOK(response)
|
|
78
77
|
}
|
|
79
78
|
catch (error) {
|
package/MockBroker.js
CHANGED
|
@@ -20,7 +20,6 @@ export class MockBroker {
|
|
|
20
20
|
this.mocks = [] // *.json,txt
|
|
21
21
|
this.currentMock = {
|
|
22
22
|
file: '',
|
|
23
|
-
get status() { return Route.parseFilename(this.file).status },
|
|
24
23
|
delay: 0
|
|
25
24
|
}
|
|
26
25
|
|
|
@@ -45,8 +44,8 @@ export class MockBroker {
|
|
|
45
44
|
urlMaskMatches(url) { return this.#route.urlMaskMatches(url) }
|
|
46
45
|
|
|
47
46
|
get file() { return this.currentMock.file }
|
|
48
|
-
get status() { return this.currentMock.status }
|
|
49
47
|
get delay() { return this.currentMock.delay }
|
|
48
|
+
get status() { return Route.parseFilename(this.currentMock.file).status }
|
|
50
49
|
|
|
51
50
|
updateFile(filename) {
|
|
52
51
|
this.currentMock.file = filename
|
package/MockDispatcher.js
CHANGED
|
@@ -25,7 +25,7 @@ export async function dispatchMock(req, response) {
|
|
|
25
25
|
|
|
26
26
|
try {
|
|
27
27
|
const { file, status, delay, currentTransform } = mockBroker
|
|
28
|
-
console.log('\n', req.url, '
|
|
28
|
+
console.log('\n', req.url, '→\n ', file)
|
|
29
29
|
|
|
30
30
|
response.statusCode = status
|
|
31
31
|
response.setHeader('content-type', mimeFor(file))
|
package/Tests.js
CHANGED
|
@@ -118,7 +118,8 @@ async function runTests() {
|
|
|
118
118
|
|
|
119
119
|
await testItUpdatesDelayAndFile(
|
|
120
120
|
'/api/alternative',
|
|
121
|
-
'api/alternative(comment-
|
|
121
|
+
'api/alternative(comment-2).GET.200.json',
|
|
122
|
+
JSON.stringify({ comment: 2 }))
|
|
122
123
|
|
|
123
124
|
await testAutogenerates500(
|
|
124
125
|
'/api/company-e/123?limit=9',
|
|
@@ -200,7 +201,7 @@ async function testItUpdatesTheCurrentSelectedMock(url, file, expectedStatus, ex
|
|
|
200
201
|
})
|
|
201
202
|
}
|
|
202
203
|
|
|
203
|
-
async function testItUpdatesDelayAndFile(url, file) {
|
|
204
|
+
async function testItUpdatesDelayAndFile(url, file, expectedBody) {
|
|
204
205
|
await request(DP.edit, {
|
|
205
206
|
method: 'PATCH',
|
|
206
207
|
body: JSON.stringify({
|
|
@@ -209,9 +210,12 @@ async function testItUpdatesDelayAndFile(url, file) {
|
|
|
209
210
|
})
|
|
210
211
|
})
|
|
211
212
|
const now = new Date()
|
|
212
|
-
await request(url)
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
const res = await request(url)
|
|
214
|
+
const body = await res.text()
|
|
215
|
+
await describe('url: ' + url, () => {
|
|
216
|
+
it('body is: ' + expectedBody, () => equal(body, expectedBody))
|
|
217
|
+
it('delay is over 1 sec', () => equal((new Date()).getTime() - now.getTime() > 1000, true))
|
|
218
|
+
})
|
|
215
219
|
}
|
|
216
220
|
|
|
217
221
|
|
package/package.json
CHANGED