Skip to content

Commit

Permalink
Added tests for the MKCOL method
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 28, 2017
1 parent 056df31 commit d895732
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/v2/tests.ts/mkcol/.createFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { TestCallback, TestInfo } from '../Type'
import { v2 } from '../../../../lib/index.js'

export function starter(server : v2.WebDAVServer, info : TestInfo, isValid : TestCallback, name : string, expectedStatusCode : number, callback ?: (server : v2.WebDAVServer) => void) : void
{
server.rootFileSystem().addSubTree(v2.RequestContext.createExternal(server), {
'emptyFolder1': v2.ResourceType.Directory,
'folder1': {
'emptyFolder2': v2.ResourceType.Directory,
'file2': v2.ResourceType.File,
'folder2': {
'emptyFolder3': v2.ResourceType.Directory,
'file3': v2.ResourceType.File
}
},
'file1': v2.ResourceType.File
}, (e) => {
if(e) return isValid(false, 'Cannot call "addSubTree(...)".', e);

info.req({
url: 'http://localhost:' + server.options.port + '/' + name,
method: 'MKCOL'
}, expectedStatusCode, () => {
if(!callback)
isValid(true);
else
callback(server);
})
})
}
13 changes: 13 additions & 0 deletions test/v2/tests.ts/mkcol/mkcolOnFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Test } from '../Type'
import { v2 } from '../../../../lib/index.js'
import { starter } from './.createFiles'

export default ((info, isValid) =>
{
const server1 = info.init(3);

starter(info.startServer(), info, isValid, 'file1', v2.HTTPCodes.MethodNotAllowed);
starter(info.startServer(), info, isValid, 'file1/folder', v2.HTTPCodes.Forbidden);
starter(info.startServer(), info, isValid, 'file1/unmapped/folder', v2.HTTPCodes.Conflict);

}) as Test;
23 changes: 23 additions & 0 deletions test/v2/tests.ts/mkcol/mkcolOnFolder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Test } from '../Type'
import { v2 } from '../../../../lib/index.js'
import { starter } from './.createFiles'

export default ((info, isValid) =>
{
const server1 = info.init(3);

starter(info.startServer(), info, isValid, 'folder1', v2.HTTPCodes.MethodNotAllowed);
starter(info.startServer(), info, isValid, 'folder1/unmapped/folder', v2.HTTPCodes.Conflict);
starter(info.startServer(), info, isValid, 'folder1/folder', v2.HTTPCodes.Created, (server) => {
info.req({
url: 'http://localhost:' + server.options.port + '/folder1/folder',
method: 'PROPFIND',
headers: {
Depth: 0
}
}, v2.HTTPCodes.MultiStatus, () => {
isValid(true);
})
});

}) as Test;
23 changes: 23 additions & 0 deletions test/v2/tests.ts/mkcol/mkcolOnUndefined.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Test } from '../Type'
import { v2 } from '../../../../lib/index.js'
import { starter } from './.createFiles'

export default ((info, isValid) =>
{
const server1 = info.init(3);

starter(info.startServer(), info, isValid, 'unmapped/folder', v2.HTTPCodes.Conflict);
starter(info.startServer(), info, isValid, 'unmapped/unmapped/folder', v2.HTTPCodes.Conflict);
starter(info.startServer(), info, isValid, 'unmapped', v2.HTTPCodes.Created, (server) => {
info.req({
url: 'http://localhost:' + server.options.port + '/unmapped',
method: 'PROPFIND',
headers: {
Depth: 0
}
}, v2.HTTPCodes.MultiStatus, () => {
isValid(true);
})
});

}) as Test;

0 comments on commit d895732

Please sign in to comment.