-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a data mapping feature that maps arguments to unrecognized flags.
- Loading branch information
1 parent
dedf9fd
commit 66439d8
Showing
4 changed files
with
175 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import 'source-map-support/register.js' | ||
import test from 'tape' | ||
import { Shell } from '../../.node/index.js' | ||
|
||
test('Map unnamed argument', t => { | ||
const shell = new Shell({ | ||
name: 'account', | ||
commands: [{ | ||
name: 'create', | ||
arguments: 'email', | ||
handler (meta) { | ||
t.ok(meta.data.hasOwnProperty('email'), 'Automapped data exists.') | ||
t.ok(meta.data.email === '[email protected]', `Attribute named email expected a value of "[email protected]". Received "${meta.data.email}".`) | ||
} | ||
}] | ||
}) | ||
|
||
shell.exec('create [email protected]') | ||
.catch(e => t.fail(e.message)) | ||
.finally(() => t.end()) | ||
}) | ||
|
||
test('Map unnamed arguments', t => { | ||
const shell = new Shell({ | ||
name: 'account', | ||
commands: [{ | ||
name: 'create', | ||
arguments: 'email displayName', | ||
handler (meta) { | ||
t.ok(meta.data.hasOwnProperty('email'), 'Automapped email data exists.') | ||
t.ok(meta.data.email === '[email protected]', `Attribute named email expected a value of "[email protected]". Received "${meta.data.email}".`) | ||
t.ok(meta.data.hasOwnProperty('displayName'), 'Automapped displayName data exists.') | ||
t.ok(meta.data.displayName === 'John Doe', `Attribute named displayName expected a value of "John Doe". Received "${meta.data.displayName}".`) | ||
} | ||
}] | ||
}) | ||
|
||
shell.exec('create [email protected] "John Doe"') | ||
.catch(e => t.fail(e.message)) | ||
.finally(() => t.end()) | ||
}) | ||
|
||
test('Map extra unnamed arguments as unknown', t => { | ||
const shell = new Shell({ | ||
name: 'account', | ||
commands: [{ | ||
name: 'create', | ||
arguments: 'email displayName', | ||
handler (meta) { | ||
t.ok(meta.data.hasOwnProperty('email'), 'Automapped email data exists.') | ||
t.ok(meta.data.email === '[email protected]', `Attribute named email expected a value of "[email protected]". Received "${meta.data.email}".`) | ||
t.ok(meta.data.hasOwnProperty('displayName'), 'Automapped displayName data exists.') | ||
t.ok(meta.data.displayName === 'John Doe', `Attribute named displayName expected a value of "John Doe". Received "${meta.data.displayName}".`) | ||
t.ok(meta.data.hasOwnProperty('unknown1'), 'Automapped unknown property to generic name.') | ||
t.ok(meta.data.unknown1 === 'test1', `Unknown attribute expected a value of "test1". Received "${meta.data.unknown1}".`) | ||
t.ok(meta.data.hasOwnProperty('unknown2'), 'Automapped extra unknown property to generic name.') | ||
t.ok(meta.data.unknown2 === 'test2', `Extra unknown attribute expected a value of "test2". Received "${meta.data.unknown2}".`) | ||
} | ||
}] | ||
}) | ||
|
||
shell.exec('create [email protected] "John Doe" test1 test2') | ||
.catch(e => t.fail(e.message)) | ||
.finally(() => t.end()) | ||
}) | ||
|
||
test('Map unnamed/unsupplied arguments as undefined', t => { | ||
const shell = new Shell({ | ||
name: 'account', | ||
commands: [{ | ||
name: 'create', | ||
arguments: 'email displayName', | ||
handler (meta) { | ||
t.ok(meta.data.hasOwnProperty('email'), 'Automapped email data exists.') | ||
t.ok(meta.data.email === '[email protected]', `Attribute named email expected a value of "[email protected]". Received "${meta.data.email}".`) | ||
t.ok(meta.data.hasOwnProperty('displayName'), 'Automapped displayName attribute exists.') | ||
t.ok(meta.data.displayName === undefined, `Attribute named displayName expected a value of "undefined". Received "${meta.data.displayName}".`) | ||
} | ||
}] | ||
}) | ||
|
||
shell.exec('create [email protected]') | ||
.catch(e => t.fail(e.message)) | ||
.finally(() => t.end()) | ||
}) | ||
|
||
test('Map unnamed arguments when duplicate names are supplied', t => { | ||
const shell = new Shell({ | ||
name: 'account', | ||
commands: [{ | ||
name: 'create', | ||
flags: { | ||
email: { | ||
alias: 'e' | ||
} | ||
}, | ||
arguments: 'email displayName', | ||
handler (meta) { | ||
t.ok(meta.data.hasOwnProperty('email'), 'Automapped email data exists.') | ||
t.ok(Array.isArray(meta.data.email) && meta.data.email[1] === '[email protected]' && meta.data.email[0] === '[email protected]', `Attribute named email expected a value of "['[email protected]', '[email protected]']". Received "[${meta.data.email.map(i => '\'' + i + '\'').reverse().join(', ')}]".`) | ||
t.ok(meta.data.displayName === undefined, `Attribute named displayName expected a value of "undefined". Received "${meta.data.displayName}".`) | ||
} | ||
}] | ||
}) | ||
|
||
shell.exec('create [email protected] -e [email protected]') | ||
.catch(e => t.fail(e.message)) | ||
.finally(() => t.end()) | ||
}) |