From b6106697a0d3a54463a91e0618b2042ef49f35ad Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 7 Oct 2015 14:07:54 +0100 Subject: [PATCH] Don't look up user details in this api --- .../contacts/app/coffee/HttpController.coffee | 24 +++----------- .../unit/coffee/HttpControllerTests.coffee | 31 +++++-------------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/services/contacts/app/coffee/HttpController.coffee b/services/contacts/app/coffee/HttpController.coffee index dd3f21791e..170a50150d 100644 --- a/services/contacts/app/coffee/HttpController.coffee +++ b/services/contacts/app/coffee/HttpController.coffee @@ -1,7 +1,5 @@ ContactManager = require "./ContactManager" -WebApiManager = require "./WebApiManager" logger = require "logger-sharelatex" -async = require "async" module.exports = HttpController = addContact: (req, res, next) -> @@ -45,17 +43,11 @@ module.exports = HttpController = HttpController._sortContacts contacts contacts = contacts.slice(0, limit) + contact_ids = contacts.map (contact) -> contact.user_id - async.mapLimit contacts, 5, - (contact, cb) -> - WebApiManager.getUserDetails contact.user_id, (error, user) -> - return cb(error) if error? - cb null, HttpController._formatUser user - (error, users) -> - return next(error) if error? - res.status(200).send({ - contacts: users - }) + res.status(200).send({ + contact_ids: contact_ids + }) _sortContacts: (contacts) -> contacts.sort (a, b) -> @@ -72,11 +64,3 @@ module.exports = HttpController = return 1 else return 0 - - _formatUser: (user) -> - return { - id: user._id - email: user.email - first_name: user.first_name - last_name: user.last_name - } \ No newline at end of file diff --git a/services/contacts/test/unit/coffee/HttpControllerTests.coffee b/services/contacts/test/unit/coffee/HttpControllerTests.coffee index 17fea0e71e..ca87b421c1 100644 --- a/services/contacts/test/unit/coffee/HttpControllerTests.coffee +++ b/services/contacts/test/unit/coffee/HttpControllerTests.coffee @@ -9,7 +9,6 @@ describe "HttpController", -> beforeEach -> @HttpController = SandboxedModule.require modulePath, requires: "./ContactManager": @ContactManager = {} - "./WebApiManager": @WebApiManager = {} "logger-sharelatex": @logger = { log: sinon.stub() } @user_id = "mock-user-id" @contact_id = "mock-contact-id" @@ -67,15 +66,7 @@ describe "HttpController", -> "user-id-2": { n: 4, ts: new Date(now) } "user-id-3": { n: 2, ts: new Date(now - 1000) } } - @user_details = { - "user-id-1": { _id: "user-id-1", email: "joe@example.com", first_name: "Joe", last_name: "Example", extra: "foo" } - "user-id-2": { _id: "user-id-2", email: "jane@example.com", first_name: "Sarah", last_name: "Example", extra: "foo" } - "user-id-3": { _id: "user-id-3", email: "sam@example.com", first_name: "Sam", last_name: "Example", extra: "foo" } - } @ContactManager.getContacts = sinon.stub().callsArgWith(1, null, @contacts) - @WebApiManager.getUserDetails = (user_id, callback = (error, user) ->) => - callback null, @user_details[user_id] - sinon.spy @WebApiManager, "getUserDetails" describe "normally", -> beforeEach -> @@ -86,19 +77,13 @@ describe "HttpController", -> .calledWith(@user_id) .should.equal true - it "should look up each contact in web for their details", -> - for user_id, data of @contacts - @WebApiManager.getUserDetails - .calledWith(user_id) - .should.equal true - it "should return a sorted list of contacts by count and timestamp", -> @res.send .calledWith({ - contacts: [ - { id: "user-id-2", email: "jane@example.com", first_name: "Sarah", last_name: "Example" } - { id: "user-id-1", email: "joe@example.com", first_name: "Joe", last_name: "Example" } - { id: "user-id-3", email: "sam@example.com", first_name: "Sam", last_name: "Example" } + contact_ids: [ + "user-id-2" + "user-id-1" + "user-id-3" ] }) .should.equal true @@ -112,9 +97,9 @@ describe "HttpController", -> it "should return the most commonly used contacts up to the limit", -> @res.send .calledWith({ - contacts: [ - { id: "user-id-2", email: "jane@example.com", first_name: "Sarah", last_name: "Example" } - { id: "user-id-1", email: "joe@example.com", first_name: "Joe", last_name: "Example" } + contact_ids: [ + "user-id-2" + "user-id-1" ] }) .should.equal true @@ -127,7 +112,7 @@ describe "HttpController", -> it "should return an empty list", -> @res.send .calledWith({ - contacts: [] + contact_ids: [] }) .should.equal true