mockaton 0.10.9 → 1.0.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.
package/README.md CHANGED
@@ -177,60 +177,64 @@ export default function capitalizeAllText(mockAsText, requestBody, config) {
177
177
  }
178
178
  ```
179
179
 
180
- ---
181
180
 
182
181
  ## API
183
182
 
184
- ### `/mockaton/edit` Select a mock for a route
185
- ```
186
- PATCH /mockaton/edit
187
- {
188
- "file": "api/foo.200.GET.json"
189
- "delayed": true // optional
190
- }
183
+ ### Select a mock for a route
184
+ ```js
185
+ fetch(addr + '/mockaton/edit', {
186
+ method: 'PATCH',
187
+ body: JSON.stringify({
188
+ file: 'api/foo.200.GET.json',
189
+ delayed: true // optional
190
+ })
191
+ })
191
192
  ```
192
- ---
193
-
194
- ### `/mockaton/bulk-select` Select all mocks that have a particular comment
195
193
 
194
+ ### Select all mocks that have a particular comment
195
+ ```js
196
+ fetch(addr + '/mockaton/bulk-select-by-comment', {
197
+ method: 'PATCH',
198
+ body: JSON.stringify('(demo-a)')
199
+ })
196
200
  ```
197
- PATCH /mockaton/bulk-select
198
- {
199
- "comment": "(demo-a)"
200
- }
201
- ```
202
- ---
203
201
 
204
- ### `/mockaton/reset` Reset
202
+ ### Reset
205
203
  Re-Initialize the collection and its states (selected mocks and cookies, delays, etc.).
204
+ ```js
205
+ fetch(add + '/mockaton/reset', {
206
+ method: 'PATCH'
207
+ })
206
208
  ```
207
- PATCH /mockaton/reset
208
- ```
209
- ---
210
209
 
211
- ### `/mockaton/cookies` Select a cookie
210
+ ### Select a cookie
212
211
  In `Config.cookies`, each key is the label used
213
212
  for changing it. Only one cookie can be set.
214
- ```
215
- PATCH /mockaton/cookies
216
- {
217
- "current_cookie_key": "My Normal User"
218
- }
213
+ ```js
214
+ fetch(addr + '/mockaton/cookies', {
215
+ method: 'PATCH',
216
+ body: JSON.stringify('My Normal User')
217
+ })
219
218
  ```
220
219
 
221
- ### `/mockaton/cookies` List Cookies
220
+ ### List Cookies
222
221
  Sends a list of the available cookies along with a flag indicated if it’s the selected.
222
+ ```js
223
+ fetch(addr + '/mockaton/cookies')
223
224
  ```
224
- GET /mockaton/cookies
225
- ```
226
-
227
- ---
228
225
 
229
- ### `/mockaton/transform` Select a Transform
226
+ ### Select a Transform
227
+ ```js
228
+ fetch(addr + '/mockaton/transform', {
229
+ method: 'PATCH',
230
+ body: JSON.stringify('api/video/list(concat newly uploaded).GET.200.mjs')
231
+ })
230
232
  ```
231
- PATCH /mockaton/transform
232
- {
233
- "file": "api/video/list(concat newly uploaded).GET.200.mjs"
234
- }
233
+
234
+ ### Update Fallback Proxy
235
+ ```js
236
+ fetch(addr + '/mockaton/fallback', {
237
+ method: 'PATCH',
238
+ body: JSON.stringify('http://example.com')
239
+ })
235
240
  ```
236
- ---
package/Tests.js CHANGED
@@ -269,7 +269,7 @@ async function testExtractsAllComments(expected) {
269
269
  async function testItBulkSelectsByComment(comment, tests) {
270
270
  await request(API.bulkSelect, {
271
271
  method: 'PATCH',
272
- body: JSON.stringify({ [DF.comment]: comment })
272
+ body: JSON.stringify(comment)
273
273
  })
274
274
  for (const [url, file, body] of tests)
275
275
  await testMockDispatching(url, file, body)
@@ -289,7 +289,7 @@ async function testItUpdatesUserRole() {
289
289
  it('Update the selected cookie', async () => {
290
290
  await request(API.cookies, {
291
291
  method: 'PATCH',
292
- body: JSON.stringify({ [DF.currentCookieKey]: 'userB' })
292
+ body: JSON.stringify('userB')
293
293
  })
294
294
  const res = await request(API.cookies)
295
295
  deepEqual(await res.json(), [
@@ -313,7 +313,7 @@ export default function (mock, reqBody, config) {
313
313
  await reset() // for registering the files
314
314
  await request(API.transform, {
315
315
  method: 'PATCH',
316
- body: JSON.stringify({ [DF.file]: 'api/transform.POST.200.mjs' })
316
+ body: JSON.stringify('api/transform.POST.200.mjs')
317
317
  })
318
318
  await testMockDispatching('/api/transform',
319
319
  'api/transform.POST.200.json',
@@ -367,10 +367,11 @@ async function testInvalidFilenamesAreIgnored() {
367
367
  async function testEnableFallbackSoRoutesWithoutMocksGetRelayed() {
368
368
  await describe('Fallback', async () => {
369
369
  const fallbackServer = createServer((_, response) => {
370
+ response.setHeader('custom_header', 'my_custom_header')
370
371
  response.statusCode = 423
371
372
  response.end('From_Fallback_Server')
372
373
  })
373
- await promisify(fallbackServer.listen).bind(fallbackServer, 3330, '127.0.0.1')()
374
+ await promisify(fallbackServer.listen).bind(fallbackServer, 0, '127.0.0.1')()
374
375
 
375
376
  await request(API.fallback, { // Enable fallback
376
377
  method: 'PATCH',
@@ -378,6 +379,7 @@ async function testEnableFallbackSoRoutesWithoutMocksGetRelayed() {
378
379
  })
379
380
  await it('Relays to fallback server', async () => {
380
381
  const res = await request('/non-existing-mock')
382
+ equal(res.headers.get('custom_header'), 'my_custom_header')
381
383
  equal(res.status, 423)
382
384
  equal(await res.text(), 'From_Fallback_Server')
383
385
  fallbackServer.close()
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": "0.10.9",
5
+ "version": "1.0.0",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Api.js CHANGED
@@ -51,8 +51,7 @@ function listMockBrokers(_, response) {
51
51
 
52
52
  async function selectCookie(req, response) {
53
53
  try {
54
- const body = await parseJSON(req)
55
- cookie.setCurrent(body[DF.currentCookieKey])
54
+ cookie.setCurrent(await parseJSON(req))
56
55
  sendOK(response)
57
56
  }
58
57
  catch (error) {
@@ -84,8 +83,7 @@ async function updateBroker(req, response) {
84
83
 
85
84
  async function bulkUpdateBrokersByCommentTag(req, response) {
86
85
  try {
87
- const body = await parseJSON(req)
88
- mockBrokersCollection.setMocksMatchingComment(body[DF.comment])
86
+ mockBrokersCollection.setMocksMatchingComment(await parseJSON(req))
89
87
  sendOK(response)
90
88
  }
91
89
  catch (error) {
@@ -96,9 +94,9 @@ async function bulkUpdateBrokersByCommentTag(req, response) {
96
94
 
97
95
  async function updateBrokerTransform(req, response) {
98
96
  try {
99
- const body = await parseJSON(req)
100
- const broker = mockBrokersCollection.getBrokerByFilename(body[DF.file])
101
- broker.updateTransform(body[DF.file])
97
+ const file = await parseJSON(req)
98
+ const broker = mockBrokersCollection.getBrokerByFilename(file)
99
+ broker.updateTransform(file)
102
100
  sendOK(response)
103
101
  }
104
102
  catch (error) {
@@ -1,7 +1,7 @@
1
1
  const MOUNT = '/mockaton'
2
2
  export const API = {
3
3
  dashboard: MOUNT,
4
- bulkSelect: MOUNT + '/bulk-select',
4
+ bulkSelect: MOUNT + '/bulk-select-by-comment',
5
5
  comments: MOUNT + '/comments',
6
6
  edit: MOUNT + '/edit',
7
7
  mocks: MOUNT + '/mocks',
@@ -12,9 +12,7 @@ export const API = {
12
12
  }
13
13
 
14
14
  export const DF = { // Dashboard Fields (XHR)
15
- comment: 'comment',
16
15
  delayed: 'delayed',
17
16
  file: 'file',
18
- currentCookieKey: 'current_cookie_key',
19
17
  isForDashboard: 'mock_request_payload'
20
18
  }
package/src/Dashboard.js CHANGED
@@ -103,7 +103,7 @@ function CookieSelector({ list }) {
103
103
  onChange() {
104
104
  fetch(API.cookies, {
105
105
  method: 'PATCH',
106
- body: JSON.stringify({ [DF.currentCookieKey]: this.value })
106
+ body: JSON.stringify(this.value)
107
107
  })
108
108
  .then(init)
109
109
  .catch(console.error)
@@ -124,7 +124,7 @@ function BulkSelector({ comments }) {
124
124
  onChange() {
125
125
  fetch(API.bulkSelect, {
126
126
  method: 'PATCH',
127
- body: JSON.stringify({ [DF.comment]: this.value })
127
+ body: JSON.stringify(this.value)
128
128
  })
129
129
  .then(init)
130
130
  .catch(console.error)
@@ -274,7 +274,7 @@ function TransformSelector({ items, selected }) {
274
274
  onChange() {
275
275
  fetch(API.transform, {
276
276
  method: 'PATCH',
277
- body: JSON.stringify({ [DF.file]: this.value })
277
+ body: JSON.stringify(this.value)
278
278
  }).then(() => {
279
279
  this.closest('tr').querySelector('a').click()
280
280
  this.className = className(this.value === this.options[0].value)
package/src/ProxyRelay.js CHANGED
@@ -6,6 +6,6 @@ export async function proxy(req, response) {
6
6
  method: req.method,
7
7
  headers: req.headers
8
8
  })
9
- response.writeHead(proxyResponse.status, proxyResponse.headers)
9
+ response.writeHead(proxyResponse.status, Object.fromEntries(proxyResponse.headers))
10
10
  response.end(await proxyResponse.text())
11
11
  }