Lloyd Brookes
9 years ago
6 changed files with 108 additions and 28 deletions
-
5example/mock/.local-web-server.json
-
20example/mock/mocks/search.mock.js
-
17example/mock/mocks/tree.mock.js
-
41example/mock/mocks/trees.mock.js
-
49lib/local-web-server.js
-
4package.json
@ -1,6 +1,7 @@ |
|||
{ |
|||
"rewrite": [ |
|||
{ "from": "/tree", "to": "/mocks/trees.mock.js" }, |
|||
{ "from": "/tree/:id", "to": "/mocks/tree.mock.js" } |
|||
{ "from": "/trees", "to": "/mocks/trees.mock.js" }, |
|||
{ "from": "/trees/:id", "to": "/mocks/tree.mock.js" }, |
|||
{ "from": "/search", "to": "/mocks/search.mock.js" } |
|||
] |
|||
} |
@ -0,0 +1,20 @@ |
|||
module.exports = [ |
|||
{ |
|||
request: { |
|||
accepts: 'json' |
|||
}, |
|||
response: { |
|||
status: 200, |
|||
body: { id: 2, name: 'eucalyptus', maxHeight: 210 } |
|||
} |
|||
}, |
|||
{ |
|||
request: { |
|||
accepts: 'xml' |
|||
}, |
|||
response: { |
|||
status: 200, |
|||
body: '<tree id="2" name="eucalyptus" maxHeight="210"/>' |
|||
} |
|||
} |
|||
] |
@ -1,8 +1,25 @@ |
|||
module.exports = [ |
|||
/* CREATE (409 CONFLICT - should be called on the collection) */ |
|||
{ |
|||
request: { method: 'POST' }, |
|||
response: { status: 409 } |
|||
}, |
|||
/* READ */ |
|||
{ |
|||
request: { method: 'GET' }, |
|||
response: { |
|||
status: 200, |
|||
body: { id: 2, name: 'eucalyptus', maxHeight: 210 } |
|||
} |
|||
}, |
|||
/* UPDATE */ |
|||
{ |
|||
request: { method: 'PUT' }, |
|||
response: { status: 204 } |
|||
}, |
|||
/* DELETE */ |
|||
{ |
|||
request: { method: 'DELETE' }, |
|||
response: { status: 204 } |
|||
} |
|||
] |
@ -1,23 +1,38 @@ |
|||
const data = [ |
|||
{ id: 1, name: 'Conifer', maxHeight: 115 }, |
|||
{ id: 2, name: 'Eucalyptus', maxHeight: 210 }, |
|||
{ id: 3, name: 'Ash', maxHeight: 40 }, |
|||
{ id: 4, name: 'Elder', maxHeight: 5 }, |
|||
{ id: 5, name: 'Holly', maxHeight: 10 } |
|||
] |
|||
|
|||
module.exports = [ |
|||
/* CREATE */ |
|||
{ |
|||
request: { |
|||
method: 'GET' |
|||
}, |
|||
request: { method: 'POST' }, |
|||
response: { |
|||
status: 200, |
|||
body: [ |
|||
{ id: 1, name: 'conifer', maxHeight: 115 }, |
|||
{ id: 2, name: 'eucalyptus', maxHeight: 210 } |
|||
] |
|||
status: 201, |
|||
location: '/tree/1' |
|||
} |
|||
}, |
|||
/* READ */ |
|||
{ |
|||
request: { |
|||
method: 'POST' |
|||
}, |
|||
request: { method: 'GET' }, |
|||
response: { |
|||
status: 201, |
|||
location: '/tree/1' |
|||
status: 200, |
|||
body: function (ctx) { |
|||
return data.filter(tree => tree.maxHeight > Number(ctx.query.tallerThan)) |
|||
} |
|||
} |
|||
}, |
|||
/* UPDATE (forbidden on collection)*/ |
|||
{ |
|||
request: { method: 'PUT' }, |
|||
response: { status: 404 } |
|||
}, |
|||
/* DELETE (forbidden on collection) */ |
|||
{ |
|||
request: { method: 'DELETE' }, |
|||
response: { status: 404 } |
|||
} |
|||
] |
Write
Preview
Loading…
Cancel
Save
Reference in new issue