mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-21 22:47:48 +00:00
Implement constructRemoteUrl helper function
This commit is contained in:
parent
141fa9be6d
commit
e52eb75ac8
@ -1,3 +1,4 @@
|
||||
url = require('url')
|
||||
_ = require('lodash')
|
||||
resin = require('../resin')
|
||||
|
||||
@ -12,3 +13,10 @@ exports.isDeviceUUIDValid = (uuid, callback) ->
|
||||
return callback?(error) if error?
|
||||
uuidExists = _.findWhere(devices, { uuid })?
|
||||
return callback(null, uuidExists)
|
||||
|
||||
exports.constructRemoteUrl = (base, path, query) ->
|
||||
if not _.isEmpty(query)
|
||||
formattedQuery = url.format({ query })
|
||||
path = url.resolve(path, formattedQuery)
|
||||
|
||||
return url.resolve(base, path)
|
||||
|
@ -63,3 +63,19 @@ describe 'Helpers:', ->
|
||||
expect(error).to.not.exist
|
||||
expect(isValid).to.be.false
|
||||
done()
|
||||
|
||||
describe '#constructRemoteUrl', ->
|
||||
|
||||
URL =
|
||||
base: 'http://google.com'
|
||||
path: '/search'
|
||||
query:
|
||||
foo: 'bar'
|
||||
|
||||
it 'should concatenate a url and a path', ->
|
||||
result = helpers.constructRemoteUrl(URL.base, URL.path)
|
||||
expect(result).to.equal(URL.base + URL.path)
|
||||
|
||||
it 'should add url queries', ->
|
||||
result = helpers.constructRemoteUrl(URL.base, URL.path, URL.query)
|
||||
expect(result).to.equal("#{URL.base}#{URL.path}?foo=bar")
|
||||
|
Loading…
Reference in New Issue
Block a user