chats.endpoint.Test.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. "use strict";
  2. var testConfig = require('../config');
  3. var APIv1 = require('../../../src/doctor/include/endpoints').APIv1;
  4. var should = require("should");
  5. var restTemplate = require('supertest').agent(testConfig.host);
  6. var userId = '48832ecc339111e6badcfa163e789456';
  7. describe('Chat api', function () {
  8. // 发送系统消息
  9. describe('when send SYSTEM message correctly', function () {
  10. it('should return 200', function (done) {
  11. var path = APIv1.Chats.Base + APIv1.Chats.SM;
  12. restTemplate.post(path)
  13. .send({
  14. to: "Rose",
  15. title: "System Message",
  16. summary: "You have new job",
  17. contentType: "1",
  18. content: "The patient has been followed in the scheduler, please make new follow plan as soon as possible."
  19. }
  20. ).end(function (err, response) {
  21. });
  22. });
  23. });
  24. // 发送私信
  25. describe('when send PRIVATE message correctly', function () {
  26. it('should return 200', function (done) {
  27. var path = APIv1.Chats.Base + APIv1.Chats.PM;
  28. restTemplate.post(path)
  29. .send({
  30. to: "Rose",
  31. title: "System Message",
  32. summary: "You have new job",
  33. contentType: "1",
  34. content: "The patient has been followed in the scheduler, please make new follow plan as soon as possible."
  35. })
  36. .end(function (err, response) {
  37. });
  38. });
  39. });
  40. // 发送群消息
  41. describe('when send PRIVATE message with bad message format', function () {
  42. it('should return 200', function (done) {
  43. var path = APIv1.Chats.Base + APIv1.Chats.PM;
  44. restTemplate.post(path)
  45. .send({
  46. from: userId,
  47. at: "Rose",
  48. group: "DiscussionGroupId",
  49. groupType: 1,
  50. contentType: 1,
  51. content: "The patient mess me up"
  52. })
  53. .end(function (err, response) {
  54. });
  55. restTemplate.post(path)
  56. .send({
  57. from: userId,
  58. at: "",
  59. group: "DiscussionGroupId",
  60. groupType: 1,
  61. contentType: 1,
  62. content: "The patient mess me up"
  63. }).end(function (err, response) {
  64. });
  65. });
  66. });
  67. // 所有聊天列表
  68. describe('when get ALL CHAT list', function () {
  69. it('should return 200 and all chat list', function (done) {
  70. var path = APIv1.Chats.Base + APIv1.Chats.List + "?user_id=" + userId;
  71. restTemplate.get(path)
  72. .end(function (err, response) {
  73. console.log("User " + userId + "'s all chat list: \n", response.body);
  74. response.status.should.equal(200);
  75. done();
  76. });
  77. });
  78. });
  79. // 未读组数量
  80. describe('when get ALL GROUP unread chat count', function () {
  81. it('should return 200 and group chat count', function (done) {
  82. var path = APIv1.Chats.Base + APIv1.Chats.GMUnreadCount + "?user_id=" + userId;
  83. restTemplate.get(path)
  84. .end(function (err, response) {
  85. console.log("User " + userId + "'s group chat count: \n", response.body);
  86. response.status.should.equal(200);
  87. done();
  88. });
  89. })
  90. });
  91. // 未读私信数量
  92. describe('when get ALL PRIVATE unread chat list', function () {
  93. it('should return 200 and private chat count', function (done) {
  94. var path = APIv1.Chats.Base + APIv1.Chats.PMUnreadCount + "?user_id=" + userId;
  95. restTemplate.get(path)
  96. .end(function (err, response) {
  97. console.log("User " + userId + "'s private chat count: \n", response.body);
  98. response.status.should.equal(200);
  99. done();
  100. });
  101. })
  102. });
  103. // 所有未读消息数量
  104. describe('when get ALL unread message count', function () {
  105. it('should return 200 and all unread message count', function (done) {
  106. var path = APIv1.Chats.Base + APIv1.Chats.UnreadMsgCount + "?user_id=" + userId;
  107. restTemplate.get(path)
  108. .end(function (err, response) {
  109. console.log("User " + userId + "'s all unread message count: \n", response.body);
  110. response.status.should.equal(200);
  111. done();
  112. });
  113. });
  114. });
  115. // 获取角标数
  116. describe('when get badge number', function () {
  117. it('shout return 200 and badge number', function (done) {
  118. var path = APIv1.Application.Base + APIv1.Application.BadgeNo + "?user_id=" + userId;
  119. restTemplate.get(path)
  120. .end(function (err, response) {
  121. console.log("User " + userId + "'s badge number: \n", response.body);
  122. response.status.should.equal(200);
  123. done();
  124. });
  125. });
  126. });
  127. });