UNPKG

3.73 kBJavaScriptView Raw
1#!/usr/bin/env ts-node
2"use strict";
3/**
4 * Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
5 *
6 * @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
7 * Wechaty Contributors <https://github.com/wechaty>.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 */
22var __importDefault = (this && this.__importDefault) || function (mod) {
23 return (mod && mod.__esModule) ? mod : { "default": mod };
24};
25Object.defineProperty(exports, "__esModule", { value: true });
26const blue_tape_1 = __importDefault(require("blue-tape"));
27const config_1 = require("./config");
28// import { Puppet } from './puppet'
29blue_tape_1.default('important variables', async (t) => {
30 // t.true('puppet' in config, 'should exist `puppet` in Config')
31 t.true('apihost' in config_1.config, 'should exist `apihost` in Config');
32 t.true('token' in config_1.config, 'should exist `token` in Config');
33 // t.ok(config.default.DEFAULT_PUPPET , 'should export DEFAULT_PUPPET')
34 // t.ok(config.default.DEFAULT_PROFILE , 'should export DEFAULT_PROFILE')
35 t.ok(config_1.config.default.DEFAULT_PROTOCOL, 'should export DEFAULT_PROTOCOL');
36 t.ok(config_1.config.default.DEFAULT_APIHOST, 'should export DEFAULT_APIHOST');
37});
38blue_tape_1.default('validApiHost()', async (t) => {
39 const OK_APIHOSTS = [
40 'api.chatie.io',
41 'chatie.io:8080',
42 ];
43 const ERR_APIHOSTS = [
44 'https://api.chatie.io',
45 'chatie.io/',
46 ];
47 OK_APIHOSTS.forEach(apihost => {
48 t.doesNotThrow(() => {
49 config_1.config.validApiHost(apihost);
50 });
51 }, 'should not row for right apihost');
52 ERR_APIHOSTS.forEach(apihost => {
53 t.throws(() => {
54 config_1.config.validApiHost(apihost);
55 });
56 }, 'should throw for error apihost');
57});
58// test('puppetInstance()', async t => {
59// // BUG Compitable with Win32 CI
60// // global instance infected across unit tests... :(
61// const bak = config.puppetInstance()
62// config.puppetInstance(null)
63// t.throws(() => {
64// config.puppetInstance()
65// }, Error, 'should throw when not initialized')
66// config.puppetInstance(bak)
67// const EXPECTED: Puppet = {userId: 'test'} as any
68// const mockPuppet = EXPECTED
69// config.puppetInstance(mockPuppet)
70// const instance = config.puppetInstance()
71// t.deepEqual(instance, EXPECTED, 'should equal with initialized data')
72// config.puppetInstance(null)
73// t.throws(() => {
74// config.puppetInstance()
75// }, Error, 'should throw after set to null')
76// config.puppetInstance(bak)
77// })
78blue_tape_1.default('systemPuppetName ()', async (t) => {
79 const WECHATY_PUPPET_ORIG = process.env['WECHATY_PUPPET'];
80 delete process.env['WECHATY_PUPPET'];
81 t.equal(config_1.config.systemPuppetName(), 'wechaty-puppet-wechat', 'should get wechaty-puppet-wechat as default puppet name');
82 process.env['WECHATY_PUPPET'] = 'wechaty-puppet-mock';
83 t.equal(config_1.config.systemPuppetName(), 'wechaty-puppet-mock', 'should get puppet name from process.env');
84 // restore the original value
85 process.env['WECHATY_PUPPET'] = WECHATY_PUPPET_ORIG;
86});
87//# sourceMappingURL=config.spec.js.map
\No newline at end of file