ResolvingAThreadTests.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * decaffeinate suggestions:
  3. * DS102: Remove unnecessary code created because of implicit returns
  4. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  5. */
  6. const {ObjectId} = require("../../../app/js/mongojs");
  7. const { expect } = require("chai");
  8. const crypto = require("crypto");
  9. const ChatClient = require("./helpers/ChatClient");
  10. const ChatApp = require("./helpers/ChatApp");
  11. describe("Resolving a thread", function() {
  12. before(function(done) {
  13. this.project_id = ObjectId().toString();
  14. this.user_id = ObjectId().toString();
  15. return ChatApp.ensureRunning(done);
  16. });
  17. describe("with a resolved thread", function() {
  18. before(function(done) {
  19. this.thread_id = ObjectId().toString();
  20. this.content = "resolved message";
  21. return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => {
  22. expect(error).to.be.null;
  23. expect(response.statusCode).to.equal(201);
  24. return ChatClient.resolveThread(this.project_id, this.thread_id, this.user_id, (error, response, body) => {
  25. expect(error).to.be.null;
  26. expect(response.statusCode).to.equal(204);
  27. return done();
  28. });
  29. });
  30. });
  31. return it("should then list the thread as resolved", function(done) {
  32. return ChatClient.getThreads(this.project_id, (error, response, threads) => {
  33. expect(error).to.be.null;
  34. expect(response.statusCode).to.equal(200);
  35. expect(threads[this.thread_id].resolved).to.equal(true);
  36. expect(threads[this.thread_id].resolved_by_user_id).to.equal(this.user_id);
  37. const resolved_at = new Date(threads[this.thread_id].resolved_at);
  38. expect(new Date() - resolved_at).to.be.below(1000);
  39. return done();
  40. });
  41. });
  42. });
  43. describe("when a thread is not resolved", function() {
  44. before(function(done) {
  45. this.thread_id = ObjectId().toString();
  46. this.content = "open message";
  47. return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => {
  48. expect(error).to.be.null;
  49. expect(response.statusCode).to.equal(201);
  50. return done();
  51. });
  52. });
  53. return it("should not list the thread as resolved", function(done) {
  54. return ChatClient.getThreads(this.project_id, (error, response, threads) => {
  55. expect(error).to.be.null;
  56. expect(response.statusCode).to.equal(200);
  57. expect(threads[this.thread_id].resolved).to.be.undefined;
  58. return done();
  59. });
  60. });
  61. });
  62. return describe("when a thread is resolved then reopened", function() {
  63. before(function(done) {
  64. this.thread_id = ObjectId().toString();
  65. this.content = "resolved message";
  66. return ChatClient.sendMessage(this.project_id, this.thread_id, this.user_id, this.content, (error, response, body) => {
  67. expect(error).to.be.null;
  68. expect(response.statusCode).to.equal(201);
  69. return ChatClient.resolveThread(this.project_id, this.thread_id, this.user_id, (error, response, body) => {
  70. expect(error).to.be.null;
  71. expect(response.statusCode).to.equal(204);
  72. return ChatClient.reopenThread(this.project_id, this.thread_id, (error, response, body) => {
  73. expect(error).to.be.null;
  74. expect(response.statusCode).to.equal(204);
  75. return done();
  76. });
  77. });
  78. });
  79. });
  80. return it("should not list the thread as resolved", function(done) {
  81. return ChatClient.getThreads(this.project_id, (error, response, threads) => {
  82. expect(error).to.be.null;
  83. expect(response.statusCode).to.equal(200);
  84. expect(threads[this.thread_id].resolved).to.be.undefined;
  85. return done();
  86. });
  87. });
  88. });
  89. });