@pacoyang/wechaty-puppet-wechat 0.28.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +14 -0
- package/.eslintrc.js +7 -0
- package/.github/workflows/npm.yml +91 -0
- package/.markdownlintrc +13 -0
- package/.travis.yml +62 -0
- package/.vscode/settings.json +73 -0
- package/CODEOWNERS +9 -0
- package/LICENSE +201 -0
- package/NOTICE +8 -0
- package/README.md +145 -0
- package/dist/examples/demo.d.ts +20 -0
- package/dist/examples/demo.d.ts.map +1 -0
- package/dist/examples/demo.js +113 -0
- package/dist/examples/demo.js.map +1 -0
- package/dist/scripts/retry-unit-tests.d.ts +10 -0
- package/dist/scripts/retry-unit-tests.d.ts.map +1 -0
- package/dist/scripts/retry-unit-tests.js +47 -0
- package/dist/scripts/retry-unit-tests.js.map +1 -0
- package/dist/src/bridge.d.ts +100 -0
- package/dist/src/bridge.d.ts.map +1 -0
- package/dist/src/bridge.js +927 -0
- package/dist/src/bridge.js.map +1 -0
- package/dist/src/bridge.spec.d.ts +21 -0
- package/dist/src/bridge.spec.d.ts.map +1 -0
- package/dist/src/bridge.spec.js +191 -0
- package/dist/src/bridge.spec.js.map +1 -0
- package/dist/src/config.d.ts +10 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +57 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/event.d.ts +23 -0
- package/dist/src/event.d.ts.map +1 -0
- package/dist/src/event.js +166 -0
- package/dist/src/event.js.map +1 -0
- package/dist/src/event.spec.d.ts +3 -0
- package/dist/src/event.spec.d.ts.map +1 -0
- package/dist/src/event.spec.js +41 -0
- package/dist/src/event.spec.js.map +1 -0
- package/dist/src/firer.d.ts +50 -0
- package/dist/src/firer.d.ts.map +1 -0
- package/dist/src/firer.js +409 -0
- package/dist/src/firer.js.map +1 -0
- package/dist/src/firer.spec.d.ts +21 -0
- package/dist/src/firer.spec.d.ts.map +1 -0
- package/dist/src/firer.spec.js +190 -0
- package/dist/src/firer.spec.js.map +1 -0
- package/dist/src/mod.d.ts +23 -0
- package/dist/src/mod.d.ts.map +1 -0
- package/dist/src/mod.js +28 -0
- package/dist/src/mod.js.map +1 -0
- package/dist/src/puppet-wechat.d.ts +164 -0
- package/dist/src/puppet-wechat.d.ts.map +1 -0
- package/dist/src/puppet-wechat.js +1287 -0
- package/dist/src/puppet-wechat.js.map +1 -0
- package/dist/src/puppet-wechat.spec.d.ts +21 -0
- package/dist/src/puppet-wechat.spec.d.ts.map +1 -0
- package/dist/src/puppet-wechat.spec.js +123 -0
- package/dist/src/puppet-wechat.spec.js.map +1 -0
- package/dist/src/pure-function-helpers/is-type.d.ts +3 -0
- package/dist/src/pure-function-helpers/is-type.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/is-type.js +12 -0
- package/dist/src/pure-function-helpers/is-type.js.map +1 -0
- package/dist/src/pure-function-helpers/message-extname.d.ts +3 -0
- package/dist/src/pure-function-helpers/message-extname.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/message-extname.js +44 -0
- package/dist/src/pure-function-helpers/message-extname.js.map +1 -0
- package/dist/src/pure-function-helpers/message-filename.d.ts +3 -0
- package/dist/src/pure-function-helpers/message-filename.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/message-filename.js +19 -0
- package/dist/src/pure-function-helpers/message-filename.js.map +1 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.d.ts +4 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.js +67 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.js.map +1 -0
- package/dist/src/pure-function-helpers/mod.d.ts +7 -0
- package/dist/src/pure-function-helpers/mod.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/mod.js +23 -0
- package/dist/src/pure-function-helpers/mod.js.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.d.ts +3 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.js +21 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.js.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.d.ts +21 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.js +37 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.js.map +1 -0
- package/dist/src/pure-function-helpers/web-message-type.d.ts +4 -0
- package/dist/src/pure-function-helpers/web-message-type.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/web-message-type.js +58 -0
- package/dist/src/pure-function-helpers/web-message-type.js.map +1 -0
- package/dist/src/pure-function-helpers/xml.d.ts +14 -0
- package/dist/src/pure-function-helpers/xml.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/xml.js +64 -0
- package/dist/src/pure-function-helpers/xml.js.map +1 -0
- package/dist/src/version.d.ts +6 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +9 -0
- package/dist/src/version.js.map +1 -0
- package/dist/src/version.spec.d.ts +3 -0
- package/dist/src/version.spec.d.ts.map +1 -0
- package/dist/src/version.spec.js +13 -0
- package/dist/src/version.spec.js.map +1 -0
- package/dist/src/web-schemas.d.ts +249 -0
- package/dist/src/web-schemas.d.ts.map +1 -0
- package/dist/src/web-schemas.js +118 -0
- package/dist/src/web-schemas.js.map +1 -0
- package/dist/src/wechaty-bro.js +868 -0
- package/dist/tests/puppeteer-contact.spec.d.ts +21 -0
- package/dist/tests/puppeteer-contact.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-contact.spec.js +67 -0
- package/dist/tests/puppeteer-contact.spec.js.map +1 -0
- package/dist/tests/puppeteer-friendship.spec.d.ts +21 -0
- package/dist/tests/puppeteer-friendship.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-friendship.spec.js +115 -0
- package/dist/tests/puppeteer-friendship.spec.js.map +1 -0
- package/dist/tests/puppeteer-message.spec.d.ts +21 -0
- package/dist/tests/puppeteer-message.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-message.spec.js +184 -0
- package/dist/tests/puppeteer-message.spec.js.map +1 -0
- package/dist/tests/puppeteer-room.spec.d.ts +21 -0
- package/dist/tests/puppeteer-room.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-room.spec.js +129 -0
- package/dist/tests/puppeteer-room.spec.js.map +1 -0
- package/dist/tests/puppeteer.spec.d.ts +21 -0
- package/dist/tests/puppeteer.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer.spec.js +213 -0
- package/dist/tests/puppeteer.spec.js.map +1 -0
- package/docs/images/puppeteer-logo.png +0 -0
- package/docs/images/wechaty-puppet-wechat.png +0 -0
- package/examples/demo.ts +130 -0
- package/package.json +94 -0
- package/scripts/generate-version.sh +18 -0
- package/scripts/npm-pack-testing.sh +49 -0
- package/scripts/package-publish-config-tag.sh +13 -0
- package/scripts/retry-unit-tests.ts +57 -0
- package/src/bridge.spec.ts +224 -0
- package/src/bridge.ts +1122 -0
- package/src/config.ts +71 -0
- package/src/event.spec.ts +41 -0
- package/src/event.ts +247 -0
- package/src/firer.spec.ts +208 -0
- package/src/firer.ts +530 -0
- package/src/mod.ts +29 -0
- package/src/puppet-wechat.spec.ts +149 -0
- package/src/puppet-wechat.ts +1659 -0
- package/src/pure-function-helpers/is-type.ts +7 -0
- package/src/pure-function-helpers/message-extname.ts +57 -0
- package/src/pure-function-helpers/message-filename.ts +25 -0
- package/src/pure-function-helpers/message-raw-payload-parser.ts +85 -0
- package/src/pure-function-helpers/mod.ts +6 -0
- package/src/pure-function-helpers/normalize-scan-status.spec.ts +44 -0
- package/src/pure-function-helpers/normalize-scan-status.ts +23 -0
- package/src/pure-function-helpers/web-message-type.ts +71 -0
- package/src/pure-function-helpers/xml.ts +79 -0
- package/src/typings.d.ts +19 -0
- package/src/version.spec.ts +10 -0
- package/src/version.ts +6 -0
- package/src/web-schemas.ts +298 -0
- package/src/wechaty-bro.js +868 -0
- package/tests/fixtures/inject-file.js +7 -0
- package/tests/fixtures/smoke-testing.ts +42 -0
- package/tests/puppeteer-contact.spec.ts +78 -0
- package/tests/puppeteer-friendship.spec.ts +157 -0
- package/tests/puppeteer-message.spec.ts +249 -0
- package/tests/puppeteer-room.spec.ts +166 -0
- package/tests/puppeteer.spec.ts +262 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
/**
|
|
3
|
+
* Wechaty - https://github.com/chatie/wechaty
|
|
4
|
+
*
|
|
5
|
+
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=puppeteer-contact.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puppeteer-contact.spec.d.ts","sourceRoot":"","sources":["../../tests/puppeteer-contact.spec.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;GAiBG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Wechaty - https://github.com/chatie/wechaty
|
|
5
|
+
*
|
|
6
|
+
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
// tslint:disable:arrow-parens
|
|
22
|
+
// tslint:disable:no-shadowed-variable
|
|
23
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
const tstest_1 = require("tstest");
|
|
28
|
+
// import {
|
|
29
|
+
// cloneClass,
|
|
30
|
+
// } from 'clone-class'
|
|
31
|
+
const config_1 = require("../src/config");
|
|
32
|
+
const puppet_wechat_1 = __importDefault(require("../src/puppet-wechat"));
|
|
33
|
+
(0, tstest_1.test)('Contact smoke testing', async (t) => {
|
|
34
|
+
/* tslint:disable:variable-name */
|
|
35
|
+
const UserName = '@0bb3e4dd746fdbd4a80546aef66f4085';
|
|
36
|
+
const NickName = 'NickNameTest';
|
|
37
|
+
const RemarkName = 'AliasTest';
|
|
38
|
+
const sandbox = tstest_1.sinon.createSandbox();
|
|
39
|
+
function mockContactPayload(id) {
|
|
40
|
+
config_1.log.verbose('PuppeteerContactTest', 'mockContactPayload(%s)', id);
|
|
41
|
+
return new Promise(resolve => {
|
|
42
|
+
if (id !== UserName)
|
|
43
|
+
return resolve({});
|
|
44
|
+
setImmediate(() => resolve({
|
|
45
|
+
NickName,
|
|
46
|
+
RemarkName,
|
|
47
|
+
UserName,
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const puppet = new puppet_wechat_1.default();
|
|
52
|
+
sandbox.stub(puppet, 'contactRawPayload').callsFake(mockContactPayload);
|
|
53
|
+
const contactPayload = await puppet.contactPayload(UserName);
|
|
54
|
+
// tslint:disable-next-line:variable-name
|
|
55
|
+
// const MyContact = cloneClass(Contact)
|
|
56
|
+
// MyContact.puppet = puppet as any // FIXME: any
|
|
57
|
+
// const c = new MyContact(UserName)
|
|
58
|
+
t.is(contactPayload.id, UserName, 'id/UserName right');
|
|
59
|
+
t.is(contactPayload.name, NickName, 'NickName set');
|
|
60
|
+
t.is(contactPayload.alias, RemarkName, 'should get the right alias from Contact');
|
|
61
|
+
sandbox.restore();
|
|
62
|
+
// const contact1 = await Contact.find({name: 'NickNameTest'})
|
|
63
|
+
// t.is(contact1.id, UserName, 'should find contact by name')
|
|
64
|
+
// const contact2 = await Contact.find({alias: 'AliasTest'})
|
|
65
|
+
// t.is(contact2.id, UserName, 'should find contact by alias')
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=puppeteer-contact.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puppeteer-contact.spec.js","sourceRoot":"","sources":["../../tests/puppeteer-contact.spec.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,8BAA8B;AAC9B,sCAAsC;;;;;AAEtC,mCAAoC;AACpC,WAAW;AACX,gBAAgB;AAChB,qCAAqC;AAErC,0CAEmC;AAEnC,yEAAgD;AAEhD,IAAA,aAAI,EAAC,uBAAuB,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IAEtC,kCAAkC;IAClC,MAAM,QAAQ,GAAG,mCAAmC,CAAA;IACpD,MAAM,QAAQ,GAAG,cAAc,CAAA;IAC/B,MAAM,UAAU,GAAG,WAAW,CAAA;I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@copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=puppeteer-friendship.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puppeteer-friendship.spec.d.ts","sourceRoot":"","sources":["../../tests/puppeteer-friendship.spec.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;GAiBG"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Wechaty - https://github.com/chatie/wechaty
|
|
5
|
+
*
|
|
6
|
+
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const tstest_1 = require("tstest");
|
|
23
|
+
const wechaty_puppet_1 = require("wechaty-puppet");
|
|
24
|
+
const puppet_wechat_1 = require("../src/puppet-wechat");
|
|
25
|
+
// class WechatyTest extends Wechaty {
|
|
26
|
+
// public initPuppetAccessory (puppet: PuppetWeChat) {
|
|
27
|
+
// super.initPuppetAccessory(puppet)
|
|
28
|
+
// }
|
|
29
|
+
// }
|
|
30
|
+
class PuppetTest extends puppet_wechat_1.PuppetWeChat {
|
|
31
|
+
contactRawPayload(id) {
|
|
32
|
+
return super.contactRawPayload(id);
|
|
33
|
+
}
|
|
34
|
+
roomRawPayload(id) {
|
|
35
|
+
return super.roomRawPayload(id);
|
|
36
|
+
}
|
|
37
|
+
messageRawPayload(id) {
|
|
38
|
+
return super.messageRawPayload(id);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
(0, tstest_1.test)('PuppetWeChatFriendship.receive smoke testing', async (t) => {
|
|
42
|
+
const puppet = new PuppetTest();
|
|
43
|
+
// const wechaty = new WechatyTest({ puppet })
|
|
44
|
+
// wechaty.initPuppetAccessory(puppet)
|
|
45
|
+
/* tslint:disable:max-line-length */
|
|
46
|
+
const rawMessagePayload = JSON.parse(`
|
|
47
|
+
{"MsgId":"3225371967511173931","FromUserName":"fmessage","ToUserName":"@f7321198e0349f1b38c9f2ef158f70eb","MsgType":37,"Content":"<msg fromusername=\\"wxid_a8d806dzznm822\\" encryptusername=\\"v1_c1e03a32c60dd9a9e14f1092132808a2de0ad363f79b303693654282954fbe4d3e12481166f4b841f28de3dd58b0bd54@stranger\\" fromnickname=\\"李卓桓.PreAngel\\" content=\\"我是群聊&quot;Wechaty&quot;的李卓桓.PreAngel\\" shortpy=\\"LZHPREANGEL\\" imagestatus=\\"3\\" scene=\\"14\\" country=\\"CN\\" province=\\"Beijing\\" city=\\"Haidian\\" sign=\\"投资人中最会飞的程序员。好友请加 918999 ,因为本号好友已满。\\" percard=\\"1\\" sex=\\"1\\" alias=\\"zixia008\\" weibo=\\"\\" weibonickname=\\"\\" albumflag=\\"0\\" albumstyle=\\"0\\" albumbgimgid=\\"911623988445184_911623988445184\\" snsflag=\\"49\\" snsbgimgid=\\"http://mmsns.qpic.cn/mmsns/zZSYtpeVianSQYekFNbuiajROicLficBzzeGuvQjnWdGDZ4budZovamibQnoKWba7D2LeuQRPffS8aeE/0\\" snsbgobjectid=\\"12183966160653848744\\" mhash=\\"\\" mfullhash=\\"\\" bigheadimgurl=\\"http://wx.qlogo.cn/mmhead/ver_1/xct7OPTbuU6iaS8gTaK2VibhRs3rATwnU1rCUwWu8ic89EGOynaic2Y4MUdKr66khhAplcfFlm7xbXhum5reania3fXDXH6CI9c3Bb4BODmYAh04/0\\" smallheadimgurl=\\"http://wx.qlogo.cn/mmhead/ver_1/xct7OPTbuU6iaS8gTaK2VibhRs3rATwnU1rCUwWu8ic89EGOynaic2Y4MUdKr66khhAplcfFlm7xbXhum5reania3fXDXH6CI9c3Bb4BODmYAh04/132\\" ticket=\\"v2_ba70dfbdb1b10168d61c1ab491be19e219db11ed5c28701f605efb4dccbf132f664d8a4c9ef6e852b2a4e8d8638be81d125c2e641f01903669539c53f1e582b2@stranger\\" opcode=\\"2\\" googlecontact=\\"\\" qrticket=\\"\\" chatroomusername=\\"2332413729@chatroom\\" sourceusername=\\"\\" sourcenickname=\\"\\"><brandlist count=\\"0\\" ver=\\"670564024\\"></brandlist></msg>","Status":3,"ImgStatus":1,"CreateTime":1475567560,"VoiceLength":0,"PlayLength":0,"FileName":"","FileSize":"","MediaId":"","Url":"","AppMsgType":0,"StatusNotifyCode":0,"StatusNotifyUserName":"","RecommendInfo":{"UserName":"@04a0fa314d0d8d50dc54e2ec908744ebf46b87404d143fd9a6692182dd90bd49","NickName":"李卓桓.PreAngel","Province":"北京","City":"海淀","Content":"我是群聊\\"Wechaty\\"的李卓桓.PreAngel","Signature":"投资人中最会飞的程序员。好友请加 918999 ,因为本号好友已满。","Alias":"zixia008","Scene":14,"AttrStatus":233251,"Sex":1,"Ticket":"v2_ba70dfbdb1b10168d61c1ab491be19e219db11ed5c28701f605efb4dccbf132f664d8a4c9ef6e852b2a4e8d8638be81d125c2e641f01903669539c53f1e582b2@stranger","OpCode":2,"HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@04a0fa314d0d8d50dc54e2ec908744ebf46b87404d143fd9a6692182dd90bd49&skey=@crypt_f9cec94b_5b073dca472bd5e41771d309bb8c37bd&msgid=3225371967511173931","MMFromVerifyMsg":true},"ForwardFlag":0,"AppInfo":{"AppID":"","Type":0},"HasProductId":0,"Ticket":"","ImgHeight":0,"ImgWidth":0,"SubMsgType":0,"NewMsgId":3225371967511174000,"MMPeerUserName":"fmessage","MMDigest":"李卓桓.PreAngel想要将你加为朋友","MMIsSend":false,"MMIsChatRoom":false,"MMUnread":true,"LocalID":"3225371967511173931","ClientMsgId":"3225371967511173931","MMActualContent":"<msg fromusername=\\"wxid_a8d806dzznm822\\" encryptusername=\\"v1_c1e03a32c60dd9a9e14f1092132808a2de0ad363f79b303693654282954fbe4d3e12481166f4b841f28de3dd58b0bd54@stranger\\" fromnickname=\\"李卓桓.PreAngel\\" content=\\"我是群聊&quot;Wechaty&quot;的李卓桓.PreAngel\\" shortpy=\\"LZHPREANGEL\\" imagestatus=\\"3\\" scene=\\"14\\" country=\\"CN\\" province=\\"Beijing\\" city=\\"Haidian\\" sign=\\"投资人中最会飞的程序员。好友请加 918999 ,因为本号好友已满。\\" percard=\\"1\\" sex=\\"1\\" alias=\\"zixia008\\" weibo=\\"\\" weibonickname=\\"\\" albumflag=\\"0\\" albumstyle=\\"0\\" albumbgimgid=\\"911623988445184_911623988445184\\" snsflag=\\"49\\" snsbgimgid=\\"http://mmsns.qpic.cn/mmsns/zZSYtpeVianSQYekFNbuiajROicLficBzzeGuvQjnWdGDZ4budZovamibQnoKWba7D2LeuQRPffS8aeE/0\\" snsbgobjectid=\\"12183966160653848744\\" mhash=\\"\\" mfullhash=\\"\\" bigheadimgurl=\\"http://wx.qlogo.cn/mmhead/ver_1/xct7OPTbuU6iaS8gTaK2VibhRs3rATwnU1rCUwWu8ic89EGOynaic2Y4MUdKr66khhAplcfFlm7xbXhum5reania3fXDXH6CI9c3Bb4BODmYAh04/0\\" smallheadimgurl=\\"http://wx.qlogo.cn/mmhead/ver_1/xct7OPTbuU6iaS8gTaK2VibhRs3rATwnU1rCUwWu8ic89EGOynaic2Y4MUdKr66khhAplcfFlm7xbXhum5reania3fXDXH6CI9c3Bb4BODmYAh04/132\\" ticket=\\"v2_ba70dfbdb1b10168d61c1ab491be19e219db11ed5c28701f605efb4dccbf132f664d8a4c9ef6e852b2a4e8d8638be81d125c2e641f01903669539c53f1e582b2@stranger\\" opcode=\\"2\\" googlecontact=\\"\\" qrticket=\\"\\" chatroomusername=\\"2332413729@chatroom\\" sourceusername=\\"\\" sourcenickname=\\"\\"><brandlist count=\\"0\\" ver=\\"670564024\\"></brandlist></msg>","MMActualSender":"fmessage","MMDigestTime":"15:52","MMDisplayTime":1475567560,"MMTime":"15:52"}
|
|
48
|
+
`);
|
|
49
|
+
const info = rawMessagePayload.RecommendInfo;
|
|
50
|
+
const hello = info.Content;
|
|
51
|
+
const ticket = info.Ticket;
|
|
52
|
+
const id = 'id';
|
|
53
|
+
const type = wechaty_puppet_1.FriendshipType.Receive;
|
|
54
|
+
const payload = {
|
|
55
|
+
contactId: info.UserName,
|
|
56
|
+
hello,
|
|
57
|
+
id,
|
|
58
|
+
ticket,
|
|
59
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
60
|
+
type,
|
|
61
|
+
};
|
|
62
|
+
const sandbox = tstest_1.sinon.createSandbox();
|
|
63
|
+
// Huan(202002)
|
|
64
|
+
// FIXME: Argument of type 'FriendshipPayloadReceive' is not assignable to parameter of type 'void | undefined'.
|
|
65
|
+
// Type 'FriendshipPayloadReceive' is not assignable to type 'void'.ts(2345)
|
|
66
|
+
sandbox.stub(puppet, 'friendshipPayload').resolves(payload);
|
|
67
|
+
// sandbox.stub(puppet, 'friendshipPayloadCache').returns(payload)
|
|
68
|
+
// const contact = wechaty.Contact.load(info.UserName)
|
|
69
|
+
// const contactPayload = await puppet.contactPayload(info.UserName)
|
|
70
|
+
// const fr = wechaty.Friendship.load(id)
|
|
71
|
+
// await fr.ready()
|
|
72
|
+
const friendshipPayload = await puppet.friendshipPayload(id);
|
|
73
|
+
t.equal(friendshipPayload.hello, '我是群聊"Wechaty"的李卓桓.PreAngel', 'should has right request message');
|
|
74
|
+
t.equal(friendshipPayload.contactId, info.UserName, 'should have a Contact id');
|
|
75
|
+
t.equal(friendshipPayload.type, wechaty_puppet_1.FriendshipType.Receive, 'should be receive type');
|
|
76
|
+
sandbox.restore();
|
|
77
|
+
});
|
|
78
|
+
(0, tstest_1.test)('PuppetWeChatFriendship.confirm smoke testing', async (t) => {
|
|
79
|
+
const CONTACT_ID = 'contact-id';
|
|
80
|
+
const puppet = new PuppetTest();
|
|
81
|
+
// const wechaty = new WechatyTest({ puppet })
|
|
82
|
+
// wechaty.initPuppetAccessory(puppet)
|
|
83
|
+
/* tslint:disable:max-line-length */
|
|
84
|
+
const rawMessagePayload = JSON.parse(`
|
|
85
|
+
{"MsgId":"3382012679535022763","FromUserName":"@04a0fa314d0d8d50dc54e2ec908744ebf46b87404d143fd9a6692182dd90bd49","ToUserName":"@f7321198e0349f1b38c9f2ef158f70eb","MsgType":10000,"Content":"You have added 李卓桓.PreAngel as your WeChat contact. Start chatting!","Status":4,"ImgStatus":1,"CreateTime":1475569920,"VoiceLength":0,"PlayLength":0,"FileName":"","FileSize":"","MediaId":"","Url":"","AppMsgType":0,"StatusNotifyCode":0,"StatusNotifyUserName":"","RecommendInfo":{"UserName":"","NickName":"","QQNum":0,"Province":"","City":"","Content":"","Signature":"","Alias":"","Scene":0,"VerifyFlag":0,"AttrStatus":0,"Sex":0,"Ticket":"","OpCode":0},"ForwardFlag":0,"AppInfo":{"AppID":"","Type":0},"HasProductId":0,"Ticket":"","ImgHeight":0,"ImgWidth":0,"SubMsgType":0,"NewMsgId":3382012679535022600,"MMPeerUserName":"@04a0fa314d0d8d50dc54e2ec908744ebf46b87404d143fd9a6692182dd90bd49","MMDigest":"You have added 李卓桓.PreAngel as your WeChat contact. Start chatting!","MMIsSend":false,"MMIsChatRoom":false,"LocalID":"3382012679535022763","ClientMsgId":"3382012679535022763","MMActualContent":"You have added 李卓桓.PreAngel as your WeChat contact. Start chatting!","MMActualSender":"@04a0fa314d0d8d50dc54e2ec908744ebf46b87404d143fd9a6692182dd90bd49","MMDigestTime":"16:32","MMDisplayTime":1475569920,"MMTime":"16:32"}
|
|
86
|
+
`);
|
|
87
|
+
const friendshipPayload = {
|
|
88
|
+
contactId: CONTACT_ID,
|
|
89
|
+
id: 'id',
|
|
90
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
91
|
+
type: wechaty_puppet_1.FriendshipType.Confirm,
|
|
92
|
+
};
|
|
93
|
+
const sandbox = tstest_1.sinon.createSandbox();
|
|
94
|
+
sandbox.stub(puppet, 'messageRawPayload').resolves(rawMessagePayload);
|
|
95
|
+
sandbox.stub(puppet, 'contactPayload').resolves({});
|
|
96
|
+
// sandbox.stub(puppet, 'contactPayloadCache') .returns({})
|
|
97
|
+
/**
|
|
98
|
+
* Huan(202002)
|
|
99
|
+
* FIXME: Argument of type 'FriendshipPayloadReceive' is not assignable to parameter of type 'void | undefined'.
|
|
100
|
+
* Type 'FriendshipPayloadReceive' is not assignable to type 'void'.ts(2345)
|
|
101
|
+
*/
|
|
102
|
+
sandbox.stub(puppet, 'friendshipPayload').resolves(friendshipPayload);
|
|
103
|
+
// sandbox.stub(puppet, 'friendshipPayloadCache') .returns(friendshipPayload)
|
|
104
|
+
// const msg = wechaty.Message.create(rawMessagePayload.MsgId)
|
|
105
|
+
// await msg.ready()
|
|
106
|
+
const msgPayload = await puppet.messagePayload(rawMessagePayload.MsgId);
|
|
107
|
+
t.true(/^You have added (.+) as your WeChat contact. Start chatting!$/.test(msgPayload.text || ''), 'should match confirm message');
|
|
108
|
+
// const fr = wechaty.Friendship.load('xx')
|
|
109
|
+
// await fr.ready()
|
|
110
|
+
const friendshipPayload2 = await puppet.friendshipPayload('xx');
|
|
111
|
+
t.is(friendshipPayload2.contactId, CONTACT_ID, 'should have a Contact id');
|
|
112
|
+
t.is(friendshipPayload2.type, wechaty_puppet_1.FriendshipType.Confirm, 'should be confirm type');
|
|
113
|
+
sandbox.restore();
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=puppeteer-friendship.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puppeteer-friendship.spec.js","sourceRoot":"","sources":["../../tests/puppeteer-friendship.spec.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;;;;GAiBG;;AAEH,mCAGyB;AAEzB,mDAG+C;AAE/C,wDAEqD;AAKrD,sCAAsC;AACtC,wDAAwD;AACxD,wCAAwC;AACxC,MAAM;AACN,IAAI;AAEJ,MAAM,UAAW,SAAQ,4BAAY;IAE5B,iBAAiB,CAAE,EAAU;QAClC,OAAO,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAA;IACpC,CAAC;IAEM,cAAc,CAAE,EAAU;QAC/B,OAAO,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAA;IACjC,CAAC;IAEM,iBAAiB,CAAE,EAAU;QAClC,OAAO,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAA;IACpC,CAAC;CAEF;AAED,IAAA,aAAI,EAAC,8CAA8C,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC/D,MAAM,MAAM,GAAI,IAAI,UAAU,EAAE,CAAA;IAChC,8CAA8C;IAC9C,sCAAsC;IAEtC,oCAAoC;IACpC,MAAM,iBAAiB,GAAyB,IAAI,CAAC,KAAK,CAAC;;GAE1D,CAAC,CA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AAC,EAAE,CAAC,kBAAkB,CAAC,IAAI,EAAE,+BAAc,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAA;IAE/E,OAAO,CAAC,OAAO,EAAE,CAAA;AACnB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
/**
|
|
3
|
+
* Wechaty - https://github.com/chatie/wechaty
|
|
4
|
+
*
|
|
5
|
+
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=puppeteer-message.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puppeteer-message.spec.d.ts","sourceRoot":"","sources":["../../tests/puppeteer-message.spec.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;GAiBG"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Wechaty - https://github.com/chatie/wechaty
|
|
5
|
+
*
|
|
6
|
+
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
// tslint:disable:no-shadowed-variable
|
|
23
|
+
// tslint:disable:max-classes-per-file
|
|
24
|
+
// tslint:disable:arrow-parens
|
|
25
|
+
// tslint:disable:ter-no-irregular-whitespace
|
|
26
|
+
const tstest_1 = require("tstest");
|
|
27
|
+
const config_1 = require("../src/config");
|
|
28
|
+
const wechaty_puppet_1 = require("wechaty-puppet");
|
|
29
|
+
const puppet_wechat_1 = require("../src/puppet-wechat");
|
|
30
|
+
// class WechatyTest extends Wechaty {
|
|
31
|
+
// public initPuppetAccessory (puppet: PuppetWeChat) {
|
|
32
|
+
// super.initPuppetAccessory(puppet)
|
|
33
|
+
// }
|
|
34
|
+
// }
|
|
35
|
+
class PuppetTest extends puppet_wechat_1.PuppetWeChat {
|
|
36
|
+
contactRawPayload(id) {
|
|
37
|
+
return super.contactRawPayload(id);
|
|
38
|
+
}
|
|
39
|
+
roomRawPayload(id) {
|
|
40
|
+
return super.roomRawPayload(id);
|
|
41
|
+
}
|
|
42
|
+
messageRawPayload(id) {
|
|
43
|
+
return super.messageRawPayload(id);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// class PuppetWeChatTest extends PuppetWeChat {
|
|
47
|
+
// public id?: string = undefined
|
|
48
|
+
// }
|
|
49
|
+
(0, tstest_1.test)('constructor()', async (t) => {
|
|
50
|
+
const puppet = new PuppetTest();
|
|
51
|
+
// const wechaty = new WechatyTest({ puppet })
|
|
52
|
+
// wechaty.initPuppetAccessory(puppet)
|
|
53
|
+
const MOCK_USER_ID = 'TEST-USER-ID';
|
|
54
|
+
/* tslint:disable:max-line-length */
|
|
55
|
+
const rawPayload = JSON.parse('{"MsgId":"179242112323992762","FromUserName":"@0bb3e4dd746fdbd4a80546aef66f4085","ToUserName":"@16d20edf23a3bf3bc71bb4140e91619f3ff33b4e33f7fcd25e65c1b02c7861ab","MsgType":1,"Content":"test123","Status":3,"ImgStatus":1,"CreateTime":1461652670,"VoiceLength":0,"PlayLength":0,"FileName":"","FileSize":"","MediaId":"","Url":"","AppMsgType":0,"StatusNotifyCode":0,"StatusNotifyUserName":"","RecommendInfo":{"UserName":"","NickName":"","QQNum":0,"Province":"","City":"","Content":"","Signature":"","Alias":"","Scene":0,"VerifyFlag":0,"AttrStatus":0,"Sex":0,"Ticket":"","OpCode":0},"ForwardFlag":0,"AppInfo":{"AppID":"","Type":0},"HasProductId":0,"Ticket":"","ImgHeight":0,"ImgWidth":0,"SubMsgType":0,"NewMsgId":179242112323992770,"MMPeerUserName":"@0bb3e4dd746fdbd4a80546aef66f4085","MMDigest":"test123","MMIsSend":false,"MMIsChatRoom":false,"MMUnread":true,"LocalID":"179242112323992762","ClientMsgId":"179242112323992762","MMActualContent":"test123","MMActualSender":"@0bb3e4dd746fdbd4a80546aef66f4085","MMDigestTime":"14:37","MMDisplayTime":1461652670,"MMTime":"14:37"}');
|
|
56
|
+
const EXPECTED = {
|
|
57
|
+
from: '@0bb3e4dd746fdbd4a80546aef66f4085',
|
|
58
|
+
id: '179242112323992762',
|
|
59
|
+
};
|
|
60
|
+
const sandbox = tstest_1.sinon.createSandbox();
|
|
61
|
+
const mockMessagePayload = async ( /* _: string */) => {
|
|
62
|
+
const payload = {
|
|
63
|
+
fromId: EXPECTED.from,
|
|
64
|
+
id: EXPECTED.id,
|
|
65
|
+
mentionIdList: [],
|
|
66
|
+
timestamp: Date.now(),
|
|
67
|
+
toId: 'toId',
|
|
68
|
+
type: wechaty_puppet_1.MessageType.Text,
|
|
69
|
+
};
|
|
70
|
+
return payload;
|
|
71
|
+
};
|
|
72
|
+
sandbox.stub(puppet, 'contactPayload').returns({});
|
|
73
|
+
// sandbox.stub(puppet, 'contactPayloadCache').returns({})
|
|
74
|
+
sandbox.stub(puppet, 'roomPayload').returns({});
|
|
75
|
+
// sandbox.stub(puppet, 'roomPayloadCache').returns({})
|
|
76
|
+
sandbox.stub(puppet, 'messagePayload').callsFake(mockMessagePayload);
|
|
77
|
+
// sandbox.stub(puppet, 'messagePayloadCache').callsFake(mockMessagePayload)
|
|
78
|
+
await puppet.login(MOCK_USER_ID);
|
|
79
|
+
const msgPayload = await puppet.messagePayload(rawPayload.MsgId);
|
|
80
|
+
t.is(msgPayload.id, EXPECTED.id, 'id right');
|
|
81
|
+
t.is(msgPayload.fromId, EXPECTED.from, 'from right');
|
|
82
|
+
sandbox.restore();
|
|
83
|
+
});
|
|
84
|
+
// Issue #445
|
|
85
|
+
// XXX have to use test.serial() because mockGetContact can not be parallel
|
|
86
|
+
(0, tstest_1.test)('ready()', async (t) => {
|
|
87
|
+
// must different with other rawData, because Contact class with load() will cache the result. or use Contact.resetPool()
|
|
88
|
+
/* tslint:disable:max-line-length */
|
|
89
|
+
const rawPayload = JSON.parse('{"MsgId":"3009511950433684462","FromUserName":"@0748ee480711bf20af91c298a0d7dcc77c30a680c1004157386b81cf13474823","ToUserName":"@b58f91e0c5c9e841e290d862ddb63c14","MsgType":1,"Content":"哈哈","Status":3,"ImgStatus":1,"CreateTime":1462887888,"VoiceLength":0,"PlayLength":0,"FileName":"","FileSize":"","MediaId":"","Url":"","AppMsgType":0,"StatusNotifyCode":0,"StatusNotifyUserName":"","RecommendInfo":{"UserName":"","NickName":"","QQNum":0,"Province":"","City":"","Content":"","Signature":"","Alias":"","Scene":0,"VerifyFlag":0,"AttrStatus":0,"Sex":0,"Ticket":"","OpCode":0},"ForwardFlag":0,"AppInfo":{"AppID":"","Type":0},"HasProductId":0,"Ticket":"","ImgHeight":0,"ImgWidth":0,"SubMsgType":0,"NewMsgId":3009511950433684500,"MMPeerUserName":"@0748ee480711bf20af91c298a0d7dcc77c30a680c1004157386b81cf13474823","MMDigest":"哈哈","MMIsSend":false,"MMIsChatRoom":false,"MMUnread":false,"LocalID":"3009511950433684462","ClientMsgId":"3009511950433684462","MMActualContent":"哈哈","MMActualSender":"@0748ee480711bf20af91c298a0d7dcc77c30a680c1004157386b81cf13474823","MMDigestTime":"21:44","MMDisplayTime":1462887888,"MMTime":"21:44","_h":104,"_index":0,"_offsetTop":0,"$$hashKey":"098"}');
|
|
90
|
+
const expectedFromUserName = '@0748ee480711bf20af91c298a0d7dcc77c30a680c1004157386b81cf13474823';
|
|
91
|
+
const expectedToUserName = '@b58f91e0c5c9e841e290d862ddb63c14';
|
|
92
|
+
const expectedFromNickName = 'From Nick Name@Test';
|
|
93
|
+
const expectedToNickName = 'To Nick Name@Test';
|
|
94
|
+
const expectedMsgId = '3009511950433684462';
|
|
95
|
+
// Mock
|
|
96
|
+
function mockContactRawPayload(id) {
|
|
97
|
+
config_1.log.silly('TestMessage', 'mocked getContact(%s)', id);
|
|
98
|
+
return new Promise(resolve => {
|
|
99
|
+
let obj = {};
|
|
100
|
+
switch (id) {
|
|
101
|
+
case expectedFromUserName:
|
|
102
|
+
obj = {
|
|
103
|
+
NickName: expectedFromNickName,
|
|
104
|
+
UserName: expectedFromUserName,
|
|
105
|
+
};
|
|
106
|
+
break;
|
|
107
|
+
case expectedToUserName:
|
|
108
|
+
obj = {
|
|
109
|
+
NickName: expectedToNickName,
|
|
110
|
+
UserName: expectedToUserName,
|
|
111
|
+
};
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
config_1.log.error('TestMessage', 'mocked getContact(%s) unknown', id);
|
|
115
|
+
t.fail(`mocked getContact(${id}) unknown`);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
config_1.log.silly('TestMessage', 'setTimeout mocked getContact');
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
config_1.log.silly('TestMessage', 'mocked getContact resolved');
|
|
121
|
+
return resolve(obj);
|
|
122
|
+
}, 100);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async function mockMessageRawPayload(id) {
|
|
126
|
+
if (id === rawPayload.MsgId) {
|
|
127
|
+
return rawPayload;
|
|
128
|
+
}
|
|
129
|
+
return {};
|
|
130
|
+
}
|
|
131
|
+
const sandbox = tstest_1.sinon.createSandbox();
|
|
132
|
+
const puppet = new PuppetTest();
|
|
133
|
+
// const wechaty = new WechatyTest({ puppet })
|
|
134
|
+
// wechaty.initPuppetAccessory(puppet)
|
|
135
|
+
sandbox.stub(puppet, 'contactRawPayload').callsFake(mockContactRawPayload);
|
|
136
|
+
sandbox.stub(puppet, 'messageRawPayload').callsFake(mockMessageRawPayload);
|
|
137
|
+
// const m = wechaty.Message.create(rawPayload.MsgId)
|
|
138
|
+
const msgPayload = await puppet.messagePayload(rawPayload.MsgId);
|
|
139
|
+
t.is(msgPayload.id, expectedMsgId, 'id/MsgId right');
|
|
140
|
+
const fromId = msgPayload.fromId;
|
|
141
|
+
const toId = msgPayload.toId;
|
|
142
|
+
if (!fromId || !toId) {
|
|
143
|
+
throw new Error('no fc or no tc');
|
|
144
|
+
}
|
|
145
|
+
const fromContactPayload = await puppet.contactPayload(fromId);
|
|
146
|
+
const toContactPayload = await puppet.contactPayload(toId);
|
|
147
|
+
t.is(fromId, expectedFromUserName, 'contact ready for FromUserName');
|
|
148
|
+
t.is(fromContactPayload.name, expectedFromNickName, 'contact ready for FromNickName');
|
|
149
|
+
t.is(toId, expectedToUserName, 'contact ready for ToUserName');
|
|
150
|
+
t.is(toContactPayload.name, expectedToNickName, 'contact ready for ToNickName');
|
|
151
|
+
sandbox.restore();
|
|
152
|
+
});
|
|
153
|
+
// test('find()', async t => {
|
|
154
|
+
// const puppet = new PuppetWeChat()
|
|
155
|
+
// // const wechaty = new WechatyTest({ puppet })
|
|
156
|
+
// // wechaty.initPuppetAccessory(puppet)
|
|
157
|
+
// const sandbox = sinon.createSandbox()
|
|
158
|
+
// sandbox.stub(puppet, 'contactPayload').resolves({})
|
|
159
|
+
// sandbox.stub(puppet, 'contactPayloadCache').returns({})
|
|
160
|
+
// const MOCK_USER_ID = 'TEST-USER-ID'
|
|
161
|
+
// await puppet.login(MOCK_USER_ID)
|
|
162
|
+
// const msg = await wechaty.Message.find({
|
|
163
|
+
// id: 'xxx',
|
|
164
|
+
// })
|
|
165
|
+
// t.ok(msg, 'Message found')
|
|
166
|
+
// t.ok(msg!.id, 'Message.id is ok')
|
|
167
|
+
// sandbox.restore()
|
|
168
|
+
// })
|
|
169
|
+
// test('findAll()', async t => {
|
|
170
|
+
// const puppet = new PuppetTest()
|
|
171
|
+
// const wechaty = new WechatyTest({ puppet })
|
|
172
|
+
// wechaty.initPuppetAccessory(puppet)
|
|
173
|
+
// const sandbox = sinon.createSandbox()
|
|
174
|
+
// sandbox.stub(puppet, 'contactPayload').resolves({})
|
|
175
|
+
// sandbox.stub(puppet, 'contactPayloadCache').returns({})
|
|
176
|
+
// const MOCK_USER_ID = 'TEST-USER-ID'
|
|
177
|
+
// await puppet.login(MOCK_USER_ID)
|
|
178
|
+
// const msgList = await wechaty.Message.findAll({
|
|
179
|
+
// from: 'yyy',
|
|
180
|
+
// })
|
|
181
|
+
// t.is(msgList.length, 2, 'Message.findAll with limit 2')
|
|
182
|
+
// sandbox.restore()
|
|
183
|
+
// })
|
|
184
|
+
//# sourceMappingURL=puppeteer-message.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puppeteer-message.spec.js","sourceRoot":"","sources":["../../tests/puppeteer-message.spec.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;;;;GAiBG;;AAEH,sCAAsC;AACtC,sCAAsC;AACtC,8BAA8B;AAC9B,6CAA6C;AAE7C,mCAGyB;AAEzB,0CAGsC;AAEtC,mDAGuC;AAEvC,wDA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AAwC;AAExC,0CAA0C;AAE1C,wDAAwD;AACxD,4DAA4D;AAE5D,wCAAwC;AACxC,qCAAqC;AAErC,oDAAoD;AACpD,mBAAmB;AACnB,OAAO;AAEP,4DAA4D;AAE5D,sBAAsB;AACtB,KAAK"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
/**
|
|
3
|
+
* Wechaty - https://github.com/chatie/wechaty
|
|
4
|
+
*
|
|
5
|
+
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=puppeteer-room.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puppeteer-room.spec.d.ts","sourceRoot":"","sources":["../../tests/puppeteer-room.spec.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;GAiBG"}
|