json-server
Advanced tools
Comparing version 1.0.0-alpha.6 to 1.0.0-alpha.7
@@ -30,3 +30,3 @@ import assert from 'node:assert/strict'; | ||
}); | ||
await test('createApp', async () => { | ||
await test('createApp', async (t) => { | ||
// URLs | ||
@@ -71,7 +71,9 @@ const POSTS = '/posts'; | ||
for (const tc of arr) { | ||
const response = await fetch(`http://localhost:${port}${tc.url}`, { | ||
method: tc.method, | ||
await t.test(`${tc.method} ${tc.url}`, async () => { | ||
const response = await fetch(`http://localhost:${port}${tc.url}`, { | ||
method: tc.method, | ||
}); | ||
assert.equal(response.status, tc.statusCode, `${response.status} !== ${tc.statusCode} ${tc.method} ${tc.url} failed`); | ||
}); | ||
assert.equal(response.status, tc.statusCode, `${response.status} !== ${tc.statusCode} ${tc.method} ${tc.url} failed`); | ||
} | ||
}); |
@@ -106,4 +106,5 @@ #!/usr/bin/env node | ||
console.log(`Started on :${port}`); | ||
console.log(`http://localhost:${port}/`); | ||
console.log(routes(db).join('\n')); | ||
console.log(`Watching ${file}...`); | ||
console.log(routes(db).join('\n')); | ||
}); |
@@ -13,13 +13,30 @@ import assert from 'node:assert/strict'; | ||
const UNKNOWN_ID = 'xxx'; | ||
const post1 = { id: '1', title: 'a', views: 100, author: { name: 'foo' } }; | ||
const post2 = { id: '2', title: 'b', views: 200, author: { name: 'bar' } }; | ||
const post3 = { id: '3', title: 'c', views: 300, author: { name: 'baz' } }; | ||
const post1 = { | ||
id: '1', | ||
title: 'a', | ||
views: 100, | ||
author: { name: 'foo' }, | ||
tags: ['foo', 'bar'], | ||
}; | ||
const post2 = { | ||
id: '2', | ||
title: 'b', | ||
views: 200, | ||
author: { name: 'bar' }, | ||
tags: ['bar'], | ||
}; | ||
const post3 = { | ||
id: '3', | ||
title: 'c', | ||
views: 300, | ||
author: { name: 'baz' }, | ||
tags: ['foo'], | ||
}; | ||
const comment1 = { id: '1', title: 'a', postId: '1' }; | ||
const items = 3; | ||
function reset() { | ||
const post1 = { id: '1', title: 'a', views: 100, author: { name: 'foo' } }; | ||
const post2 = { id: '2', title: 'b', views: 200, author: { name: 'bar' } }; | ||
const post3 = { id: '3', title: 'c', views: 300, author: { name: 'baz' } }; | ||
const comment1 = { id: '1', title: 'a', postId: '1' }; | ||
db.data = { posts: [post1, post2, post3], comments: [comment1] }; | ||
db.data = structuredClone({ | ||
posts: [post1, post2, post3], | ||
comments: [comment1], | ||
}); | ||
} | ||
@@ -40,3 +57,3 @@ await test('findById', () => { | ||
}); | ||
await test('find', () => { | ||
await test('find', async (t) => { | ||
const arr = [ | ||
@@ -69,2 +86,7 @@ { | ||
name: POSTS, | ||
params: { 'tags[0]': 'foo' }, | ||
res: [post1, post3], | ||
}, | ||
{ | ||
name: POSTS, | ||
params: { id: UNKNOWN_ID, views: post1.views.toString() }, | ||
@@ -205,9 +227,11 @@ res: [], | ||
for (const tc of arr) { | ||
if (tc.data) { | ||
db.data = tc.data; | ||
} | ||
else { | ||
reset(); | ||
} | ||
assert.deepEqual(service.find(tc.name, tc.params), tc.res); | ||
await t.test(`${tc.name} ${JSON.stringify(tc.params)}`, () => { | ||
if (tc.data) { | ||
db.data = tc.data; | ||
} | ||
else { | ||
reset(); | ||
} | ||
assert.deepEqual(service.find(tc.name, tc.params), tc.res); | ||
}); | ||
} | ||
@@ -214,0 +238,0 @@ }); |
{ | ||
"name": "json-server", | ||
"version": "1.0.0-alpha.6", | ||
"version": "1.0.0-alpha.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -13,3 +13,3 @@ # json-server | ||
Create a `db.json` or `db.json5` file | ||
Create a `db.json` (or `db.json5`) file | ||
@@ -32,3 +32,3 @@ ```json | ||
```shell | ||
json-server db.json | ||
$ json-server db.json | ||
``` | ||
@@ -39,3 +39,3 @@ | ||
```shell | ||
curl -H "Accept: application/json" -X GET http://localhost:3000/posts/1 | ||
$ curl -H "Accept: application/json" -X GET http://localhost:3000/posts/1 | ||
{ | ||
@@ -64,3 +64,3 @@ "id": "1", | ||
- ` ` →`==` | ||
- ` ` → `==` | ||
- `lt` → `<` | ||
@@ -104,6 +104,13 @@ - `lte` → `<=` | ||
### Nested fields | ||
### Nested and array fields | ||
- `x.y.z` | ||
- `x.y.z_...` | ||
- `x.y.z[i]_...` | ||
``` | ||
GET /posts?author.name=foo | ||
GET /posts?author.email=foo | ||
GET /posts?names[0]=foo | ||
``` | ||
### Include | ||
@@ -110,0 +117,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
163641
1881
139