Skip to content

Commit 30ea0d3

Browse files
committed
Added tests for the 'translate' header
1 parent 163914f commit 30ea0d3

File tree

1 file changed

+79
-73
lines changed

1 file changed

+79
-73
lines changed

test/tests/source.js

Lines changed: 79 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var webdav = require('../../lib/index.js'),
55

66
module.exports = (test, options, index) => test('source', (isValid, server) =>
77
{
8-
isValid = isValid.multiple(1, server);
8+
isValid = isValid.multiple(2, server);
99
const _ = (e, cb) => {
1010
if(e)
1111
isValid(false, e);
@@ -25,105 +25,111 @@ module.exports = (test, options, index) => test('source', (isValid, server) =>
2525

2626
const url = 'http://localhost:' + (options.port + index)
2727

28-
let processed = '<html><body>processed content</body></html>';
29-
let unprocessed = 'unprocessed content';
30-
31-
server.rootResource.addChild({
32-
write(targetSource, callback)
33-
{
34-
callback(null, new stream.Writable({
35-
write: (chunk, encoding, callback) => {
36-
if(targetSource)
37-
unprocessed = chunk;
38-
else
39-
processed = chunk;
40-
41-
callback(null);
42-
}
43-
}));
44-
},
45-
read(targetSource, callback)
46-
{
47-
callback(null, new stream.Readable({
48-
read: function(size)
49-
{
50-
this.push(targetSource ? unprocessed : processed);
51-
this.push(null);
52-
}
53-
}));
54-
},
55-
webName(callback)
56-
{
57-
callback(null, 'testFile.txt');
58-
},
59-
mimeType(targetSource, callback)
60-
{
61-
callback(null, targetSource ? 'text/plain' : 'text/html');
62-
},
63-
size(targetSource, callback)
64-
{
65-
callback(null, targetSource ? unprocessed.length : processed.length);
66-
},
67-
getLocks(callback)
68-
{
69-
callback(null, []);
70-
},
71-
type(callback)
72-
{
73-
callback(null, webdav.ResourceType.File);
74-
}
75-
}, (e) => _(e, () => {
76-
request({
77-
url: url + '/testFile.txt',
78-
method: 'GET',
79-
headers: {
28+
test('source');
29+
test('translate');
30+
31+
function test(headerName)
32+
{
33+
let processed = '<html><body>processed content</body></html>';
34+
let unprocessed = 'unprocessed content';
35+
36+
server.rootResource.addChild({
37+
write(targetSource, callback)
38+
{
39+
callback(null, new stream.Writable({
40+
write: (chunk, encoding, callback) => {
41+
if(targetSource)
42+
unprocessed = chunk;
43+
else
44+
processed = chunk;
45+
46+
callback(null);
47+
}
48+
}));
49+
},
50+
read(targetSource, callback)
51+
{
52+
callback(null, new stream.Readable({
53+
read: function(size)
54+
{
55+
this.push(targetSource ? unprocessed : processed);
56+
this.push(null);
57+
}
58+
}));
59+
},
60+
webName(callback)
61+
{
62+
callback(null, 'testFile.txt');
63+
},
64+
mimeType(targetSource, callback)
65+
{
66+
callback(null, targetSource ? 'text/plain' : 'text/html');
67+
},
68+
size(targetSource, callback)
69+
{
70+
callback(null, targetSource ? unprocessed.length : processed.length);
71+
},
72+
getLocks(callback)
73+
{
74+
callback(null, []);
75+
},
76+
type(callback)
77+
{
78+
callback(null, webdav.ResourceType.File);
8079
}
81-
}, expect(processed, () => {
80+
}, (e) => _(e, () => {
8281
request({
8382
url: url + '/testFile.txt',
8483
method: 'GET',
8584
headers: {
86-
source: 'T'
87-
}
88-
}, expect(unprocessed, () => {
89-
const old = {
90-
processed,
91-
unprocessed
9285
}
86+
}, expect(processed, () => {
9387
request({
9488
url: url + '/testFile.txt',
95-
method: 'PUT',
89+
method: 'GET',
9690
headers: {
97-
},
98-
body: processed + 'addon'
99-
}, (e, res, body) => _(e, () => {
91+
[headerName]: 'T'
92+
}
93+
}, expect(unprocessed, () => {
94+
const old = {
95+
processed,
96+
unprocessed
97+
}
10098
request({
10199
url: url + '/testFile.txt',
102100
method: 'PUT',
103101
headers: {
104-
source: 'T'
105102
},
106-
body: unprocessed + 'addonX'
103+
body: processed + 'addon'
107104
}, (e, res, body) => _(e, () => {
108105
request({
109106
url: url + '/testFile.txt',
110-
method: 'GET',
107+
method: 'PUT',
111108
headers: {
112-
}
113-
}, expect(old.processed + 'addon', () => {
109+
[headerName]: 'T'
110+
},
111+
body: unprocessed + 'addonX'
112+
}, (e, res, body) => _(e, () => {
114113
request({
115114
url: url + '/testFile.txt',
116115
method: 'GET',
117116
headers: {
118-
source: 'T'
119117
}
120-
}, expect(old.unprocessed + 'addonX', () => {
121-
isValid(true);
118+
}, expect(old.processed + 'addon', () => {
119+
request({
120+
url: url + '/testFile.txt',
121+
method: 'GET',
122+
headers: {
123+
[headerName]: 'T'
124+
}
125+
}, expect(old.unprocessed + 'addonX', () => {
126+
isValid(true);
127+
}))
122128
}))
123129
}))
124130
}))
125131
}))
126132
}))
127133
}))
128-
}))
134+
}
129135
})

0 commit comments

Comments
 (0)