2017-01-04 13:51:08 +00:00
|
|
|
{ObjectId} = require "../../../app/js/mongojs"
|
|
|
|
expect = require("chai").expect
|
|
|
|
crypto = require "crypto"
|
|
|
|
|
|
|
|
ChatClient = require "./helpers/ChatClient"
|
2018-01-29 12:01:26 +00:00
|
|
|
ChatApp = require "./helpers/ChatApp"
|
2017-01-04 13:51:08 +00:00
|
|
|
|
|
|
|
describe "Resolving a thread", ->
|
2018-01-29 12:01:26 +00:00
|
|
|
before (done) ->
|
2017-01-04 13:51:08 +00:00
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@user_id = ObjectId().toString()
|
2018-01-29 12:01:26 +00:00
|
|
|
ChatApp.ensureRunning done
|
|
|
|
|
2017-01-04 13:51:08 +00:00
|
|
|
describe "with a resolved thread", ->
|
|
|
|
before (done) ->
|
|
|
|
@thread_id = ObjectId().toString()
|
|
|
|
@content = "resolved message"
|
|
|
|
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 201
|
|
|
|
ChatClient.resolveThread @project_id, @thread_id, @user_id, (error, response, body) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 204
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should then list the thread as resolved", (done) ->
|
|
|
|
ChatClient.getThreads @project_id, (error, response, threads) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 200
|
|
|
|
expect(threads[@thread_id].resolved).to.equal true
|
2017-01-06 13:14:47 +00:00
|
|
|
expect(threads[@thread_id].resolved_by_user_id).to.equal @user_id
|
2017-01-04 13:51:08 +00:00
|
|
|
resolved_at = new Date(threads[@thread_id].resolved_at)
|
|
|
|
expect(new Date() - resolved_at).to.be.below 1000
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "when a thread is not resolved", ->
|
|
|
|
before (done) ->
|
|
|
|
@thread_id = ObjectId().toString()
|
|
|
|
@content = "open message"
|
|
|
|
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 201
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should not list the thread as resolved", (done) ->
|
|
|
|
ChatClient.getThreads @project_id, (error, response, threads) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 200
|
|
|
|
expect(threads[@thread_id].resolved).to.be.undefined
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "when a thread is resolved then reopened", ->
|
|
|
|
before (done) ->
|
|
|
|
@thread_id = ObjectId().toString()
|
|
|
|
@content = "resolved message"
|
|
|
|
ChatClient.sendMessage @project_id, @thread_id, @user_id, @content, (error, response, body) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 201
|
|
|
|
ChatClient.resolveThread @project_id, @thread_id, @user_id, (error, response, body) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 204
|
|
|
|
ChatClient.reopenThread @project_id, @thread_id, (error, response, body) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 204
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should not list the thread as resolved", (done) ->
|
|
|
|
ChatClient.getThreads @project_id, (error, response, threads) =>
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal 200
|
|
|
|
expect(threads[@thread_id].resolved).to.be.undefined
|
|
|
|
done()
|