Skip to content

Commit

Permalink
Merge 41a06f6 into 7e86c0b
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinND committed Jun 26, 2014
2 parents 7e86c0b + 41a06f6 commit 7ced093
Show file tree
Hide file tree
Showing 24 changed files with 169 additions and 109 deletions.
20 changes: 3 additions & 17 deletions bin/make-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mkdirp(mocksDirectory, function(err) {
anyfetch = new Anyfetch(res.body.token);

async.auto({
getUserId: function(cb) {
getCurrentUser: function(cb) {
anyfetch.getCurrentUser(function(err, user) {
userId = user.id;
cb(err);
Expand Down Expand Up @@ -119,19 +119,8 @@ mkdirp(mocksDirectory, function(err) {
});
},

postDocumentsFile: ['postDocuments', function(cb) {
var hash = configuration.test.fakeFile;
hash.file = fs.createReadStream(hash.path);
anyfetch.getDocumentById(documentId).postFile(hash, function(err, res) {
if(res.body) {
saveMock({ expectedStatus: 204 }, res.body);
}
cb(err);
});
}],

// Now the fake content is setup, we can test all the gets in parallel
endpoints: ['getMyUserId', 'postSubcompanies', 'postDocumentsFile', function(cb) {
endpoints: ['getCurrentUser', 'postSubcompanies', 'postDocuments', function(cb) {
var endpoints = [
'getDocuments',
'getStatus',
Expand All @@ -146,7 +135,6 @@ mkdirp(mocksDirectory, function(err) {
['getDocumentsById', documentId],
['getDocumentsByIdentifier', documentIdentifier],
['getUsersById', userId],
['getBatch', { pages: ['/document_types', '/providers'] }]
];

// Only proceed when all of them are done
Expand All @@ -162,13 +150,11 @@ mkdirp(mocksDirectory, function(err) {
}],

// Subfunctions of getDocumentById
subFunctions: ['postDocumentsFile', function(cb) {
subFunctions: ['endpoints', function(cb) {
var subs = [
'getSimilar',
'getRelated',
'getRaw',
// TODO: re-enable when API is fixed
//'getFile'
];
var pre = anyfetch.getDocumentsById(documentId);
var c = configuration.apiDescriptors.getDocumentsById.subFunctions;
Expand Down
1 change: 1 addition & 0 deletions config/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
test: {
port: process.env.PORT || '50000',
managerPort: process.env.MANAGER_TEST_PORT || '50001',
mockPort: process.env.MOCK_TEST_PORT || '50002',
login: process.env.LOGIN,
password: process.env.PASSWORD,

Expand Down
26 changes: 23 additions & 3 deletions lib/test-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ var restify = require('restify');
var filename = require('../helpers/endpoint-filename.js');
var configuration = require('../../config/configuration.js');

// TODO: create `GET /batch` response from the various mock files

module.exports = function createTestServer() {
var server = restify.createServer();
server.use(restify.queryParser());
Expand Down Expand Up @@ -56,7 +54,10 @@ module.exports = function createTestServer() {
Object.keys(configuration.apiDescriptors).forEach(function(name) {
var config = configuration.apiDescriptors[name];

respondTo(config);
// We'll override `GET /batch`
if(config.endpoint !== '/batch') {
respondTo(config);
}

if(config.subFunctions) {
Object.keys(config.subFunctions).forEach(function(name) {
Expand All @@ -66,5 +67,24 @@ module.exports = function createTestServer() {
}
});

/**
* Custom response to GET /batch
* We craft the response from each asked endpoint.
*/
server.get('/batch', function(req, res) {
var pages = req.params.pages;
var response = {};

pages.forEach(function(page) {
var config = {
verb: 'GET',
endpoint: page
};
response[page] = require('./mocks/' + filename(config) + '.json');
});

res.send(response);
});

return server;
};
42 changes: 0 additions & 42 deletions lib/test-server/mocks/get-batch.json

This file was deleted.

14 changes: 13 additions & 1 deletion lib/test-server/mocks/get-document_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@
"full": "<article>\n <h1>{{{ title }}}</h1>\n <code>{{{ path }}}</code>\n</article>\n",
"title": "{{ title }}"
},
"updated": "2014-06-16T14:11:13.144Z",
"updated": "2014-06-25T14:06:24.833Z",
"documents": 1
},
"5252ce4ce4cfcd16f55cfa3a": {
"_type": "DocumentType",
"id": "5252ce4ce4cfcd16f55cfa3a",
"name": "contact",
"templates": {
"snippet": "<article class=\"two-columns\">\n <aside>\n <img src=\"{{ image }}\" />\n </aside>\n <section>\n <h1>{{{ name }}}</h1>\n <span>{{{ job }}}</span>\n </section>\n</article>\n",
"full": "<article>\n\n <section class=\"two-columns\">\n <aside>\n <img src=\"{{ image }}\"/> \n </aside>\n <section>\n <h1><a href=\"anyfetch://search/{{name}}\">{{{ name }}}</a></h1>\n <span>{{{ job }}}</span> \n </section>\n </section>\n\n <section>\n {{#phone.length}}\n <h2>Phones:</h2>\n <ul>\n {{ #phone }}\n <li>{{ phone }} ( {{ type }} )</li>\n {{ /phone }}\n </ul>\n {{/phone.length}}\n\n {{#email.length}}\n <h2>Emails:</h2>\n <ul>\n {{ #email }}\n <li>{{ email }} ( {{ type }} )</li>\n {{ /email }}\n </ul>\n {{/email.length}}\n\n {{#address.length}}\n <h2>Address:</h2>\n <ul>\n {{ #address }}\n <li>{{ address }} ( {{ type }} )</li>\n {{ /address }}\n </ul>\n {{/address.length}}\n\n {{#website.length}}\n <h2>Website:</h2>\n <ul>\n {{ #website }}\n <li>{{{ website }}}</li>\n {{ /website }}\n </ul>\n {{/website.length}}\n\n\n {{#birthday}}\n <h2>Birthday:</h2>\n <span>{{birthday}}</span>\n {{/birthday}}\n\n </section>\n\n</article>\n",
"title": "{{ name }}"
},
"updated": "2014-06-25T07:59:21.566Z",
"documents": 381
}
}
10 changes: 5 additions & 5 deletions lib/test-server/mocks/get-documents-id-raw.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"_type": "Document",
"id": "539efb0019cf08ec1bc40c31",
"id": "53aad75f45419da341fc5c02",
"identifier": "the \"unique\" document identifier (éüà)",
"creation_date": "2014-06-16T14:11:12.671Z",
"token": "539afa9270e5c5e1387fc2c3",
"creation_date": "2014-06-25T14:06:23.948Z",
"provider": "5396f9a148f9f76e6b197957",
"company": "5391b692c8318c0ec7000026",
"document_type": "5252ce4ce4cfcd16f55cfa3b",
"actions": {},
"document_url": "/documents/539efb0019cf08ec1bc40c31",
"document_url": "/documents/53aad75f45419da341fc5c02",
"projection_type": "raw",
"data": {
"foo": "some_string"
Expand All @@ -16,7 +16,7 @@
"path": "/hello",
"some_key": "some random sentence"
},
"last_hydration": "2014-06-16T14:11:13.120Z",
"last_hydration": "2014-06-25T14:06:24.653Z",
"hydrating": [
"http://plaintext.hydrater.anyfetch.com/hydrate"
],
Expand Down
2 changes: 1 addition & 1 deletion lib/test-server/mocks/get-documents-id-related.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"document_type": "5252ce4ce4cfcd16f55cfa3b",
"facets": {
"document_types": {},
"tokens": {},
"providers": {},
"creation_dates": {}
},
"data": [],
Expand Down
40 changes: 34 additions & 6 deletions lib/test-server/mocks/get-documents-id-similar.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,39 @@
"random"
],
"facets": {
"document_types": {},
"tokens": {},
"creation_dates": {}
"document_types": {
"5252ce4ce4cfcd16f55cfa3a": 1
},
"providers": {
"53a14dadaa19645626f38b4a": 1
},
"creation_dates": {
"1401580800000": 1
}
},
"data": [],
"count": 0,
"max_score": null
"data": [
{
"_type": "Document",
"id": "53a14e37d9d493b510e41996",
"identifier": "https://mail.google.com/mail/b/merlin.nimier@gmail.com/#contact/5865599e0d5e0f2a",
"creation_date": "2014-06-18T08:30:47.638Z",
"provider": "53a14dadaa19645626f38b4a",
"company": "5391b692c8318c0ec7000026",
"document_type": "5252ce4ce4cfcd16f55cfa3a",
"actions": {
"show": "https://mail.google.com/mail/b/merlin.nimier@gmail.com/#contact/5865599e0d5e0f2a"
},
"document_url": "/documents/53a14e37d9d493b510e41996",
"projection_type": "snippet",
"data": {
"name": "Anonymous",
"image": "https://www.gravatar.com/avatar/5348ec1f92ed3a6be5accc2d04566d64?d=mm&s=96",
"job": " "
},
"related_count": 0,
"score": 0.1973946
}
],
"count": 1,
"max_score": 0.1973946
}
8 changes: 4 additions & 4 deletions lib/test-server/mocks/get-documents-id.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"_type": "Document",
"id": "539efb0019cf08ec1bc40c31",
"id": "53aad75f45419da341fc5c02",
"identifier": "the \"unique\" document identifier (éüà)",
"creation_date": "2014-06-16T14:11:12.671Z",
"token": "539afa9270e5c5e1387fc2c3",
"creation_date": "2014-06-25T14:06:23.948Z",
"provider": "5396f9a148f9f76e6b197957",
"company": "5391b692c8318c0ec7000026",
"document_type": "5252ce4ce4cfcd16f55cfa3b",
"actions": {},
"document_url": "/documents/539efb0019cf08ec1bc40c31",
"document_url": "/documents/53aad75f45419da341fc5c02",
"projection_type": "full",
"data": {
"title": "Hello",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"_type": "Document",
"id": "539efb0019cf08ec1bc40c31",
"id": "53aad75f45419da341fc5c02",
"identifier": "the \"unique\" document identifier (éüà)",
"creation_date": "2014-06-16T14:11:12.671Z",
"token": "539afa9270e5c5e1387fc2c3",
"creation_date": "2014-06-25T14:06:23.948Z",
"provider": "5396f9a148f9f76e6b197957",
"company": "5391b692c8318c0ec7000026",
"document_type": "5252ce4ce4cfcd16f55cfa3b",
"actions": {},
"document_url": "/documents/539efb0019cf08ec1bc40c31",
"document_url": "/documents/53aad75f45419da341fc5c02",
"projection_type": "full",
"data": {
"title": "Hello",
Expand Down
2 changes: 1 addition & 1 deletion lib/test-server/mocks/get-index.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"update_url": "/company/update",
"reset_url": "/company/reset",
"token_url": "/token",
"server_time": "2014-06-16T14:11:13.319Z"
"server_time": "2014-06-25T14:06:25.102Z"
}
10 changes: 8 additions & 2 deletions lib/test-server/mocks/get-providers.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"539afa9270e5c5e1387fc2c3": {
"5396f9a148f9f76e6b197957": {
"client": null,
"name": null,
"updated": "2014-06-16T14:11:13.144Z",
"updated": "2014-06-25T14:06:24.833Z",
"document_count": 1
},
"53a14dadaa19645626f38b4a": {
"client": "52bff1eec8318cb228000001",
"name": "Google Contacts",
"updated": "2014-06-25T07:59:21.566Z",
"document_count": 381
}
}
6 changes: 3 additions & 3 deletions lib/test-server/mocks/get-subcompanies-id.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"_type": "Company",
"id": "539efb0019cf08ec1bc40c32",
"id": "53aad76045419da341fc5c03",
"name": "the_fake_subcompany",
"hydraters": [
"http://localhost:5000/plaintext/hydrate",
"http://localhost:5000/pdf/hydrate"
"http://plaintext.hydrater.anyfetch.com/hydrate",
"http://pdf.hydrater.anyfetch.com/hydrate"
]
}
6 changes: 3 additions & 3 deletions lib/test-server/mocks/get-subcompanies.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[
{
"_type": "Company",
"id": "539efb0019cf08ec1bc40c32",
"id": "53aad76045419da341fc5c03",
"name": "the_fake_subcompany",
"hydraters": [
"http://localhost:5000/plaintext/hydrate",
"http://localhost:5000/pdf/hydrate"
"http://plaintext.hydrater.anyfetch.com/hydrate",
"http://pdf.hydrater.anyfetch.com/hydrate"
]
}
]
2 changes: 1 addition & 1 deletion lib/test-server/mocks/get-token.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"token": "599e754ef7313c2e2975ce8ac610430a7707b66711fae1b33e109e088ff868a9"
"token": "ce48a8d00155140901aba760d9e2844d723e1d8e65b415cc3512b31dfdb6b7af"
}
2 changes: 1 addition & 1 deletion lib/test-server/mocks/get-users-id.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_type": "User",
"id": "5391b692c8318c0ec7000027",
"email": "merlin@anyfetch.com",
"name": "",
"name": "User",
"is_admin": true,
"user_url": "/users/5391b692c8318c0ec7000027"
}
10 changes: 9 additions & 1 deletion lib/test-server/mocks/get-users.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
"_type": "User",
"id": "5391b692c8318c0ec7000027",
"email": "merlin@anyfetch.com",
"name": "",
"name": "User",
"is_admin": true,
"user_url": "/users/5391b692c8318c0ec7000027"
},
{
"_type": "User",
"id": "53aad42245419da341fc5bfc",
"email": "thechuck1049@norris.com",
"name": "Chuck Norris",
"is_admin": true,
"user_url": "/users/53aad42245419da341fc5bfc"
}
]

0 comments on commit 7ced093

Please sign in to comment.