-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
78 lines (62 loc) · 2.1 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// eslint-disable
/** Dependencies */
const { randomBytes } = require('crypto');
const teleapi = require('./index.js');
const assert = require('assert');
/** Preparing */
const TOKEN = process.env.TOKEN;
assert.ok(TOKEN, 'The environment must be contain a `TOKEN` variable before you run test.');
/** Testing */
describe('Exports', () => {
it('should be as a Function', () => {
assert.equal(Object.getPrototypeOf(teleapi), Function.prototype);
});
it('should be contained a `version` variable', () => {
assert.ok(teleapi.version);
});
it('should be contained a `methods` variable', () => {
assert.ok(teleapi.methods);
});
});
describe('Instance', () => {
it('should return new instance', () => {
const api = teleapi(TOKEN);
assert.ok(api);
});
it('should return new instance with custom api', () => {
const methodName = 'getMe';
const version = '1.0-custom';
const api = teleapi(TOKEN, {
version: '1.0-custom',
methods: [methodName],
});
assert.ok(api);
assert.equal(api.version, version);
assert.ok(api.getMe);
});
});
describe('API', () => {
it('should request to sendMessage without params and get throw an error', (done) => {
const api = teleapi(TOKEN);
api.sendMessage()
.then(() => done(new Error("Request wasn't to pass")))
.catch(() => done());
});
it('should request to random method without params and get throw an error', (done) => {
const method = `random-${randomBytes(16).toString('hex')}`;
const api = teleapi(TOKEN);
api.method(method)
.then(() => done(new Error("Request wasn't to pass")))
.catch(() => done());
});
it('should be received an information about the bot', (done) => {
const api = teleapi(TOKEN);
api.getMe().
then((response) => {
assert.ok(response.id);
assert.ok(response.is_bot);
assert.ok(response.username);
done();
});
});
});