提交 66311500 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fix Room tests

上级 97c8cb02
......@@ -3,7 +3,7 @@
### Connecting ChatBots.
Wechaty is a Bot Framework for Wechat **Personal** Account, It can help you easy creating personal wechat bot in 7 lines of javascript code, with cross platform support to [linux](https://travis-ci.org/wechaty/wechaty), [win32](https://ci.appveyor.com/project/zixia/wechaty) and [darwin(OSX/Mac)](https://travis-ci.org/wechaty/wechaty).
Wechaty is a Bot Framework for Wechat **Personal** Account that help you easy creating personal wechat bot in 7 lines of javascript code, with cross platform support to [linux](https://travis-ci.org/wechaty/wechaty), [win32](https://ci.appveyor.com/project/zixia/wechaty) and [darwin(OSX/Mac)](https://travis-ci.org/wechaty/wechaty).
:octocat: <https://github.com/wechaty/wechaty>
:beetle: <https://github.com/wechaty/wechaty/issues>
......
......@@ -352,7 +352,7 @@ class PuppetWeb extends Puppet {
})
}
roomDelMember(room, contact) {
roomDel(room, contact) {
if (!this.bridge) {
return Promise.reject(new Error('roomDelMember fail: no bridge(yet)!'))
}
......@@ -365,7 +365,7 @@ class PuppetWeb extends Puppet {
})
}
roomAddMember(room, contact) {
roomAdd(room, contact) {
if (!this.bridge) {
return Promise.reject(new Error('fail: no bridge(yet)!'))
}
......@@ -378,14 +378,17 @@ class PuppetWeb extends Puppet {
})
}
roomModTopic(room, topic) {
roomTopic(room, topic) {
if (!this.bridge) {
return Promise.reject(new Error('fail: no bridge(yet)!'))
} else if (!room || typeof topic === 'undefined') {
return Promise.reject(new Error('room or topic not found'))
}
const roomId = room.id
const roomId = room.id
return this.bridge.roomModTopic(roomId, topic)
.catch(e => {
log.warn('PuppetWeb', 'roomModTopic(%s) rejected: %s', topic, e.message)
log.warn('PuppetWeb', 'roomTopic(%s) rejected: %s', topic, e.message)
throw e
})
}
......
......@@ -488,11 +488,11 @@
const UserNameListArg = UserNameList.map(n => { return { UserName: n } })
const chatroomFactory = WechatyBro.glue.chatroomFactory
const state = WechatyBro.glue.state
chatroomFactory.create(UserNameListArg)
.then(r => {
if (r.BaseResponse && 0 == r.BaseResponse.Ret || -2013 == e.BaseResponse.Ret) {
// be careful: key name is userName, not UserName! 20161001
WechatyBro.glue.state.go('chat', { userName: r.ChatRoomName })
state.go('chat', { userName: r.ChatRoomName }) // BE CAREFUL: key name is userName, not UserName! 20161001
}
})
.catch(e => {
......@@ -501,6 +501,7 @@
})
return 'no callback (yet)'
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
......@@ -559,6 +560,7 @@
, getUserName: getUserName
, getMsgImg: getMsgImg
// for Wechaty Room Class
, roomFind
, roomCreate
, roomAddMember
......
......@@ -21,8 +21,9 @@ class Room {
}
toString() { return this.id }
toStringEx() { return `Room(${this.obj.name}[${this.id}])` }
toStringEx() { return `Room(${this.obj.topic}[${this.id}])` }
// @private
isReady() {
return this.obj.memberList && this.obj.memberList.length
}
......@@ -42,7 +43,7 @@ class Room {
} else if (this.isReady()) {
return Promise.resolve(this)
} else if (this.obj.id) {
log.warn('Room', 'ready() has obj.id but memberList empty in room %s. reloading', this.obj.name)
log.warn('Room', 'ready() has obj.id but memberList empty in room %s. reloading', this.obj.topic)
}
contactGetter = contactGetter || Room.puppet.getContact.bind(Room.puppet)
......@@ -58,7 +59,7 @@ class Room {
})
}
name() { return UtilLib.plainText(this.obj.name) }
name() { return UtilLib.plainText(this.obj.topic) }
get(prop) { return this.obj[prop] || this.dirtyObj[prop] }
parse(rawObj) {
......@@ -68,7 +69,7 @@ class Room {
return {
id: rawObj.UserName
, encryId: rawObj.EncryChatRoomId // ???
, name: rawObj.NickName
, topic: rawObj.NickName
, memberList: this.parseMemberList(rawObj.MemberList)
}
}
......@@ -100,10 +101,11 @@ class Room {
if (!contact) {
throw new Error('contact not found')
}
return Room.puppet.roomDelMember(this, contact)
return Room.puppet.roomDel(this, contact)
.then(r => this.delLocal(contact))
}
// @private
delLocal(contact) {
log.verbose('Room', 'delLocal(%s)', contact)
......@@ -146,13 +148,17 @@ class Room {
throw new Error('contact not found')
}
return Room.puppet.roomAddMember(this, contact)
return Room.puppet.roomAdd(this, contact)
}
modTopic(topic) {
log.verbose('Room', 'modTopic(%s)', topic)
topic(newTopic) {
log.verbose('Room', 'topic(%s)', newTopic)
return Room.puppet.roomModTopic(this, topic)
if (newTopic) {
Room.puppet.roomTopic(this, newTopic)
return newTopic
}
return this.get('topic')
}
static create(contactList) {
......@@ -211,7 +217,7 @@ class Room {
})
.catch(e => {
log.error('Room', 'find() rejected: %s', e.message)
return [] // fail safe
return null // fail safe
})
}
......@@ -233,7 +239,7 @@ class Room {
})
.catch(e => {
log.error('Room', 'findAll() rejected: %s', e.message)
throw e
return [] // fail safe
})
}
......
......@@ -4,10 +4,11 @@ import {
, Room
, Contact
, Puppet
, PuppetWeb
, log
} from '../'
Room.attach(new Puppet())
Room.attach(new PuppetWeb())
test('Room smoke testing', async t => {
......@@ -37,7 +38,7 @@ test('Room smoke testing', async t => {
// .then(r => {
t.is(r.get('id') , UserName, 'UserName set')
t.is(r.get('name') , NickName, 'NickName set')
t.is(r.get('topic') , NickName, 'NickName set')
t.is(r.get('encryId') , EncryChatRoomId, 'EncryChatRoomId set')
const s = r.toString()
......@@ -65,22 +66,18 @@ test('Room smoke testing', async t => {
})
*/
test('TBW: Room static method', t => {
const r = Room.find({
id: 'xxx'
}, {
limit: 1
test('Room static method', async t => {
const room = await Room.find({
name: 'xxx'
})
t.truthy(r.id, 'Room.find')
t.truthy(room === null, 'should return null before login')
const rs = Room.findAll({
from: 'yyy'
}, {
limit: 2
const roomList = await Room.findAll({
name: 'yyy'
})
t.is(rs.length, 2, 'Room.findAll with limit 2')
t.is(roomList.length, 0, 'should return empty array before login')
// t.end()
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册