chats.endpoint.Test.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 = '0de7295862dd11e69faffa163e8aee56'; //
  7. var targetUserId = '37959ddf86f211e6b394fa163e424525'; //
  8. var adminTeamId = 5; // 行政团队ID: 黄庄家庭医生团队
  9. var consultGroupId = 'bcfd47c57ea74ba19fa049222c76befd'; // 讨论组ID
  10. var at = '';
  11. describe('Chat api', function () {
  12. // 发送系统消息
  13. describe('when send SYSTEM message correctly', function () {
  14. it('should return 200', function (done) {
  15. var path = APIv1.Chats.Base + APIv1.Chats.SM;
  16. restTemplate.post(path)
  17. .send({
  18. to: userId,
  19. title: "系统消息",
  20. summary: "您有一条新的工作记录",
  21. contentType: "1",
  22. content: "患者已经签约,可以制定随访计划。"
  23. })
  24. .end(function (err, response) {
  25. if(response.status !== 200){
  26. console.log(response.body);
  27. }
  28. response.status.should.equal(200);
  29. done();
  30. });
  31. });
  32. });
  33. describe('when send SYSTEM message that user not exist', function () {
  34. it('should return 404', function (done) {
  35. var path = APIv1.Chats.Base + APIv1.Chats.SM;
  36. restTemplate.post(path)
  37. .send({
  38. to: "Rose Unknown",
  39. title: "System Message",
  40. summary: "You have new job",
  41. contentType: "1",
  42. content: "The patient has been followed in the scheduler, please make new follow plan as soon as possible."
  43. })
  44. .end(function (err, response) {
  45. response.status.should.equal(404);
  46. done();
  47. });
  48. });
  49. });
  50. // 发送私信
  51. describe('when send PRIVATE message correctly', function () {
  52. it('should return 200', function (done) {
  53. var path = APIv1.Chats.Base + APIv1.Chats.PM;
  54. restTemplate.post(path)
  55. .send({
  56. from: userId,
  57. to: targetUserId,
  58. contentType: 1,
  59. content: "此患者白细胞如此高,中性粒值也高,同时感染细菌与病毒吗?"
  60. })
  61. .end(function (err, response) {
  62. response.status.should.equal(200);
  63. done();
  64. });
  65. });
  66. });
  67. // 向行政团队发送群消息
  68. describe('when send GROUP of admin team message correctly', function () {
  69. it('should return 200', function (done) {
  70. var path = APIv1.Chats.Base + APIv1.Chats.GM;
  71. restTemplate.post(path)
  72. .send({
  73. from: userId,
  74. at: '',
  75. group: adminTeamId,
  76. groupType: 1,
  77. contentType: 1,
  78. content: "请问:居民签约人数是否达标"
  79. })
  80. .end(function (err, response) {
  81. if(response.status !== 200){
  82. console.log(response.body);
  83. }
  84. response.status.should.equal(200);
  85. done();
  86. });
  87. });
  88. });
  89. // 向讨论组发送群消息
  90. describe('when send GROUP of consult team message correctly', function () {
  91. it('should return 200', function (done) {
  92. var path = APIv1.Chats.Base + APIv1.Chats.GM;
  93. restTemplate.post(path)
  94. .send({
  95. from: '0de705f962dd11e69faffa163e8aee56',
  96. at: '794f637bd3c64b948b112f16911a7883',
  97. group: consultGroupId,
  98. groupType: 2,
  99. contentType: 1,
  100. content: "庄医生,患者体征数据是否正常?"
  101. })
  102. .end(function (err, response) {
  103. if(response.status !== 200){
  104. console.log(response.body);
  105. }
  106. response.status.should.equal(200);
  107. done();
  108. });
  109. });
  110. });
  111. // 所有聊天列表
  112. describe('when get ALL CHAT list', function () {
  113. it('should return 200 and all chat list', function (done) {
  114. var path = APIv1.Chats.Base + APIv1.Chats.List + "?user_id=" + userId;
  115. restTemplate.get(path)
  116. .end(function (err, response) {
  117. console.log("User " + userId + "'s all chat list: \n", response.body);
  118. response.status.should.equal(200);
  119. done();
  120. });
  121. });
  122. });
  123. // 未读组数量
  124. describe('when get ALL GROUP unread chat count', function () {
  125. it('should return 200 and group chat count', function (done) {
  126. var path = APIv1.Chats.Base + APIv1.Chats.GMUnreadCount + "?user_id=" + userId;
  127. restTemplate.get(path)
  128. .end(function (err, response) {
  129. console.log("User " + userId + "'s group chat count: \n", response.body);
  130. response.status.should.equal(200);
  131. done();
  132. });
  133. })
  134. });
  135. // 未读私信数量
  136. describe('when get ALL PRIVATE unread chat list', function () {
  137. it('should return 200 and private chat count', function (done) {
  138. var path = APIv1.Chats.Base + APIv1.Chats.PMUnreadCount + "?user_id=" + userId;
  139. restTemplate.get(path)
  140. .end(function (err, response) {
  141. console.log("User " + userId + "'s private chat count: \n", response.body);
  142. response.status.should.equal(200);
  143. done();
  144. });
  145. })
  146. });
  147. // 所有未读消息数量
  148. describe('when get ALL unread message count', function () {
  149. it('should return 200 and all unread message count', function (done) {
  150. var path = APIv1.Chats.Base + APIv1.Chats.UnreadMsgCount + "?user_id=" + userId;
  151. restTemplate.get(path)
  152. .end(function (err, response) {
  153. console.log("User " + userId + "'s all unread message count: \n", response.body);
  154. response.status.should.equal(200);
  155. done();
  156. });
  157. });
  158. });
  159. // 获取角标数
  160. describe('when get badge number', function () {
  161. it('shout return 200 and badge number', function (done) {
  162. var path = APIv1.Application.Base + APIv1.Application.BadgeNo + "?user_id=" + userId;
  163. restTemplate.get(path)
  164. .end(function (err, response) {
  165. console.log("User " + userId + "'s badge number: \n", response.body);
  166. response.status.should.equal(200);
  167. done();
  168. });
  169. });
  170. });
  171. });