fix(parse): revert to 0.2 API (#10)

This commit is contained in:
Fabrice Marsaud 2016-06-07 10:10:20 +02:00 committed by Julien Fontanet
parent 0031c2a9b7
commit 32f4d42e59
2 changed files with 41 additions and 41 deletions

View File

@ -5,14 +5,8 @@ import trimStart from 'lodash/trimStart'
const sanitizePath = (...paths) => filter(map(paths, s => s && filter(map(s.split('/'), trim)).join('/'))).join('/')
export const parse = url => {
if (typeof url === 'object') {
url = url.url
}
const remote = {url}
const [type, rest] = url.split('://')
export const parse = remote => {
const [type, rest] = remote.url.split('://')
if (type === 'file') {
remote.type = 'local'
remote.path = `/${trimStart(rest, '/')}` // the leading slash has been forgotten on client side first implementation

View File

@ -11,36 +11,34 @@ import { parse, format } from './'
// Data used for both parse and format (i.e. correctly formatted).
const data = {
file: {
url: 'file:///var/lib/xoa/backup',
type: 'local',
path: '/var/lib/xoa/backup'
in: {
url: 'file:///var/lib/xoa/backup',
name: 'fileRemote'
},
out: {
url: 'file:///var/lib/xoa/backup',
type: 'local',
path: '/var/lib/xoa/backup',
name: 'fileRemote'
},
url: 'file:///var/lib/xoa/backup'
},
SMB: {
url: 'smb://Administrator:password@toto\\\\192.168.100.225\\smb\0',
type: 'smb',
host: '192.168.100.225\\smb',
path: '',
domain: 'toto',
username: 'Administrator',
password: 'password'
},
'SMB with @ sign in password': {
url: 'smb://Administrator:pass@word@toto\\\\192.168.100.225\\smb\0',
type: 'smb',
host: '192.168.100.225\\smb',
path: '',
domain: 'toto',
username: 'Administrator',
password: 'pass@word'
},
'SMB with colon in password': {
url: 'smb://Administrator:pass:word@toto\\\\192.168.100.225\\smb\0',
type: 'smb',
host: '192.168.100.225\\smb',
path: '',
domain: 'toto',
username: 'Administrator',
password: 'pass:word'
in: {
url: 'smb://Administrator:pas:sw@ord@toto\\\\192.168.100.225\\smb\0',
name: 'smbRemote'
},
out: {
url: 'smb://Administrator:pas:sw@ord@toto\\\\192.168.100.225\\smb\0',
type: 'smb',
host: '192.168.100.225\\smb',
path: '',
domain: 'toto',
username: 'Administrator',
password: 'pas:sw@ord',
name: 'smbRemote'
},
url: 'smb://Administrator:pas:sw@ord@toto\\\\192.168.100.225\\smb\0'
}
}
@ -48,9 +46,17 @@ const parseData = {
...data,
'file with missing leading slash (#7)': {
url: 'file://var/lib/xoa/backup',
type: 'local',
path: '/var/lib/xoa/backup'
in: {
url: 'file://var/lib/xoa/backup',
name: 'fileRemote'
},
out: {
url: 'file://var/lib/xoa/backup',
type: 'local',
path: '/var/lib/xoa/backup',
name: 'fileRemote'
},
url: 'file:///var/lib/xoa/backup'
}
}
@ -62,7 +68,7 @@ describe('format', () => {
for (const name in formatData) {
const datum = formatData[name]
it(name, () => {
expect(format(datum)).to.equal(datum.url)
expect(format({...datum.out})).to.equal(datum.url)
})
}
})
@ -71,7 +77,7 @@ describe('parse', () => {
for (const name in parseData) {
const datum = parseData[name]
it(name, () => {
expect(parse(datum)).to.eql(datum)
expect(parse({...datum.in})).to.eql(datum.out)
})
}
})