im.client.user.Test.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * IM客户端单元测试。单元测试编写规则:至少对对每个接口执行正反例测试,若有条件可以增加接口的性能测试。
  3. *
  4. * @author sand
  5. * @since 2016/12/24
  6. */
  7. "use strict";
  8. var $ = require('jquery');
  9. let assert = require('assert');
  10. let imClient = require('../../src/client/im.client');
  11. // 测试会话用的数据, test data
  12. let TD = {
  13. DoctorA: {
  14. id: "cd92414c-5b06-11e6-8344-fa163e8aee56", // 周美丽医生
  15. token: "0PFWlKmLBN9YzhCfFWVgYA",
  16. clientId: "H6FYbDejks6VjMmW3uH7V6",
  17. platform: 0
  18. }
  19. };
  20. describe("User API", function () {
  21. /**
  22. * 用户API。测试范围:
  23. * 1 有效/无效用户ID登录/状态更新/退出
  24. */
  25. describe("login", function () {
  26. it("return success with valid user", function (done) {
  27. imClient.Users.login(TD.DoctorA.id, TD.DoctorA.token, TD.DoctorA.clientId, TD.DoctorA.platform,
  28. function (data) {
  29. assert.strictEqual(Object.keys(data).length, 0);
  30. done();
  31. },
  32. function (xhr, status, error) {
  33. assert.ok(false, xhr.responseJSON.message);
  34. done();
  35. });
  36. });
  37. it("return failed with invalid user", function (done) {
  38. done();
  39. });
  40. });
  41. describe("updateStatus", function () {
  42. it("return success with valid user", function (done) {
  43. imClient.Users.updateStatus(TD.DoctorA.id, true, function (data) {
  44. assert.strictEqual(Object.keys(data).length, 0);
  45. done();
  46. },
  47. function (xhr, status, error) {
  48. console.error(xhr.responseJSON.message);
  49. assert.strictEqual(xhr.status, 200);
  50. done();
  51. });
  52. });
  53. it("return failed with invalid user", function (done) {
  54. imClient.Users.updateStatus("invalid_user_id", true, function (data) {
  55. assert.ok(false, "Update status with invalid user id must NOT return success");
  56. done();
  57. },
  58. function (xhr, status, error) {
  59. assert.strictEqual(xhr.status, 404);
  60. done()
  61. });
  62. });
  63. });
  64. describe("logout", function () {
  65. it("return success with valid user", function (done) {
  66. imClient.Users.logout(TD.DoctorA.id, function (data) {
  67. assert.strictEqual(Object.keys(data).length, 0);
  68. done();
  69. },
  70. function (xhr, status, error) {
  71. assert.ok(false, xhr.responseJSON.message);
  72. done()
  73. });
  74. });
  75. it("return failed with invalid user id", function (done) {
  76. imClient.Users.logout("invalid_user_id", function (data) {
  77. assert.ok(false, "Logout with invalid user id must NOT return success");
  78. done();
  79. },
  80. function (xhr, status, error) {
  81. assert.strictEqual(xhr.status, 404);
  82. done()
  83. });
  84. });
  85. });
  86. });