123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- /**
- * IM客户端单元测试。单元测试编写规则:至少对对每个接口执行正反例测试,若有条件可以增加接口的性能测试。
- *
- * 此部分为P2P会话测试。
- *
- * @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 = {
- SessionId: 'b07e8c4eabcb0c6fe790843026424afb2fb64d80',
- UnreadMessageCount: 0,
- P2P: {
- DoctorA: {
- id: "cd92414c-5b06-11e6-8344-fa163e8aee56",
- name: "周美丽",
- token: "0PFWlKmLBN9YzhCfFWVgYA",
- clientId: "H6FYbDejks6VjMmW3uH7V6",
- platform: 0
- },
- DoctorB: {
- id: "cd919343-5b06-11e6-8344-fa163e8aee56",
- name: "李毅",
- token: "0PFWlKmLBN9YzhCfFWVgYA",
- clientId: "H6FYbDejks6VjMmW3uH7V6",
- platform: 0
- }
- }
- };
- /**
- * 会话API。测试逻辑:
- * A医生登录
- * B医生登录
- *
- * A医生向B医生发送3条消息
- * B医生获取会话列表
- * B医生获取与A医生的会话未读消息列表
- *
- * B医生向A医生发送5条消息
- * A医生获取会话列表
- * A医生获取与A医生的会话未读消息列表
- *
- * A医生退出
- * B医生退出
- */
- describe("Session P2P", function () {
- // 登录
- describe("User login", function () {
- it("all user must be success", function (done) {
- imClient.Users.login(TD.P2P.DoctorA.id, TD.P2P.DoctorA.token, TD.P2P.DoctorA.clientId, TD.P2P.DoctorA.platform,
- function (data) {
- assert.ok(Object.keys(data).length === 0, "Doctor A login failed.");
- },
- function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message);
- });
- imClient.Users.login(TD.P2P.DoctorB.id, TD.P2P.DoctorB.token, TD.P2P.DoctorB.clientId, TD.P2P.DoctorB.platform,
- function (data) {
- assert.ok(Object.keys(data).length === 0, "Doctor B login failed.");
- done();
- },
- function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message);
- done();
- });
- });
- });
- // 发送消息: A -> B
- describe("Send message from A to B", function () {
- it("every message must be ok", function (done) {
- // 创建会话并发送消息
- imClient.Sessions.createP2pSession(TD.P2P.DoctorA.id, TD.P2P.DoctorB.id,
- function (session) {
- assert.ok(session.id.length > 0, "Create session failed.");
- TD.SessionId = session.id;
- imClient.Sessions.sendMessage(session.id, TD.P2P.DoctorA.id, TD.P2P.DoctorA.name, "李医生,你好", 1,
- function (data) {
- assert.ok(Object.keys(data).length > 0, "Send message failed.");
- }, function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message)
- });
- imClient.Sessions.sendMessage(session.id, TD.P2P.DoctorA.id, TD.P2P.DoctorA.name, "莲前社区糖尿病患者已进入随访跟踪状态", 1,
- function (data) {
- assert.ok(Object.keys(data).length > 0, "Send message failed.");
- }, function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message)
- });
- imClient.Sessions.sendMessage(session.id, TD.P2P.DoctorA.id, TD.P2P.DoctorA.name, "但处方信息还需要您的确认,请尽快回复,谢谢!", 1,
- function (data) {
- assert.ok(Object.keys(data).length > 0, "Send message failed.");
- done();
- }, function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message)
- });
- },
- function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message);
- done();
- });
- });
- });
- // 获取并发送消息: B -> A
- describe("Send message from B to A", function () {
- it("every message must be ok", function (done) {
- imClient.Sessions.getSessionsWithDoctor(TD.P2P.DoctorB.id, 0, 10,
- function (sessions) {
- let isPass = false;
- for (let i in sessions) {
- if (sessions[i].id == TD.SessionId) {
- isPass = true;
- TD.UnreadMessageCount = sessions[i].unread_count;
- break;
- }
- }
- assert.ok(isPass, "Get sessions with doctor failed.");
- // 读取未读消息数
- imClient.Sessions.getSessionUnreadMessageCount(TD.SessionId, TD.P2P.DoctorB,
- function (data) {
- assert.strictEqual(data.count, TD.UnreadMessageCount, "Get unread message count failed.");
- },
- function (xhr, status, error) {
- });
- },
- function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message);
- done();
- });
- });
- });
- // 退出
- describe("User logout", function () {
- it("all user must be success", function (done) {
- imClient.Users.logout(TD.P2P.DoctorA.id, function (data) {
- assert.ok(Object.keys(data).length === 0, "Doctor A logout failed.");
- }, function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message);
- });
- imClient.Users.logout(TD.P2P.DoctorB.id, function (data) {
- assert.ok(Object.keys(data).length === 0, "Doctor B logout failed.");
- done();
- }, function (xhr, status, error) {
- assert.ok(false, xhr.responseJSON.message);
- done();
- });
- });
- });
- });
|