Skip to content

Commit

Permalink
Make BaseClient#getItemURL async
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragnis committed Jun 2, 2018
1 parent 1456df0 commit 30a80b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/baseclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

/**
Expand Down
15 changes: 9 additions & 6 deletions test/unit/baseclient-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
},

Expand All @@ -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');
});
});
}
},

Expand Down

0 comments on commit 30a80b2

Please sign in to comment.