From 30a80b2784a8df0bd6420a538b2c82c12cf48b4a Mon Sep 17 00:00:00 2001
From: Ragnis Armus <ragnis@aragnis.com>
Date: Sat, 2 Jun 2018 18:58:58 +0300
Subject: [PATCH] Make BaseClient#getItemURL async

---
 src/baseclient.js             | 10 +++++-----
 test/unit/baseclient-suite.js | 15 +++++++++------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/baseclient.js b/src/baseclient.js
index d5f0117e2..3be9203d7 100644
--- a/src/baseclient.js
+++ b/src/baseclient.js
@@ -289,18 +289,18 @@ BaseClient.prototype = {
    * URL of an item in the ``/public`` folder.
    *
    * @param {string} path - Path relative to the module root.
-   * @returns {string} The full URL of the item, including the storage origin
+   * @returns {Promise} Resolves to t he full URL of the item, including the storage origin.
    */
   getItemURL: function (path) {
     if (typeof(path) !== 'string') {
-      throw 'Argument \'path\' of baseClient.getItemURL must be a string';
+      return Promise.reject('Argument \'path\' of baseClient.getItemURL must be a string');
     }
+    let url;
     if (this.storage.connected) {
       path = this._cleanPath( this.makePath(path) );
-      return this.storage.remote.href + path;
-    } else {
-      return undefined;
+      url = this.storage.remote.href + path;
     }
+    return Promise.resolve(url);
   },
 
   /**
diff --git a/test/unit/baseclient-suite.js b/test/unit/baseclient-suite.js
index f5417df27..6679b694e 100644
--- a/test/unit/baseclient-suite.js
+++ b/test/unit/baseclient-suite.js
@@ -403,8 +403,9 @@ define(['./src/config', './src/baseclient', 'test/helpers/mocks', 'tv4'],
           env.storage.connected = true;
           env.storage.remote = {href: 'http://example.com/test'};
 
-          var itemURL = env.client.getItemURL('A%2FB /C/%bla//D');
-          test.assert(itemURL, 'http://example.com/test/foo/A%252FB%20/C/%25bla/D');
+          env.client.getItemURL('A%2FB /C/%bla//D').then((itemURL) => {
+            test.assert(itemURL, 'http://example.com/test/foo/A%252FB%20/C/%25bla/D');
+          });
         }
       },
 
@@ -414,11 +415,13 @@ define(['./src/config', './src/baseclient', 'test/helpers/mocks', 'tv4'],
           env.storage.connected = true;
           env.storage.remote = {href: 'http://example.com/test'};
 
-          test.assert(env.client.getItemURL("Capture d'écran"),
-                      'http://example.com/test/foo/Capture%20d%27%C3%A9cran');
+          env.client.getItemURL("Capture d'écran").then((itemURL) => {
+            test.assertAnd(itemURL, 'http://example.com/test/foo/Capture%20d%27%C3%A9cran');
 
-          test.assert(env.client.getItemURL('So they said "hey"'),
-                      'http://example.com/test/foo/So%20they%20said%20%22hey%22');
+            env.client.getItemURL('So they said "hey"').then((itemURL) => {
+              test.assert(itemURL, 'http://example.com/test/foo/So%20they%20said%20%22hey%22');
+            });
+          });
         }
       },