-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
100 lines (89 loc) · 2.29 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {readFile} from 'fs';
import {promisify} from 'util';
import test from 'ava';
import cpanelZoneExport from './index.js';
import * as util from './lib/utils.js';
const readFileAsync = promisify(readFile);
test.beforeEach(async (t) => {
t.context.data = await readFileAsync('./testZoneResponse.json', 'utf8');
t.context.validZoneFile = await readFileAsync('./validZoneFile.txt', 'utf8');
});
test('Example zone response', (t) => {
const records = util.getRecorsFromData(t.context.data);
t.is(typeof records, 'object');
t.is(records.length, 20);
});
test('Group records by type', (t) => {
const exampleRecords = [
{
class: 'IN',
ttl: '14400',
name: 'example.com.',
type: 'A',
record: '193.111.10.1',
address: '193.111.10.1'
},
{
type: 'CNAME',
record: 'example.com',
cname: 'example.com',
class: 'IN',
name: 'www.example.com.',
ttl: '14400'
},
{
type: 'CNAME',
record: 'd.example.com',
cname: 'd.example.com',
class: 'IN',
name: 'www.example.com.',
ttl: '14400'
}
];
const group = util.groupByType(exampleRecords, 'type');
t.deepEqual(group, {
A: [
{
class: 'IN',
ttl: '14400',
name: 'example.com.',
type: 'A',
record: '193.111.10.1',
address: '193.111.10.1'
}
],
CNAME: [
{
type: 'CNAME',
record: 'example.com',
cname: 'example.com',
class: 'IN',
name: 'www.example.com.',
ttl: '14400'
},
{
type: 'CNAME',
record: 'd.example.com',
cname: 'd.example.com',
class: 'IN',
name: 'www.example.com.',
ttl: '14400'
}
]
});
});
test('Compose functions', (t) => {
const lowercase = (string) => string.toLowerCase();
const capitalize = (string) =>
`${string.charAt(0).toUpperCase()}${string.slice(1)}`;
const reverse = (string) => string.split('').reverse().join('');
const fn = util.pipe(lowercase, capitalize, reverse);
t.is(fn('Hello World'), 'dlrow olleH');
});
test('Generate zone file', (t) => {
const zoneFile = cpanelZoneExport(t.context.data, {
domain: 'example.com',
datetime: '2021-01-17T15:56:20.796Z'
});
t.is(zoneFile, t.context.validZoneFile);
});