[ARVADOS-WORKBENCH2] updated: 1.1.4-573-g4b7d15c

Git user git at public.curoverse.com
Thu Aug 9 09:53:38 EDT 2018


Summary of changes:
 src/common/webdav.test.ts | 89 +++++++++++++++++++++++++++++++++++++++++++++++
 src/common/webdav.ts      |  8 ++---
 2 files changed, 93 insertions(+), 4 deletions(-)
 create mode 100644 src/common/webdav.test.ts

       via  4b7d15c94685ca3e34ebb905a4803f895367ad09 (commit)
      from  1c42304ed00d0055e24070793e0cef08a7c76c97 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 4b7d15c94685ca3e34ebb905a4803f895367ad09
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Thu Aug 9 15:53:24 2018 +0200

    Create webdav client tests
    
    Feature #13989
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/common/webdav.test.ts b/src/common/webdav.test.ts
new file mode 100644
index 0000000..7da1585
--- /dev/null
+++ b/src/common/webdav.test.ts
@@ -0,0 +1,89 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { WebDAV } from "./webdav";
+
+describe('WebDAV', () => {
+    it('makes use of provided config', async () => {
+        const { open, load, setRequestHeader, createRequest } = mockCreateRequest();
+        const webdav = WebDAV.create({ baseUrl: 'http://foo.com/', headers: { Authorization: 'Basic' } }, createRequest);
+        const promise = webdav.propfind('foo');
+        load();
+        const request = await promise;
+        expect(open).toHaveBeenCalledWith('PROPFIND', 'http://foo.com/foo');
+        expect(setRequestHeader).toHaveBeenCalledWith('Authorization', 'Basic');
+        expect(request).toBeInstanceOf(XMLHttpRequest);
+    });
+
+    it('PROPFIND', async () => {
+        const { open, load, createRequest } = mockCreateRequest();
+        const webdav = WebDAV.create(undefined, createRequest);
+        const promise = webdav.propfind('foo');
+        load();
+        const request = await promise;
+        expect(open).toHaveBeenCalledWith('PROPFIND', 'foo');
+        expect(request).toBeInstanceOf(XMLHttpRequest);
+    });
+
+    it('PUT', async () => {
+        const { open, send, load, createRequest } = mockCreateRequest();
+        const webdav = WebDAV.create(undefined, createRequest);
+        const promise = webdav.put('foo', { data: 'Test data' });
+        load();
+        const request = await promise;
+        expect(open).toHaveBeenCalledWith('PUT', 'foo');
+        expect(send).toHaveBeenCalledWith('Test data');
+        expect(request).toBeInstanceOf(XMLHttpRequest);
+    });
+
+    it('COPY', async () => {
+        const { open, setRequestHeader, load, createRequest } = mockCreateRequest();
+        const webdav = WebDAV.create(undefined, createRequest);
+        const promise = webdav.copy('foo', { destination: 'foo-copy' });
+        load();
+        const request = await promise;
+        expect(open).toHaveBeenCalledWith('COPY', 'foo');
+        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'foo-copy');
+        expect(request).toBeInstanceOf(XMLHttpRequest);
+    });
+
+    it('MOVE', async () => {
+        const { open, setRequestHeader, load, createRequest } = mockCreateRequest();
+        const webdav = WebDAV.create(undefined, createRequest);
+        const promise = webdav.move('foo', { destination: 'foo-copy' });
+        load();
+        const request = await promise;
+        expect(open).toHaveBeenCalledWith('MOVE', 'foo');
+        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'foo-copy');
+        expect(request).toBeInstanceOf(XMLHttpRequest);
+    });
+
+    it('DELETE', async () => {
+        const { open, load, createRequest } = mockCreateRequest();
+        const webdav = WebDAV.create(undefined, createRequest);
+        const promise = webdav.delete('foo');
+        load();
+        const request = await promise;
+        expect(open).toHaveBeenCalledWith('DELETE', 'foo');
+        expect(request).toBeInstanceOf(XMLHttpRequest);
+    });
+});
+
+const mockCreateRequest = () => {
+    const send = jest.fn();
+    const open = jest.fn();
+    const setRequestHeader = jest.fn();
+    const request = new XMLHttpRequest();
+    request.send = send;
+    request.open = open;
+    request.setRequestHeader = setRequestHeader;
+    const load = () => request.dispatchEvent(new Event('load'));
+    return {
+        send,
+        open,
+        load,
+        setRequestHeader,
+        createRequest: () => request
+    };
+};
diff --git a/src/common/webdav.ts b/src/common/webdav.ts
index 5c7f9d2..24dacbd 100644
--- a/src/common/webdav.ts
+++ b/src/common/webdav.ts
@@ -3,8 +3,8 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 export class WebDAV {
-    static create(config?: Partial<WebDAVDefaults>) {
-        return new WebDAV(config);
+    static create(config?: Partial<WebDAVDefaults>, createRequest?: () => XMLHttpRequest) {
+        return new WebDAV(config, createRequest);
     }
 
     defaults: WebDAVDefaults = {
@@ -44,7 +44,7 @@ export class WebDAV {
             method: 'DELETE'
         })
 
-    private constructor(config?: Partial<WebDAVDefaults>) {
+    private constructor(config?: Partial<WebDAVDefaults>, private createRequest = () => new XMLHttpRequest()) {
         if (config) {
             this.defaults = { ...this.defaults, ...config };
         }
@@ -52,7 +52,7 @@ export class WebDAV {
 
     private request = (config: RequestConfig) => {
         return new Promise<XMLHttpRequest>((resolve, reject) => {
-            const r = new XMLHttpRequest();
+            const r = this.createRequest();
             r.open(config.method, this.defaults.baseUrl + config.url);
 
             const headers = { ...this.defaults.headers, ...config.headers };

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list