-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathutils.spec.js
135 lines (112 loc) · 4.43 KB
/
utils.spec.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const { expect } = require('chai');
const UTILS = require('../lib/utils.js');
describe('utils tests', () => {
const servURL = 'http://localhost:6363/';
it('check standard urls', () => {
expect(UTILS.standard_urls.rdf).to.equal(UTILS.getStdURL('rdf', ''));
});
it('check URIEncodePayload', () => {
const expected = 'a=A&b=B&c=C&day=sir&b=D';
const payload = [{
a: 'A', b: 'B', c: 'C', day: 'sir',
}, { b: 'D' }];
expect(UTILS.URIEncodePayload(payload)).to.equal(expected);
});
it('check addURLPrefix', () => {
const docURL = 'http://mydocs/';
UTILS.addURLPrefix('doc', docURL);
expect(UTILS.standard_urls.doc).to.equal(docURL);
});
it('check empty', () => {
expect(UTILS.empty({})).to.equal(true);
expect(UTILS.empty([])).to.equal(true);
expect(UTILS.empty({ a: '' })).to.equal(false);
expect(UTILS.empty([''])).to.equal(false);
});
/* it('check genBNID',function(){
const bnid = UTILS.genBNID();
expect(bnid.substring(0, 4)).to.equal("doc:");
}) */
it('check getShorthand', () => {
const sh = UTILS.getShorthand(`${UTILS.standard_urls.rdf}type`);
expect(sh).to.equal('rdf:type');
});
it('check compareIDs', () => {
const sh = UTILS.compareIDs(`${UTILS.standard_urls.rdf}type`, 'rdf:type');
expect(sh).to.equal(true);
});
// I HAVE TO CHECK IF THIS IS OK
it('check shorten', () => {
const sh = UTILS.shorten(`${UTILS.standard_urls.rdf}type`);
expect(sh).to.equal('type');
});
it('check unshorten', () => {
const full = `${UTILS.standard_urls.rdf}type`;
expect(UTILS.unshorten('rdf:type')).to.equal(full);
});
it('check valid URL', () => {
expect(UTILS.validURL('http://myweb/')).to.equal(true);
expect(UTILS.validURL('https://myweb/')).to.equal(true);
expect(UTILS.validURL('nothttps://myweb/')).to.equal(false);
});
it('check labelFromURL', () => {
const label = UTILS.labelFromURL('doc:This_IS_A_DOC');
expect(label).to.equal('This IS A DOC');
});
it('check urlFragment', () => {
const frag = UTILS.urlFragment(UTILS.getStdURL('rdf', 'type'));
expect(frag).to.equal('type');
});
it('check lastURLBit', () => {
const label = UTILS.lastURLBit('http://adsfsd/X');
expect(label).to.equal('X');
});
it('check addNamespacesToVariables', () => {
const full = UTILS.addNamespacesToVariables(['A', 'v:B']);
expect(full).to.eql(['v:A', 'v:B']);
});
it('check removeNamespacesFromVariables', () => {
const full = UTILS.removeNamespacesFromVariables(['A', 'v:B']);
expect(full).to.eql(['A', 'B']);
});
it('check isStringType', () => {
expect(UTILS.TypeHelper.isStringType(UTILS.getStdURL('xsd', 'string'))).to.equal(true);
expect(UTILS.TypeHelper.isStringType(UTILS.getStdURL('xsd', 'decimal'))).to.equal(false);
});
it('check numberWithCommas', () => {
const cnum = UTILS.TypeHelper.numberWithCommas(10000.323);
const cnum2 = UTILS.TypeHelper.numberWithCommas(100009323, '.');
expect(cnum).to.equal('10,000.323');
expect(cnum2).to.equal('100.009.323');
});
it('check parseDate', () => {
const xsdstr = '-0001-02-01T10:12:23.3';
const parsed = UTILS.DateHelper.parseDate('xsd:dateTime', xsdstr);
const expected = {
year: '-0001', month: 2, day: 1, hour: '10', minute: '12', second: '23.3', timezone: false,
};
expect(parsed).to.eql(expected);
});
it('check xsdFromParsed', () => {
const parsed = {
year: '-0001', month: 2, day: 1, hour: '10', minute: '12', second: '23.3',
};
const xsdstr = UTILS.DateHelper.xsdFromParsed(parsed, 'xsd:dateTime');
const expected = '-0001-02-01T10:12:23.3';
expect(xsdstr).to.equal(expected);
});
it('encodeURISegment test ====%%TEST organization name', () => {
expect(UTILS.encodeURISegment("====%%TEST")).to.equal("====%25%25TEST");
});
it('encodeURISegment test &&26567 organization name', () => {
expect(UTILS.encodeURISegment("&&26567")).to.equal("%26%2626567");
});
it('encodeURISegment test %6277&ˆˆˆ@ˆˆWˆTWTET#Y@&&GHHSHHS organization name', () => {
expect(UTILS.encodeURISegment("%6277&ˆˆˆ@ˆˆWˆTWTET#Y@&&GHHSHHS")).to.equal("%256277%26%CB%86%CB%86%CB%86@%CB%86%CB%86W%CB%86TWTET%23Y@%26%26GHHSHHS");
});
/* it('check convertTimestampToXsd',function(){
let parsed = UTILS.DateHelper.convertTimestampToXsd(0);
const expected = { year: 1970, month: 1, day: 1, hour: 1, minute: 0, second: 0}
expect(parsed).to.eql(expected);
}) */
});