|
|
@@ -17,8 +17,8 @@ const { expect } = chai
|
|
|
const modulePath = '../../../app/js/HttpController.js'
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
-describe('HttpController', function() {
|
|
|
- beforeEach(function() {
|
|
|
+describe('HttpController', function () {
|
|
|
+ beforeEach(function () {
|
|
|
this.HttpController = SandboxedModule.require(modulePath, {
|
|
|
requires: {
|
|
|
'./ContactManager': (this.ContactManager = {}),
|
|
|
@@ -36,43 +36,43 @@ describe('HttpController', function() {
|
|
|
return (this.next = sinon.stub())
|
|
|
})
|
|
|
|
|
|
- describe('addContact', function() {
|
|
|
- beforeEach(function() {
|
|
|
+ describe('addContact', function () {
|
|
|
+ beforeEach(function () {
|
|
|
this.req.params = { user_id: this.user_id }
|
|
|
return (this.ContactManager.touchContact = sinon.stub().callsArg(2))
|
|
|
})
|
|
|
|
|
|
- describe('with a valid user_id and contact_id', function() {
|
|
|
- beforeEach(function() {
|
|
|
+ describe('with a valid user_id and contact_id', function () {
|
|
|
+ beforeEach(function () {
|
|
|
this.req.body = { contact_id: this.contact_id }
|
|
|
return this.HttpController.addContact(this.req, this.res, this.next)
|
|
|
})
|
|
|
|
|
|
- it("should update the contact in the user's contact list", function() {
|
|
|
+ it("should update the contact in the user's contact list", function () {
|
|
|
return this.ContactManager.touchContact
|
|
|
.calledWith(this.user_id, this.contact_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
- it("should update the user in the contact's contact list", function() {
|
|
|
+ it("should update the user in the contact's contact list", function () {
|
|
|
return this.ContactManager.touchContact
|
|
|
.calledWith(this.contact_id, this.user_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
- return it('should send back a 204 status', function() {
|
|
|
+ return it('should send back a 204 status', function () {
|
|
|
this.res.status.calledWith(204).should.equal(true)
|
|
|
return this.res.end.called.should.equal(true)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- return describe('with an invalid contact id', function() {
|
|
|
- beforeEach(function() {
|
|
|
+ return describe('with an invalid contact id', function () {
|
|
|
+ beforeEach(function () {
|
|
|
this.req.body = { contact_id: '' }
|
|
|
return this.HttpController.addContact(this.req, this.res, this.next)
|
|
|
})
|
|
|
|
|
|
- return it('should return 400, Bad Request', function() {
|
|
|
+ return it('should return 400, Bad Request', function () {
|
|
|
this.res.status.calledWith(400).should.equal(true)
|
|
|
return this.res.send
|
|
|
.calledWith('contact_id should be a non-blank string')
|
|
|
@@ -81,8 +81,8 @@ describe('HttpController', function() {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- return describe('getContacts', function() {
|
|
|
- beforeEach(function() {
|
|
|
+ return describe('getContacts', function () {
|
|
|
+ beforeEach(function () {
|
|
|
this.req.params = { user_id: this.user_id }
|
|
|
const now = Date.now()
|
|
|
this.contacts = {
|
|
|
@@ -95,18 +95,18 @@ describe('HttpController', function() {
|
|
|
.callsArgWith(1, null, this.contacts))
|
|
|
})
|
|
|
|
|
|
- describe('normally', function() {
|
|
|
- beforeEach(function() {
|
|
|
+ describe('normally', function () {
|
|
|
+ beforeEach(function () {
|
|
|
return this.HttpController.getContacts(this.req, this.res, this.next)
|
|
|
})
|
|
|
|
|
|
- it('should look up the contacts in mongo', function() {
|
|
|
+ it('should look up the contacts in mongo', function () {
|
|
|
return this.ContactManager.getContacts
|
|
|
.calledWith(this.user_id)
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
|
|
|
- return it('should return a sorted list of contacts by count and timestamp', function() {
|
|
|
+ return it('should return a sorted list of contacts by count and timestamp', function () {
|
|
|
return this.res.send
|
|
|
.calledWith({
|
|
|
contact_ids: ['user-id-2', 'user-id-1', 'user-id-3']
|
|
|
@@ -115,13 +115,13 @@ describe('HttpController', function() {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('with more contacts than the limit', function() {
|
|
|
- beforeEach(function() {
|
|
|
+ describe('with more contacts than the limit', function () {
|
|
|
+ beforeEach(function () {
|
|
|
this.req.query = { limit: 2 }
|
|
|
return this.HttpController.getContacts(this.req, this.res, this.next)
|
|
|
})
|
|
|
|
|
|
- return it('should return the most commonly used contacts up to the limit', function() {
|
|
|
+ return it('should return the most commonly used contacts up to the limit', function () {
|
|
|
return this.res.send
|
|
|
.calledWith({
|
|
|
contact_ids: ['user-id-2', 'user-id-1']
|
|
|
@@ -130,15 +130,15 @@ describe('HttpController', function() {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('without a contact list', function() {
|
|
|
- beforeEach(function() {
|
|
|
+ describe('without a contact list', function () {
|
|
|
+ beforeEach(function () {
|
|
|
this.ContactManager.getContacts = sinon
|
|
|
.stub()
|
|
|
.callsArgWith(1, null, null)
|
|
|
return this.HttpController.getContacts(this.req, this.res, this.next)
|
|
|
})
|
|
|
|
|
|
- return it('should return an empty list', function() {
|
|
|
+ return it('should return an empty list', function () {
|
|
|
return this.res.send
|
|
|
.calledWith({
|
|
|
contact_ids: []
|