Skip to content

Commit

Permalink
Added tests for the DELETE method
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 13, 2017
1 parent 105580f commit feb22d6
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/tests/deletePhysicalFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var webdav = require('../../lib/index.js'),
Client = require("webdav-fs"),
path = require('path'),
fs = require('fs')

module.exports = (test, options, index) => test('delete a physical file', isValid =>
{
var server = new webdav.WebDAVServer();
server.start(options.port + index);
isValid = isValid.multiple(1, server);

var wfs = Client(
"http://127.0.0.1:" + (options.port + index)
);

const fileName = 'file.txt';
const filePath = path.join(__dirname, 'deletePhysicalFile', fileName);
if(!fs.existsSync(filePath))
fs.writeFileSync(filePath, 'Test!');

server.rootResource.addChild(new webdav.PhysicalFile(filePath), e => {
if(e)
{
isValid(false, e)
return;
}

wfs.stat('/' + fileName, (e, stat) => {
if(e)
{
isValid(false, e)
return;
}

wfs.unlink('/' + fileName, (e) => {
if(e)
{
isValid(false, e)
return;
}

fs.exists(filePath, (exists) => {
isValid(!exists)
})
})
})
});
})
106 changes: 106 additions & 0 deletions test/tests/deletePhysicalFolder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
var webdav = require('../../lib/index.js'),
Client = require("webdav-fs"),
path = require('path'),
fs = require('fs')

module.exports = (test, options, index) => test('delete a physical folder', isValid =>
{
var server = new webdav.WebDAVServer();
server.start(options.port + index);
isValid = isValid.multiple(2, server);

var wfs = Client(
"http://127.0.0.1:" + (options.port + index)
);

const folderName = 'emptyFolder';
const folderPath = path.join(__dirname, 'deletePhysicalFolder', folderName);
if(!fs.existsSync(folderPath))
fs.mkdirSync(folderPath);

server.rootResource.addChild(new webdav.PhysicalFolder(folderPath), e => {
if(e)
{
isValid(false, e)
return;
}

wfs.stat('/' + folderName, (e, stat) => {
if(e)
{
isValid(false, e)
return;
}

wfs.unlink('/' + folderName, (e) => {
if(e)
{
isValid(false, e)
return;
}

fs.exists(folderPath, (exists) => {
isValid(!exists)
})
})
})
});

const folderName2 = 'notEmptyFolder';
const folderPath2 = path.join(__dirname, 'deletePhysicalFolder', folderName2);
if(!fs.existsSync(folderPath2))
fs.mkdirSync(folderPath2);
const fd = new webdav.PhysicalFolder(folderPath2);

const folderName3 = 'folder';
const folderPath3 = path.join(folderPath2, folderName3);
if(!fs.existsSync(folderPath3))
fs.mkdirSync(folderPath3);
fd.addChild(new webdav.PhysicalFolder(folderPath3), e => {
if(e)
{
isValid(false, e)
return;
}

const fileName4 = 'file.txt';
const filePath4 = path.join(folderPath2, fileName4);
if(!fs.existsSync(filePath4))
fs.writeFileSync(filePath4, 'Test!');
fd.addChild(new webdav.PhysicalFile(filePath4), e => {
if(e)
{
isValid(false, e)
return;
}

server.rootResource.addChild(fd, e => {
if(e)
{
isValid(false, e)
return;
}

wfs.stat('/' + folderName2, (e, stat) => {
if(e)
{
isValid(false, e)
return;
}

wfs.unlink('/' + folderName2, (e) => {
if(e)
{
isValid(false, e)
return;
}

fs.exists(folderPath2, (exists) => {
isValid(!exists)
})
})
})
});
});
});
})
46 changes: 46 additions & 0 deletions test/tests/deleteVirtualFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var webdav = require('../../lib/index.js'),
Client = require("webdav-fs")

module.exports = (test, options, index) => test('delete a virtual file', isValid =>
{
var server = new webdav.WebDAVServer();
server.start(options.port + index);
isValid = isValid.multiple(2, server);

var wfs = Client(
"http://127.0.0.1:" + (options.port + index)
);

const fileName = 'file.txt';
server.rootResource.addChild(new webdav.VirtualFile(fileName), e => {
if(e)
{
isValid(false, e)
return;
}

wfs.stat('/' + fileName, (e, stat) => {
if(e)
{
isValid(false, e)
return;
}

wfs.unlink('/' + fileName, (e) => {
if(e)
{
isValid(false, e)
return;
}

wfs.stat('/' + fileName, (e, stat) => {
isValid(!!e)
})
})
})
});

wfs.unlink('/fileNotFound.txt', (e) => {
isValid(!!e)
})
})
88 changes: 88 additions & 0 deletions test/tests/deleteVirtualFolder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
var webdav = require('../../lib/index.js'),
Client = require("webdav-fs")

module.exports = (test, options, index) => test('delete a virtual folder', isValid =>
{
var server = new webdav.WebDAVServer();
server.start(options.port + index);
isValid = isValid.multiple(2, server);

var wfs = Client(
"http://127.0.0.1:" + (options.port + index)
);

const folderName = 'folder';
server.rootResource.addChild(new webdav.VirtualFolder(folderName), e => {
if(e)
{
isValid(false, e)
return;
}

wfs.stat('/' + folderName, (e, stat) => {
if(e)
{
isValid(false, e)
return;
}

wfs.unlink('/' + folderName, (e) => {
if(e)
{
isValid(false, e)
return;
}

wfs.stat('/' + folderName, (e, stat) => {
isValid(!!e)
})
})
})
});

const folderName2 = 'notEmptyFolder';
const vd = new webdav.VirtualFolder(folderName2);
vd.addChild(new webdav.VirtualFolder('folder'), e => {
if(e)
{
isValid(false, e)
return;
}

vd.addChild(new webdav.VirtualFile('file.txt'), e => {
if(e)
{
isValid(false, e)
return;
}

server.rootResource.addChild(vd, e => {
if(e)
{
isValid(false, e)
return;
}

wfs.stat('/' + folderName2, (e, stat) => {
if(e)
{
isValid(false, e)
return;
}

wfs.unlink('/' + folderName2, (e) => {
if(e)
{
isValid(false, e)
return;
}

wfs.stat('/' + folderName2, (e, stat) => {
isValid(!!e)
})
})
})
});
});
});
})

0 comments on commit feb22d6

Please sign in to comment.