@juzi/wechaty
Version:
Wechaty is a RPA SDK for Chatbot Makers.
77 lines • 3.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
*
* @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
* Wechaty Contributors <https://github.com/wechaty>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
const tstest_1 = require("tstest");
const wechaty_puppet_mock_1 = require("@juzi/wechaty-puppet-mock");
const wechaty_builder_js_1 = require("../wechaty-builder.js");
const contact_js_1 = require("./contact.js");
(0, tstest_1.test)('findAll()', async (t) => {
const EXPECTED_NAME = 'TestingBot';
const EXPECTED_ADDITIONAL_INFO = {
subjectA: 'A',
subjectB: 'B',
};
const puppet = new wechaty_puppet_mock_1.PuppetMock();
const wechaty = wechaty_builder_js_1.WechatyBuilder.build({ puppet });
const mockContact = puppet.mocker.createContact({ name: EXPECTED_NAME, additionalInfo: JSON.stringify(EXPECTED_ADDITIONAL_INFO) });
await wechaty.start();
await puppet.mocker.login(mockContact);
const contactList = await wechaty.Contact.findAll();
t.equal(contactList.length, 1, 'should find 1 contact');
t.equal(contactList[0].name(), EXPECTED_NAME, 'should get name from payload');
t.same(contactList[0].payload, mockContact.payload, 'should get payload from mockContact');
const additionalInfo = contactList[0].additionalInfo();
t.same(additionalInfo, EXPECTED_ADDITIONAL_INFO, 'additional info should be matched');
await wechaty.stop();
});
(0, tstest_1.test)('Should not be able to instanciate directly', async (t) => {
t.throws(() => {
const c = contact_js_1.ContactImpl.load('xxx');
t.fail(c.name());
}, 'should throw when `Contact.load()`');
t.throws(() => {
const c = contact_js_1.ContactImpl.load('xxx');
t.fail(c.name());
}, 'should throw when `Contact.load()`');
});
(0, tstest_1.test)('Should not be able to instanciate through cloneClass without puppet', async (t) => {
t.throws(() => {
const c = contact_js_1.ContactImpl.load('xxx');
t.fail(c.name());
}, 'should throw when `MyContact.load()` without puppet');
t.throws(() => {
const c = contact_js_1.ContactImpl.load('xxx');
t.fail(c.name());
}, 'should throw when `MyContact.load()` without puppet');
});
(0, tstest_1.test)('should throw when instanciate the global class', async (t) => {
t.throws(() => {
const c = contact_js_1.ContactImpl.load('xxx');
t.fail('should not run to here');
t.fail(c.toString());
}, 'should throw when we instanciate a global class');
});
(0, tstest_1.test)('ProtectedProperties', async (t) => {
const noOneLeft = true;
t.ok(noOneLeft, 'should match Wechaty properties for every protected property');
});
//# sourceMappingURL=contact.spec.js.map