-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
88 lines (66 loc) · 2.31 KB
/
Copy pathtest.js
File metadata and controls
88 lines (66 loc) · 2.31 KB
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
var _ = require('underscore');
var assert = require('chai').assert;
var outfile = require('./');
var should = require('chai').should();
var VALID_DESCRIPTOR = {
'name': 'my-dataset',
'resources': [{
'path': 'data.csv',
'schema': {
'fields': [
{'name': 'var1', 'type': 'string'},
{'name': 'var2', 'type': 'integer'},
{'name': 'var3', 'type': 'number'}
]
}
}]
};
describe('Data Package Output File', function() {
it('throw error if empty descriptor passed', function(done, err) {
if (err) done(err);
try {
outfile({});
} catch(exception) {
exception.message.should.be.not.empty;
exception.message.should.be.a('string');
done();
return;
}
done('Exception not thrown');
});
it('return proper mime-type', function(done, err) {
if (err) done(err);
(new RegExp(/^data:application\/json:/)).exec(outfile(VALID_DESCRIPTOR)).should.be.not.empty;
done();
});
it('return proper mime-type if old IE flag passed in params', function(done, err) {
if (err) done(err);
(new RegExp(/^data:text\/plain:/)).exec(
outfile(VALID_DESCRIPTOR, {IE9: true})
).should.be.not.empty;
done();
});
it('return charset passed in options', function(done, err) {
var charset = 'CHRSET';
if (err) done(err);
(new RegExp('^data:application\/json:' + charset + ',')).exec(
outfile(VALID_DESCRIPTOR, {charset: charset})
).should.be.not.empty;
done();
});
it('return utf-8 as default charset if none passed in options', function(done, err) {
if (err) done(err);
(new RegExp('^data:application\/json:utf-8,')).exec(
outfile(VALID_DESCRIPTOR)
).should.be.not.empty;
done();
});
it('return a string that evaluates into original descriptor', function(done, err) {
if (err) done(err);
JSON.parse(outfile(VALID_DESCRIPTOR).replace(/^[^{]+,/, '')).should.deep.equal(VALID_DESCRIPTOR);
JSON.parse(outfile(VALID_DESCRIPTOR, {IE9: true}).replace(/^[^{]+,/, '')).should.deep.equal(VALID_DESCRIPTOR);
JSON.parse(outfile(VALID_DESCRIPTOR, {charset: 'CHRST'}).replace(/^[^{]+,/, '')).should.deep.equal(VALID_DESCRIPTOR);
JSON.parse(outfile(VALID_DESCRIPTOR, {IE9: true, charset: 'CHRST'}).replace(/^[^{]+,/, '')).should.deep.equal(VALID_DESCRIPTOR);
done();
});
});