chats.endpoint.Test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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('API: Chat', 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. let now = new Date();
  17. now.setSeconds(now.getSeconds() + 2);
  18. let delay = now.toUTCString();
  19. restTemplate.post(path)
  20. .send({
  21. to: 'x1',
  22. title: "系统消息",
  23. summary: "您有一条新的工作记录",
  24. contentType: "1",
  25. content: "患者已经签约,可以制定随访计划。",
  26. delay: delay
  27. })
  28. .end(function (err, response) {
  29. if(response.status === 200){
  30. console.log(response.body);
  31. }
  32. response.status.should.equal(200);
  33. done();
  34. });
  35. });
  36. });
  37. describe('when send SYSTEM message that user not exist', function () {
  38. it('should return 404', function (done) {
  39. var path = APIv1.Chats.Base + APIv1.Chats.SM;
  40. restTemplate.post(path)
  41. .send({
  42. to: "Rose Unknown",
  43. title: "System Message",
  44. summary: "You have new job",
  45. contentType: "1",
  46. content: "The patient has been followed in the scheduler, please make new follow plan as soon as possible."
  47. })
  48. .end(function (err, response) {
  49. response.status.should.equal(404);
  50. done();
  51. });
  52. });
  53. });
  54. // 发送私信
  55. describe('when send PRIVATE message correctly', function () {
  56. it('should return 200', function (done) {
  57. var path = APIv1.Chats.Base + APIv1.Chats.PM;
  58. restTemplate.post(path)
  59. .send({
  60. from: userId,
  61. to: targetUserId,
  62. contentType: 1,
  63. content: "此患者白细胞如此高,中性粒值也高,同时感染细菌与病毒吗?"
  64. })
  65. .end(function (err, response) {
  66. response.status.should.equal(200);
  67. done();
  68. });
  69. });
  70. });
  71. // 向行政团队发送群消息
  72. describe('when send GROUP of admin team message correctly', function () {
  73. it('should return 200', function (done) {
  74. var path = APIv1.Chats.Base + APIv1.Chats.GM;
  75. restTemplate.post(path)
  76. .send({
  77. from: userId,
  78. at: '',
  79. group: adminTeamId,
  80. groupType: 1,
  81. contentType: 1,
  82. content: "请问:居民签约人数是否达标"
  83. })
  84. .end(function (err, response) {
  85. if(response.status === 200){
  86. console.log(response.body);
  87. }
  88. response.status.should.equal(200);
  89. done();
  90. });
  91. });
  92. });
  93. // 向讨论组发送群消息
  94. describe('when send GROUP of consult team message correctly', function () {
  95. it('should return 200', function (done) {
  96. var path = APIv1.Chats.Base + APIv1.Chats.GM;
  97. restTemplate.post(path)
  98. .send({
  99. from: '0de705f962dd11e69faffa163e8aee56',
  100. at: '794f637bd3c64b948b112f16911a7883',
  101. group: consultGroupId,
  102. groupType: 2,
  103. contentType: 1,
  104. content: "庄医生,患者体征数据是否正常?"
  105. })
  106. .end(function (err, response) {
  107. if(response.status === 200){
  108. console.log(response.body);
  109. }
  110. response.status.should.equal(200);
  111. done();
  112. });
  113. });
  114. });
  115. // 所有聊天列表
  116. describe('when get ALL CHAT list', function () {
  117. it('should return 200 and all chat list', function (done) {
  118. var path = APIv1.Chats.Base + APIv1.Chats.List + "?user_id=" + userId;
  119. restTemplate.get(path)
  120. .end(function (err, response) {
  121. if(response.status === 200){
  122. console.log("User " + userId + "'s all chat list: \n", response.body);
  123. }
  124. response.status.should.equal(200);
  125. done();
  126. });
  127. });
  128. });
  129. // 最近联系对象
  130. describe('when get recent chat list, including ', function () {
  131. it('should return 200 and recent chat list in date span', function (done) {
  132. var path = APIv1.Chats.Base + APIv1.Chats.Recent + "?user_id=" + userId + "&days=7";
  133. restTemplate.get(path)
  134. .end(function (err, response) {
  135. if(response.status === 200){
  136. console.log("User " + userId + "'s recent chats: \n", response.body);
  137. }
  138. response.status.should.equal(200);
  139. done();
  140. })
  141. });
  142. });
  143. // 与居民的聊天列表,包括含有居民的群
  144. describe('when get patient contained chat list', function () {
  145. it('should return 200 and chat list with patients', function (done) {
  146. var path = APIv1.Chats.Base + APIv1.Chats.ListWithPatient + "?user_id=" + 'D2016082203';
  147. restTemplate.get(path)
  148. .end(function (err, response) {
  149. if(response.status === 200){
  150. console.log("User " + userId + "'s chats with patients: \n", response.body);
  151. }
  152. response.status.should.equal(200);
  153. done();
  154. })
  155. });
  156. });
  157. // 与医生的聊天列表,不包含有居民的群
  158. describe('when get doctor contained only chat list', function () {
  159. it('should return 200 and chat list with doctors', function (done) {
  160. var path = APIv1.Chats.Base + APIv1.Chats.ListWithDoctor + "?user_id=0de7421c62dd11e69faffa163e8aee56";
  161. restTemplate.get(path)
  162. .end(function (err, response) {
  163. if(response.status === 200){
  164. console.log("User " + userId + "'s chats with doctors: \n", response.body);
  165. }
  166. response.status.should.equal(200);
  167. done();
  168. })
  169. });
  170. });
  171. // 所有未读组消息数
  172. describe('when get ALL GROUP unread chat count', function () {
  173. it('should return 200 and group chat count', function (done) {
  174. var path = APIv1.Chats.Base + APIv1.Chats.GMUnreadCount + "?user_id=" + userId;
  175. restTemplate.get(path)
  176. .end(function (err, response) {
  177. if(response.status === 200) {
  178. console.log("User " + userId + "'s group chat count: \n", response.body);
  179. }
  180. response.status.should.equal(200);
  181. done();
  182. });
  183. })
  184. });
  185. // 所有未读私信数
  186. describe('when get ALL PRIVATE unread chat list', function () {
  187. it('should return 200 and private chat count', function (done) {
  188. var path = APIv1.Chats.Base + APIv1.Chats.PMUnreadCount + "?user_id=" + userId;
  189. restTemplate.get(path)
  190. .end(function (err, response) {
  191. if(response.status === 200){
  192. console.log("User " + userId + "'s private chat count: \n", response.body);
  193. }
  194. response.status.should.equal(200);
  195. done();
  196. });
  197. })
  198. });
  199. // 所有未读消息数
  200. describe('when get ALL unread message count', function () {
  201. it('should return 200 and all unread message count', function (done) {
  202. var path = APIv1.Chats.Base + APIv1.Chats.UnreadMsgCount + "?user_id=" + userId;
  203. restTemplate.get(path)
  204. .end(function (err, response) {
  205. if(response.status === 200){
  206. console.log("User " + userId + "'s all unread message count: \n", response.body);
  207. }
  208. response.status.should.equal(200);
  209. done();
  210. });
  211. });
  212. });
  213. // 获取未读私信
  214. describe('when get unread private messages', function () {
  215. it('should return 200 and unread private messages', function (done) {
  216. var path = APIv1.Chats.Base + APIv1.Chats.PMUnread + "?user_id=D2016008240002&peer_id=D2016008240003";
  217. restTemplate.get(path)
  218. .end(function (err, response) {
  219. if(response.status === 200){
  220. console.log("User D2016008240002's unread private message with D2016008240003: \n", response.body);
  221. }
  222. response.status.should.equal(200);
  223. done();
  224. });
  225. })
  226. });
  227. // 获取未群消息
  228. describe('when get unread group messages', function () {
  229. it('should return 200 and unread group messages', function (done) {
  230. var path = APIv1.Chats.Base + APIv1.Chats.GMUnread + "?group_id=2&user_id=D20160322000003";
  231. restTemplate.get(path)
  232. .end(function (err, response) {
  233. if(response.status === 200){
  234. console.log("User D20160322000003's unread messages in group 2: \n", response.body);
  235. }
  236. response.status.should.equal(200);
  237. done();
  238. });
  239. })
  240. });
  241. // 获取角标数
  242. describe('when get badge number', function () {
  243. it('shout return 200 and badge number', function (done) {
  244. var path = APIv1.Application.Base + APIv1.Application.BadgeNo + "?user_id=" + userId;
  245. restTemplate.get(path)
  246. .end(function (err, response) {
  247. if(response.status === 200){
  248. console.log("User " + userId + "'s badge number: \n", response.body);
  249. }
  250. response.status.should.equal(200);
  251. done();
  252. });
  253. });
  254. });
  255. });