ResolvingAThreadTests.js 3.7 KB

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