added basic chat handler

This commit is contained in:
Henry Oswald 2014-07-02 17:28:05 +01:00
parent b81fac1cf4
commit 8670b543b9
5 changed files with 101 additions and 2 deletions

View file

@ -0,0 +1,26 @@
request = require("request")
settings = require("settings-sharelatex")
logger = require("logger-sharelatex")
module.exports =
sendMessage: (project_id, user_id, messageContent, callback)->
opts =
method:"post"
json:
content:messageContent
user_id:user_id
uri:"#{settings.apis.chat.url}/room/#{project_id}/messages"
request opts, (err, response, body)->
if err?
logger.err err:err, "problem sending new message to chat"
callback(err, body)
getMessages: (project_id, query, callback)->
opts =
uri:"#{settings.apis.chat.url}/room/#{project_id}/messages"
method:"get"
request opts, (err, response, body)->
callback(err, body)

View file

@ -23,6 +23,7 @@ module.exports =
new_email:req.query.new_email || "" new_email:req.query.new_email || ""
loginPage : (req, res)-> loginPage : (req, res)->
console.info req
res.render 'user/login', res.render 'user/login',
title: 'Login', title: 'Login',
redir: req.query.redir redir: req.query.redir

View file

@ -0,0 +1,74 @@
should = require('chai').should()
SandboxedModule = require('sandboxed-module')
assert = require('assert')
path = require('path')
sinon = require('sinon')
modulePath = path.join __dirname, "../../../../app/js/Features/Chat/ChatHandler"
expect = require("chai").expect
describe "ChatHandler", ->
beforeEach ->
@settings =
apis:
chat:
url:"chat.sharelatex.env"
@request = sinon.stub()
@ChatHandler = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
"logger-sharelatex": log:->
"request": @request
@project_id = "3213213kl12j"
@user_id = "2k3jlkjs9"
@messageContent = "my message here"
describe "sending message", ->
beforeEach ->
@messageResponse =
message:"Details"
@request.callsArgWith(1, null, null, @messageResponse)
it "should post the data to the chat api", (done)->
@ChatHandler.sendMessage @project_id, @user_id, @messageContent, (err)=>
@opts =
method:"post"
json:
content:@messageContent
user_id:@user_id
uri:"#{@settings.apis.chat.url}/room/#{@project_id}/messages"
@request.calledWith(@opts).should.equal true
done()
it "should return the message from the post", (done)->
@ChatHandler.sendMessage @project_id, @user_id, @messageContent, (err, returnedMessage)=>
returnedMessage.should.equal @messageResponse
done()
describe "get messages", ->
beforeEach ->
@returnedMessages = [{content:"hello world"}]
@request.callsArgWith(1, null, null, @returnedMessages)
it "should make get request for room to chat api", (done)->
@ChatHandler.getMessages @project_id, (err)=>
@opts =
method:"get"
uri:"#{@settings.apis.chat.url}/room/#{@project_id}/messages"
@request.calledWith(@opts).should.equal true
done()
it "should return the messages from the request", (done)->
@ChatHandler.getMessages @project_id, (err, returnedMessages)=>
returnedMessages.should.equal @returnedMessages
done()

View file

@ -4,7 +4,6 @@ Settings = require 'settings-sharelatex'
should = require("chai").should() should = require("chai").should()
MockRequest = require "../helpers/MockRequest" MockRequest = require "../helpers/MockRequest"
MockResponse = require "../helpers/MockResponse" MockResponse = require "../helpers/MockResponse"
tk = require 'timekeeper'
modulePath = '../../../../app/js/Features/Subscription/SubscriptionController' modulePath = '../../../../app/js/Features/Subscription/SubscriptionController'
mockSubscriptions = mockSubscriptions =

View file

@ -4,7 +4,6 @@ sinon = require 'sinon'
querystring = require 'querystring' querystring = require 'querystring'
modulePath = "../../../../app/js/Features/Subscription/SubscriptionHandler" modulePath = "../../../../app/js/Features/Subscription/SubscriptionHandler"
SubscriptionHandler = require modulePath SubscriptionHandler = require modulePath
tk = require 'timekeeper'
mockRecurlySubscriptions = mockRecurlySubscriptions =
"subscription-123-active": "subscription-123-active":