1 | #!/usr/bin/env ts-node
|
2 | /**
|
3 | * Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
|
4 | *
|
5 | * @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
|
6 | * Wechaty Contributors <https://github.com/wechaty>.
|
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 |
|
22 | import test from 'blue-tape'
|
23 |
|
24 | import { config } from './config'
|
25 | // import { Puppet } from './puppet'
|
26 |
|
27 | test('important variables', async t => {
|
28 | // t.true('puppet' in config, 'should exist `puppet` in Config')
|
29 | t.true('apihost' in config, 'should exist `apihost` in Config')
|
30 | t.true('token' in config, 'should exist `token` in Config')
|
31 |
|
32 | // t.ok(config.default.DEFAULT_PUPPET , 'should export DEFAULT_PUPPET')
|
33 | // t.ok(config.default.DEFAULT_PROFILE , 'should export DEFAULT_PROFILE')
|
34 | t.ok(config.default.DEFAULT_PROTOCOL, 'should export DEFAULT_PROTOCOL')
|
35 | t.ok(config.default.DEFAULT_APIHOST, 'should export DEFAULT_APIHOST')
|
36 | })
|
37 |
|
38 | test('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.validApiHost(apihost)
|
50 | })
|
51 | }, 'should not row for right apihost')
|
52 | ERR_APIHOSTS.forEach(apihost => {
|
53 | t.throws(() => {
|
54 | config.validApiHost(apihost)
|
55 | })
|
56 | }, 'should throw for error apihost')
|
57 |
|
58 | })
|
59 |
|
60 | // test('puppetInstance()', async t => {
|
61 | // // BUG Compitable with Win32 CI
|
62 | // // global instance infected across unit tests... :(
|
63 | // const bak = config.puppetInstance()
|
64 |
|
65 | // config.puppetInstance(null)
|
66 | // t.throws(() => {
|
67 | // config.puppetInstance()
|
68 | // }, Error, 'should throw when not initialized')
|
69 | // config.puppetInstance(bak)
|
70 |
|
71 | // const EXPECTED: Puppet = {userId: 'test'} as any
|
72 | // const mockPuppet = EXPECTED
|
73 |
|
74 | // config.puppetInstance(mockPuppet)
|
75 | // const instance = config.puppetInstance()
|
76 | // t.deepEqual(instance, EXPECTED, 'should equal with initialized data')
|
77 |
|
78 | // config.puppetInstance(null)
|
79 | // t.throws(() => {
|
80 | // config.puppetInstance()
|
81 | // }, Error, 'should throw after set to null')
|
82 |
|
83 | // config.puppetInstance(bak)
|
84 | // })
|
85 |
|
86 | test('systemPuppetName ()', async t => {
|
87 | const WECHATY_PUPPET_ORIG = process.env.WECHATY_PUPPET
|
88 |
|
89 | delete process.env.WECHATY_PUPPET
|
90 | t.equal(config.systemPuppetName(), 'wechaty-puppet-puppeteer', 'should get wechaty-puppet-puppeteer as puppet name')
|
91 |
|
92 | process.env.WECHATY_PUPPET = 'wechaty-puppet-mock'
|
93 | t.equal(config.systemPuppetName(), 'wechaty-puppet-mock', 'should get puppet name from process.env')
|
94 |
|
95 | // restore the original value
|
96 | process.env.WECHATY_PUPPET = WECHATY_PUPPET_ORIG
|
97 | })
|