-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffice.js
106 lines (84 loc) · 2.92 KB
/
office.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
'use strict';
require('should');
var office = require('../lib/');
var anyfetchHydrater = require('anyfetch-hydrater');
var HydrationError = anyfetchHydrater.HydrationError;
describe('Office hydrater', function() {
describe('with extension', function() {
it('should return the correct error when there is no extension', function(done) {
var document = {
data: {},
metadata: {
path: "/samples/textrtf",
}
};
var changes = anyfetchHydrater.defaultChanges();
office(__dirname + document.metadata.path, document, changes, function(err) {
err.should.eql(new HydrationError("Unknown file extension or content type"));
done();
});
});
it('should return the correct error when the extension is invalid', function(done) {
var document = {
data: {},
metadata: {
path: "/samples/text.fuck",
}
};
var changes = anyfetchHydrater.defaultChanges();
office(__dirname + document.metadata.path, document, changes, function(err) {
err.should.eql(new HydrationError("Unknown file extension or content type"));
done();
});
});
it('should return the correct error when there is no path', function(done) {
var document = {
data: {},
};
var changes = anyfetchHydrater.defaultChanges();
office(__dirname + "/samples/text.rtf", document, changes, function(err) {
err.should.eql(new HydrationError("Unknown file extension or content type"));
done();
});
});
});
describe('with content type', function() {
it('should return the correct error when there is no content type', function(done) {
var document = {
data: {}
};
var changes = anyfetchHydrater.defaultChanges();
office(__dirname + "/samples/textrtf", document, changes, function(err) {
err.should.eql(new HydrationError("Unknown file extension or content type"));
done();
});
});
it('should return the correct error when the content type is invalid', function(done) {
var document = {
data: {
"content-type": "application/tamère"
},
};
var changes = anyfetchHydrater.defaultChanges();
office(__dirname + "/samples/textrtf", document, changes, function(err) {
err.should.eql(new HydrationError("Unknown file extension or content type"));
done();
});
});
});
describe('with error', function() {
it("should return the correct error when loffice can't hydrate file", function(done) {
this.timeout(120000);
var document = {
metadata: {
path: "/samples/errored.rtf"
}
};
var changes = anyfetchHydrater.defaultChanges();
office(__dirname + "/samples/errored.rtf", document, changes, function(err) {
err.message.should.match(/Document is empty/i);
done();
});
});
});
});