Ver código fonte

增加消息发送单元测试

Sand 8 anos atrás
pai
commit
e5fa94b578

+ 15 - 15
src/server/models/user/users.js

@ -159,11 +159,11 @@ class Users extends RedisModel {
     */
    login(userId, platform, token, clientId) {
        let self = this;
        let loginFromApp = platform === PLATFORMS.Wechat;
        let loginFromApp = platform !== PLATFORMS.Wechat;
        let usersKey = REDIS_KEYS.Users;
        let userKey = self.makeRedisKey(REDIS_KEYS.User, userId);
        let userStatusKey = self.makeRedisKey(loginFromApp ? REDIS_KEYS.UserWechatStatus : REDIS_KEYS.UserWechatStatus, userId);
        let userStatusKey = self.makeRedisKey(loginFromApp ? REDIS_KEYS.UserAppStatus : REDIS_KEYS.UserWechatStatus, userId);
        let lastLoginTime = new Date();
        async.waterfall([
@ -180,9 +180,9 @@ class Users extends RedisModel {
            },
            // cache user info and app/wechat status
            function (userInfo, callback) {
                let multi = redisConn.multiAsync()
                let multi = redisConn.multi()
                    .zadd(usersKey, lastLoginTime.getMilliseconds(), userId)
                    .hmset(userKey, 'avatar', userInfo.avatar, 'birthdate', userInfo.birthdate,
                    .hmset(userKey, 'avatar', userInfo.avatar ? userInfo.avatar : '', 'birthdate', userInfo.birthdate? userInfo.birthdate : '',
                        'name', userInfo.name, 'role', loginFromApp ? 'doctor' : 'patient');
                if (loginFromApp) {
@ -201,15 +201,15 @@ class Users extends RedisModel {
            // cache sessions, participants, topics, messages
            function (callback) {
                SessionRepo.findAll(userId, function (err, sessions) {
                    for (let i = 0; i < sessions.length; ++i) {
                        let sessionId = sessions[i].id;
                        let name = sessions[i].name;
                        let type = sessions[i].type;
                        let createDate = sessions[i].create_date;
                    for (let session in sessions) {
                        let sessionId = session.id;
                        let name = session.name;
                        let type = session.type;
                        let createDate = session.create_date;
                        (function (sessionId, userId) {
                            // cache sessions
                            redisConn.multiAsync()
                            redisConn.multi()
                                .zadd(self.makeRedisKey(REDIS_KEYS.UserSessions, userId))
                                .hmset(self.makeRedisKey(REDIS_KEYS.Session, sessionId, 'name', name, 'type', type, 'create_date', createDate))
                                .execAsync().then(function (res) {
@ -223,9 +223,9 @@ class Users extends RedisModel {
                                        let participantRole = participant.participant_role;
                                        let score = new Date().getMilliseconds();
                                        redisConn.multiAsync()
                                            .zaddAsync(sessionParticipantsKey, participantId, score)
                                            .hsetAsync(sessionParticipantsRoleKey, participantId, participantRole)
                                        redisConn.multi()
                                            .zadd(sessionParticipantsKey, participantId, score)
                                            .hset(sessionParticipantsRoleKey, participantId, participantRole)
                                            .execAsync().then(function (res) {
                                        });
                                    }
@ -246,7 +246,7 @@ class Users extends RedisModel {
                                            timestamp: message.timestamp
                                        };
                                        redisConn.multiAsync()
                                        redisConn.multi()
                                            .hset(messagesKey, id, msgJson)
                                            .zadd(messagesByTimestampKey, id)
                                            .execAsync()
@ -266,7 +266,7 @@ class Users extends RedisModel {
                                        let endBy = topic.end_by;
                                        let startMesssageId = topic.start_message_id;
                                        let endMessageId = topic.end_message_id;
                                        redisConn.multiAsync()
                                        redisConn.multi()
                                            .zadd(topicsKey, topicId)
                                            .hmset(topicKey, 'name', name, 'session_id', sessionId, 'create_time',
                                                createTime, 'end_by', endBy, 'start_message_id',

+ 1 - 1
test/server/config.js

@ -1,3 +1,3 @@
"use strict";
module.exports.host = 'http://127.0.0.1:3000';
module.exports.host = 'http://127.0.0.1:3008';

+ 8 - 0
test/server/endpoints/sessions.endpoin.Test.js

@ -0,0 +1,8 @@
/**
 * 会话端点。
 *
 * author: Sand
 * since: 12/21/2016
 */
"use strict";

+ 4 - 3
test/server/node_modules/mongoose/lib/document.js

@ -587,12 +587,13 @@ Document.prototype.set = function(path, val, type, options) {
      if (pathtype === 'real' || pathtype === 'virtual') {
        // Check for setting single embedded schema to document (gh-3535)
        var p = path[key];
        if (this.schema.paths[pathName] &&
            this.schema.paths[pathName].$isSingleNested &&
            path[key] instanceof Document) {
          path[key] = path[key].toObject({virtuals: false});
          p = p.toObject({ virtuals: false, transform: false });
        }
        this.set(prefix + key, path[key], constructing);
        this.set(prefix + key, p, constructing);
      } else if (pathtype === 'nested' && path[key] instanceof Document) {
        this.set(prefix + key,
            path[key].toObject({transform: false}), constructing);
@ -2275,7 +2276,7 @@ function minimize(obj) {
    key = keys[i];
    val = obj[key];
    if (utils.isObject(val)) {
    if (utils.isObject(val) && !Buffer.isBuffer(val)) {
      obj[key] = minimize(val);
    }

+ 1 - 0
test/server/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js

@ -163,6 +163,7 @@ function listen(conn) {
  conn.db.on('reconnect', function() {
    conn.readyState = STATES.connected;
    conn.emit('reconnected');
    conn.onOpen();
  });
  conn.db.on('timeout', function(err) {
    var error = new Error(err && err.err || 'connection timeout');

+ 8 - 8
test/server/node_modules/mongoose/lib/model.js

@ -13,7 +13,6 @@ var utils = require('./utils');
var hasOwnProperty = utils.object.hasOwnProperty;
var isMongooseObject = utils.isMongooseObject;
var EventEmitter = require('events').EventEmitter;
var MongooseArray = require('./types/array');
var util = require('util');
var tick = utils.tick;
@ -838,6 +837,7 @@ Model.discriminator = function discriminator(name, schema) {
    var id = schema.options.id;
    var keys = Object.keys(schema.options);
    schema.options.discriminatorKey = baseSchema.options.discriminatorKey;
    for (var i = 0; i < keys.length; ++i) {
      var _key = keys[i];
@ -2347,12 +2347,12 @@ Model.geoNear = function(near, options, callback) {
 *
 *     // Find the max balance of all accounts
 *     Users.aggregate(
 *         { $group: { _id: null, maxBalance: { $max: '$balance' }}}
 *       , { $project: { _id: 0, maxBalance: 1 }}
 *       , function (err, res) {
 *       if (err) return handleError(err);
 *       console.log(res); // [ { maxBalance: 98000 } ]
 *     });
 *       { $group: { _id: null, maxBalance: { $max: '$balance' }}},
 *       { $project: { _id: 0, maxBalance: 1 }},
 *       function (err, res) {
 *         if (err) return handleError(err);
 *         console.log(res); // [ { maxBalance: 98000 } ]
 *       });
 *
 *     // Or use the aggregation pipeline builder.
 *     Users.aggregate()
@ -3082,7 +3082,7 @@ function convertTo_id(val) {
      }
    }
    if (val.isMongooseArray) {
      return new MongooseArray(val, val._path, val._parent);
      return val._schema.cast(val, val._parent);
    }
    return [].concat(val);

+ 2 - 2
test/server/node_modules/mongoose/lib/query.js

@ -2449,10 +2449,10 @@ Query.prototype._castUpdate = function _castUpdate(obj, overwrite) {
    val = ret[op];
    hasDollarKey = hasDollarKey || op.charAt(0) === '$';
    if (val &&
        val.constructor.name === 'Object' &&
        typeof val === 'object' &&
        (!overwrite || hasDollarKey)) {
      hasKeys |= this._walkUpdatePath(val, op);
    } else if (overwrite && ret.constructor.name === 'Object') {
    } else if (overwrite && ret && typeof ret === 'object') {
      // if we are just using overwrite, cast the query and then we will
      // *always* return the value, even if it is an empty object. We need to
      // set hasKeys above because we need to account for the case where the

+ 9 - 2
test/server/node_modules/mongoose/lib/schema.js

@ -896,8 +896,15 @@ function applyTimestampsToChildren(query) {
          timestamps = $path.schema.options.timestamps;
          createdAt = timestamps.createdAt || 'createdAt';
          updatedAt = timestamps.updatedAt || 'updatedAt';
          update.$push[key][updatedAt] = now;
          update.$push[key][createdAt] = now;
          if (update.$push[key].$each) {
            update.$push[key].$each.forEach(function(subdoc) {
              subdoc[updatedAt] = now;
              subdoc[createdAt] = now;
            });
          } else {
            update.$push[key][updatedAt] = now;
            update.$push[key][createdAt] = now;
          }
        }
      }
    }

+ 1 - 1
test/server/node_modules/mongoose/lib/schema/string.js

@ -57,7 +57,7 @@ SchemaString.prototype.constructor = SchemaString;
 *       values: ['opening', 'open', 'closing', 'closed'],
 *       message: 'enum validator failed for path `{PATH}` with value `{VALUE}`'
 *     }
 *     var s = new Schema({ state: { type: String, enum: enu })
 *     var s = new Schema({ state: { type: String, enum: enum })
 *     var M = db.model('M', s)
 *     var m = new M({ state: 'invalid' })
 *     m.save(function (err) {

+ 1 - 0
test/server/node_modules/mongoose/lib/types/subdocument.js

@ -58,6 +58,7 @@ Subdocument.prototype.markModified = function(path) {
};
Subdocument.prototype.$markValid = function(path) {
  Document.prototype.$markValid.call(this, path);
  if (this.$parent) {
    this.$parent.$markValid([this.$basePath, path].join('.'));
  }