chats.endpoint.Test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. 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. if(response.status === 200){
  118. console.log("User " + userId + "'s all chat list: \n", response.body);
  119. }
  120. response.status.should.equal(200);
  121. done();
  122. });
  123. });
  124. });
  125. // 最近联系对象
  126. describe('when get recent chat list, including ', function () {
  127. it('should return 200 and recent chat list in date span', function (done) {
  128. var path = APIv1.Chats.Base + APIv1.Chats.Recent + "?user_id=" + userId + "&days=7";
  129. restTemplate.get(path)
  130. .end(function (err, response) {
  131. if(response.status === 200){
  132. console.log("User " + userId + "'s recent chats: \n", response.body);
  133. }
  134. response.status.should.equal(200);
  135. done();
  136. })
  137. });
  138. });
  139. // 与居民的聊天列表,包括含有居民的群
  140. describe('when get patient contained chat list', function () {
  141. it('should return 200 and chat list with patients', function (done) {
  142. var path = APIv1.Chats.Base + APIv1.Chats.ListWithPatient + "?user_id=" + 'D2016082203';
  143. restTemplate.get(path)
  144. .end(function (err, response) {
  145. if(response.status === 200){
  146. console.log("User " + userId + "'s chats with patients: \n", response.body);
  147. }
  148. response.status.should.equal(200);
  149. done();
  150. })
  151. });
  152. });
  153. // 与医生的聊天列表,不包含有居民的群
  154. describe('when get doctor contained only chat list', function () {
  155. it('should return 200 and chat list with doctors', function (done) {
  156. var path = APIv1.Chats.Base + APIv1.Chats.ListWithDoctor + "?user_id=0de7421c62dd11e69faffa163e8aee56";
  157. restTemplate.get(path)
  158. .end(function (err, response) {
  159. if(response.status === 200){
  160. console.log("User " + userId + "'s chats with doctors: \n", response.body);
  161. }
  162. response.status.should.equal(200);
  163. done();
  164. })
  165. });
  166. });
  167. // 所有未读组消息数
  168. describe('when get ALL GROUP unread chat count', function () {
  169. it('should return 200 and group chat count', function (done) {
  170. var path = APIv1.Chats.Base + APIv1.Chats.GMUnreadCount + "?user_id=" + userId;
  171. restTemplate.get(path)
  172. .end(function (err, response) {
  173. if(response.status === 200) {
  174. console.log("User " + userId + "'s group chat count: \n", response.body);
  175. }
  176. response.status.should.equal(200);
  177. done();
  178. });
  179. })
  180. });
  181. // 所有未读私信数
  182. describe('when get ALL PRIVATE unread chat list', function () {
  183. it('should return 200 and private chat count', function (done) {
  184. var path = APIv1.Chats.Base + APIv1.Chats.PMUnreadCount + "?user_id=" + userId;
  185. restTemplate.get(path)
  186. .end(function (err, response) {
  187. if(response.status === 200){
  188. console.log("User " + userId + "'s private chat count: \n", response.body);
  189. }
  190. response.status.should.equal(200);
  191. done();
  192. });
  193. })
  194. });
  195. // 所有未读消息数
  196. describe('when get ALL unread message count', function () {
  197. it('should return 200 and all unread message count', function (done) {
  198. var path = APIv1.Chats.Base + APIv1.Chats.UnreadMsgCount + "?user_id=" + userId;
  199. restTemplate.get(path)
  200. .end(function (err, response) {
  201. if(response.status === 200){
  202. console.log("User " + userId + "'s all unread message count: \n", response.body);
  203. }
  204. response.status.should.equal(200);
  205. done();
  206. });
  207. });
  208. });
  209. // 获取未读私信
  210. describe('when get unread private messages', function () {
  211. it('should return 200 and unread private messages', function (done) {
  212. var path = APIv1.Chats.Base + APIv1.Chats.PMUnread + "?user_id=D2016008240002&peer_id=D2016008240003";
  213. restTemplate.get(path)
  214. .end(function (err, response) {
  215. if(response.status === 200){
  216. console.log("User D2016008240002's unread private message with D2016008240003: \n", response.body);
  217. }
  218. response.status.should.equal(200);
  219. done();
  220. });
  221. })
  222. });
  223. // 获取未群消息
  224. describe('when get unread group messages', function () {
  225. it('should return 200 and unread group messages', function (done) {
  226. var path = APIv1.Chats.Base + APIv1.Chats.GMUnread + "?group_id=2&user_id=D20160322000003";
  227. restTemplate.get(path)
  228. .end(function (err, response) {
  229. if(response.status === 200){
  230. console.log("User D20160322000003's unread messages in group 2: \n", response.body);
  231. }
  232. response.status.should.equal(200);
  233. done();
  234. });
  235. })
  236. });
  237. // 获取角标数
  238. describe('when get badge number', function () {
  239. it('shout return 200 and badge number', function (done) {
  240. var path = APIv1.Application.Base + APIv1.Application.BadgeNo + "?user_id=" + userId;
  241. restTemplate.get(path)
  242. .end(function (err, response) {
  243. if(response.status === 200){
  244. console.log("User " + userId + "'s badge number: \n", response.body);
  245. }
  246. response.status.should.equal(200);
  247. done();
  248. });
  249. });
  250. });
  251. });