12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- /**
- * IM客户端单元测试。单元测试编写规则:至少对对每个接口执行正反例测试,若有条件可以增加接口的性能测试。
- *
- * @author sand
- * @since 2016/12/24
- */
- "use strict";
- var $ = require('jquery');
- let assert = require('assert');
- let imClient = require('../../src/client/im.client');
- // 测试会话用的数据, test data
- let TD = {
- DoctorA: {
- id: "cd92414c-5b06-11e6-8344-fa163e8aee56", // 周美丽医生
- token: "0PFWlKmLBN9YzhCfFWVgYA",
- clientId: "H6FYbDejks6VjMmW3uH7V6",
- platform: 0
- }
- };
- describe("User API", function () {
- /**
- * 用户API。测试范围:
- * 1 有效/无效用户ID登录/状态更新/退出
- */
- describe("login", function () {
- it("return success with valid user", function (done) {
- imClient.Users.login(TD.DoctorA.id, TD.DoctorA.token, TD.DoctorA.clientId, TD.DoctorA.platform,
- function (data) {
- assert.strictEqual(Object.keys(data).length, 0);
- done();
- },
- function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message);
- done();
- });
- });
- it("return failed with invalid user", function (done) {
- done();
- });
- });
- describe("updateStatus", function () {
- it("return success with valid user", function (done) {
- imClient.Users.updateStatus(TD.DoctorA.id, true, function (data) {
- assert.strictEqual(Object.keys(data).length, 0);
- done();
- },
- function (xhr, status, error) {
- console.error(xhr.responseJSON.message);
- assert.strictEqual(xhr.status, 200);
- done();
- });
- });
- it("return failed with invalid user", function (done) {
- imClient.Users.updateStatus("invalid_user_id", true, function (data) {
- assert.ok(false, "Update status with invalid user id must NOT return success");
- done();
- },
- function (xhr, status, error) {
- assert.strictEqual(xhr.status, 404);
- done()
- });
- });
- });
- describe("logout", function () {
- it("return success with valid user", function (done) {
- imClient.Users.logout(TD.DoctorA.id, function (data) {
- assert.strictEqual(Object.keys(data).length, 0);
- done();
- },
- function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message);
- done()
- });
- });
- it("return failed with invalid user id", function (done) {
- imClient.Users.logout("invalid_user_id", function (data) {
- assert.ok(false, "Logout with invalid user id must NOT return success");
- done();
- },
- function (xhr, status, error) {
- assert.strictEqual(xhr.status, 404);
- done()
- });
- });
- });
- });
|