wechaty-puppet-official-account
Version:
Wechaty Puppet for WeChat Official Accounts
120 lines • 3.96 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv/config.js");
const tstest_1 = require("tstest");
const cuid_1 = __importDefault(require("cuid"));
const ci_info_1 = __importDefault(require("ci-info"));
const unirest_1 = __importDefault(require("unirest"));
const oa_options_js_1 = require("../../tests/fixtures/oa-options.js");
const official_account_js_1 = require("./official-account.js");
/*
* refer to : https://github.com/wechaty/wechaty-puppet-official-account/issues/8
* try to fix global pr runtime test
*/
const isPR = !!(ci_info_1.default.isPR);
void cuid_1.default; // for testing
(0, tstest_1.test)('OfficialAccount smoke testing', async (t) => {
if (isPR) {
void t.skip('Skip for PR');
return;
}
const WEBHOOK_PROXY_URL = [
'http://',
'wechaty-puppet-official-account',
'-',
(0, cuid_1.default)(),
// '.serverless.social',
'.localtunnel.chatie.io',
// '.test.localhost.localdomain',
].join('');
const oa = new official_account_js_1.OfficialAccount({
...(0, oa_options_js_1.getOaOptions)(),
webhookProxyUrl: WEBHOOK_PROXY_URL,
});
await oa.start();
const future = new Promise(resolve => oa.once('message', resolve));
const PAYLOAD = {
Content: 'testing123',
CreateTime: '1596436942',
FromUserName: 'oOiiq59SLkf1AGuuTh668cxP8_Xs',
MsgId: '22855481560378379',
MsgType: 'text',
ToUserName: 'gh_27056d3d5d05',
};
const XML = `
<xml>
<ToUserName><![CDATA[${PAYLOAD.ToUserName}]]></ToUserName>
<FromUserName><![CDATA[${PAYLOAD.FromUserName}]]></FromUserName>
<CreateTime>${PAYLOAD.CreateTime}</CreateTime>
<MsgType><![CDATA[${PAYLOAD.MsgType}]]></MsgType>
<Content><![CDATA[${PAYLOAD.Content}]]></Content>
</xml>
`;
const response = await unirest_1.default
.post(WEBHOOK_PROXY_URL)
// .headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
.type('xml')
.send(XML);
t.equal(response.body, 'success', 'should get success response');
try {
await Promise.race([
future,
new Promise((resolve, reject) => { void resolve; setTimeout(reject, 15000); }),
]);
t.pass('should get a message emit event from oa instance');
}
catch (e) {
t.fail('should not get timeout rejection');
}
// await new Promise(resolve => setTimeout(resolve, 100 * 1000))
await oa.stop();
});
(0, tstest_1.test)('updateAccessToken()', async (t) => {
if (isPR) {
await t.skip('Skip for PR');
return;
}
const oa = new official_account_js_1.OfficialAccount({
...(0, oa_options_js_1.getOaOptions)(),
port: 0,
});
await oa.start();
try {
t.ok(oa.accessToken, 'should get access token');
}
catch (e) {
t.fail('should not be rejected');
}
await oa.stop();
});
(0, tstest_1.test)('sendCustomMessage()', async (t) => {
if (isPR) {
await t.skip('Skip for PR');
return;
}
const oa = new official_account_js_1.OfficialAccount({
...(0, oa_options_js_1.getOaOptions)(),
port: 0,
});
try {
await oa.start();
const ret = await oa.sendCustomMessage({
content: 'wechaty-puppet-official-account CI testing',
msgtype: 'text',
touser: 'oOiiq59SLkf1AGuuTh668cxP8_Xs',
});
t.not(ret, null, 'should get messageId');
}
catch (e) {
console.error(e);
t.fail('should not be rejected');
}
finally {
await oa.stop();
}
});
//# sourceMappingURL=official-account.spec.js.map