diff --git a/test/v2/tests.ts/mkcol/.createFiles.ts b/test/v2/tests.ts/mkcol/.createFiles.ts new file mode 100644 index 00000000..b581796b --- /dev/null +++ b/test/v2/tests.ts/mkcol/.createFiles.ts @@ -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); + }) + }) +} diff --git a/test/v2/tests.ts/mkcol/mkcolOnFile.ts b/test/v2/tests.ts/mkcol/mkcolOnFile.ts new file mode 100644 index 00000000..632c07f4 --- /dev/null +++ b/test/v2/tests.ts/mkcol/mkcolOnFile.ts @@ -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; diff --git a/test/v2/tests.ts/mkcol/mkcolOnFolder.ts b/test/v2/tests.ts/mkcol/mkcolOnFolder.ts new file mode 100644 index 00000000..74b78e81 --- /dev/null +++ b/test/v2/tests.ts/mkcol/mkcolOnFolder.ts @@ -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; diff --git a/test/v2/tests.ts/mkcol/mkcolOnUndefined.ts b/test/v2/tests.ts/mkcol/mkcolOnUndefined.ts new file mode 100644 index 00000000..f09436be --- /dev/null +++ b/test/v2/tests.ts/mkcol/mkcolOnUndefined.ts @@ -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;