add in acceptance tests

This commit is contained in:
James Allen 2015-10-07 14:20:30 +01:00
parent b6106697a0
commit 3959cba071
3 changed files with 75 additions and 5 deletions

View file

@ -16,8 +16,8 @@ app = express()
app.use Metrics.http.monitor(logger)
app.get '/user/:user_id/contacts', HttpController.getUserContacts
app.post '/user/:user_id/contacts', bodyParser.json(limit: "2mb"), HttpController.addUserContacts
app.get '/user/:user_id/contacts', HttpController.getContacts
app.post '/user/:user_id/contacts', bodyParser.json(limit: "2mb"), HttpController.addContact
app.get '/status', (req, res)->
res.send('contacts is alive')
@ -33,4 +33,4 @@ port = Settings.internal.contacts.port
host = Settings.internal.contacts.host
app.listen port, host, (error) ->
throw error if error?
logger.info "Docstore starting up, listening on #{host}:#{port}"
logger.info "contacts starting up, listening on #{host}:#{port}"

View file

@ -3,8 +3,9 @@ http.globalAgent.maxSockets = 300
module.exports =
internal:
port: 3036
host: "localhost"
contacts:
port: 3036
host: "localhost"
mongo:
url: 'mongodb://127.0.0.1/sharelatex'

View file

@ -0,0 +1,69 @@
sinon = require "sinon"
chai = require("chai")
chai.should()
expect = chai.expect
ObjectId = require("mongojs").ObjectId
request = require "request"
async = require "async"
HOST = "http://localhost:3036"
describe "Getting Contacts", ->
describe "with no contacts", ->
beforeEach ->
@user_id = ObjectId().toString()
it "should return an empty array", (done) ->
request {
method: "GET"
url: "#{HOST}/user/#{@user_id}/contacts"
json: true
}, (error, response, body) ->
response.statusCode.should.equal 200
body.contact_ids.should.deep.equal []
done()
describe "with contacts", ->
beforeEach (done) ->
@user_id = ObjectId().toString()
@contact_id_1 = ObjectId().toString()
@contact_id_2 = ObjectId().toString()
@contact_id_3 = ObjectId().toString()
touchContact = (user_id, contact_id, cb) ->
request({
method: "POST"
url: "#{HOST}/user/#{user_id}/contacts"
json: {
contact_id: contact_id
}
}, cb)
async.series [
# 2 is preferred since touched twice, then 3 since most recent, then 1
(cb) => touchContact @user_id, @contact_id_1, cb
(cb) => touchContact @user_id, @contact_id_2, cb
(cb) => touchContact @user_id, @contact_id_2, cb
(cb) => touchContact @user_id, @contact_id_3, cb
], done
it "should return a sorted list of contacts", (done) ->
request {
method: "GET"
url: "#{HOST}/user/#{@user_id}/contacts"
json: true
}, (error, response, body) =>
response.statusCode.should.equal 200
body.contact_ids.should.deep.equal [@contact_id_2, @contact_id_3, @contact_id_1]
done()
it "should respect a limit and only return top X contacts", ->
request {
method: "GET"
url: "#{HOST}/user/#{@user_id}/contacts?limit=2"
json: true
}, (error, response, body) =>
response.statusCode.should.equal 200
body.contact_ids.should.deep.equal [@contact_id_2, @contact_id_3]
done()