generated from salesforcecli/plugin-template-sf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d89d967
commit 667d294
Showing
5 changed files
with
255 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 @@ | ||
/* | ||
* Copyright (c) 2022, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import * as os from 'os'; | ||
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; | ||
import { expect } from 'chai'; | ||
|
||
function unsetAll() { | ||
execCmd('sf alias unset DevHub'); | ||
execCmd('sf alias unset Admin'); | ||
execCmd('sf alias unset user'); | ||
} | ||
|
||
describe('alias list NUTs', () => { | ||
let session: TestSession; | ||
|
||
before(async () => { | ||
session = await TestSession.create({ | ||
project: { name: 'aliasListNUTs' }, | ||
authStrategy: 'NONE', | ||
}); | ||
}); | ||
|
||
after(async () => { | ||
await session?.clean(); | ||
}); | ||
|
||
describe('alias list without results', () => { | ||
beforeEach(() => { | ||
unsetAll(); | ||
}); | ||
|
||
it('lists no aliases correctly', () => { | ||
const { result } = execCmd('alias list --json', { ensureExitCode: 0 }).jsonOutput; | ||
expect(result).to.deep.equal([]); | ||
}); | ||
|
||
it('lists no aliases stdout', () => { | ||
const res: string = execCmd('alias list').shellOutput; | ||
expect(res).to.include('No aliases found'); | ||
}); | ||
}); | ||
|
||
describe('alias list with singular result', () => { | ||
beforeEach(() => { | ||
unsetAll(); | ||
execCmd('alias set [email protected]'); | ||
}); | ||
|
||
it('lists singular alias correctly', () => { | ||
const { result } = execCmd('alias list --json', { ensureExitCode: 0 }).jsonOutput; | ||
expect(result).to.deep.equal([ | ||
{ | ||
alias: 'DevHub', | ||
value: '[email protected]', | ||
}, | ||
]); | ||
}); | ||
|
||
it('lists singular result correctly stdout', () => { | ||
const res: string = execCmd('alias list', { ensureExitCode: 0 }).shellOutput; | ||
expect(res).to.include(`Alias List${os.EOL}=====`); // Table header | ||
expect(res).to.include('DevHub'); | ||
expect(res).to.include('[email protected]'); | ||
}); | ||
}); | ||
|
||
describe('alias list with multiple results', () => { | ||
beforeEach(() => { | ||
unsetAll(); | ||
execCmd('alias set [email protected]'); | ||
execCmd('alias set [email protected]'); | ||
execCmd('alias set [email protected]'); | ||
}); | ||
|
||
it('lists multiple results correctly JSON', () => { | ||
const { result } = execCmd('alias list --json', { ensureExitCode: 0 }).jsonOutput; | ||
expect(result).to.deep.equal([ | ||
{ | ||
alias: 'DevHub', | ||
value: '[email protected]', | ||
}, | ||
{ | ||
alias: 'Admin', | ||
value: '[email protected]', | ||
}, | ||
{ | ||
alias: 'user', | ||
value: '[email protected]', | ||
}, | ||
]); | ||
}); | ||
|
||
it('lists multiple results correctly stdout', () => { | ||
const res: string = execCmd('alias list', { ensureExitCode: 0 }).shellOutput; | ||
expect(res).to.include(`Alias List${os.EOL}=====`); // Table header | ||
expect(res).to.include('DevHub'); | ||
expect(res).to.include('[email protected]'); | ||
expect(res).to.include('Admin'); | ||
expect(res).to.include('[email protected]'); | ||
expect(res).to.include('user'); | ||
expect(res).to.include('[email protected]'); | ||
}); | ||
}); | ||
}); |
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,132 @@ | ||
/* | ||
* Copyright (c) 2022, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import * as os from 'os'; | ||
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; | ||
import { getNumber, getString } from '@salesforce/ts-types'; | ||
import { expect } from 'chai'; | ||
import { Messages } from '@salesforce/core'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.load('@salesforce/plugin-settings', 'alias.set', [ | ||
// 'summary', | ||
// 'description', | ||
// 'examples', | ||
'error.ArgumentsRequired', | ||
// 'error.DuplicateArgument', | ||
// 'error.InvalidArgumentFormat', | ||
'error.ValueRequired', | ||
]); | ||
|
||
function unsetAll() { | ||
execCmd('alias unset DevHub Admin user'); | ||
} | ||
|
||
describe('alias set NUTs', () => { | ||
let session: TestSession; | ||
|
||
before(async () => { | ||
session = await TestSession.create({ | ||
project: { name: 'aliasSetNUTs' }, | ||
authStrategy: 'NONE', | ||
}); | ||
}); | ||
|
||
after(async () => { | ||
await session?.clean(); | ||
}); | ||
|
||
describe('initial alias setup', () => { | ||
beforeEach(() => { | ||
unsetAll(); | ||
}); | ||
|
||
it('alias set multiple values and json', () => { | ||
const { result } = execCmd('alias set [email protected] [email protected] --json', { | ||
ensureExitCode: 0, | ||
}).jsonOutput; | ||
|
||
expect(result).to.deep.equal([ | ||
{ alias: 'DevHub', value: '[email protected]' }, | ||
{ alias: 'Admin', value: '[email protected]' }, | ||
]); | ||
}); | ||
|
||
it('alias set multiple values stdout', () => { | ||
const res: string = execCmd('alias set [email protected] [email protected]', { | ||
ensureExitCode: 0, | ||
}).shellOutput; | ||
|
||
expect(res).to.include(`Alias Set${os.EOL}=====`); // Table header | ||
expect(res).to.include('Alias Value'); | ||
expect(res).to.include('DevHub'); | ||
expect(res).to.include('[email protected]'); | ||
expect(res).to.include('Admin'); | ||
expect(res).to.include('[email protected]'); | ||
}); | ||
}); | ||
|
||
describe('alias set overwrites existing entry', () => { | ||
beforeEach(() => { | ||
unsetAll(); | ||
execCmd('alias set [email protected]'); | ||
}); | ||
|
||
it('alias set overwrites existing entry correctly json', () => { | ||
// overwriting DevHub entry to point to newdevhub | ||
const { result } = execCmd('alias set [email protected] [email protected] --json', { | ||
ensureExitCode: 0, | ||
}).jsonOutput; | ||
|
||
expect(result).to.deep.equal([ | ||
// newdevhub verified | ||
{ alias: 'DevHub', value: '[email protected]' }, | ||
{ alias: 'Admin', value: '[email protected]' }, | ||
]); | ||
}); | ||
|
||
it('alias set overwrites entry correctly stdout', () => { | ||
const res: string = execCmd('alias set [email protected] [email protected]', { | ||
ensureExitCode: 0, | ||
}).shellOutput; | ||
expect(res).to.include(`Alias Set${os.EOL}=====`); // Table header | ||
expect(res).to.include('Alias Value'); | ||
expect(res).to.include('DevHub'); | ||
expect(res).to.include('[email protected]'); | ||
expect(res).to.include('Admin'); | ||
expect(res).to.include('[email protected]'); | ||
}); | ||
|
||
it('alias set DevHub= shows error to use alias unset command', () => { | ||
const res = execCmd('alias set DevHub=', { | ||
ensureExitCode: 1, | ||
}).shellOutput.stderr; | ||
|
||
expect(res).to.include(messages.getMessages('error.ValueRequired')); | ||
}); | ||
}); | ||
|
||
describe('alias set without varargs throws error', () => { | ||
it('alias set --json', () => { | ||
// access each member individually because the stack trace will be different | ||
const res = execCmd('alias set --json'); | ||
expect(getNumber(res.jsonOutput, 'status')).to.equal(1); | ||
expect(getString(res.jsonOutput, 'name')).to.equal('ArgumentsRequiredError'); | ||
expect(getString(res.jsonOutput, 'stack')).to.contain('ArgumentsRequiredError'); | ||
expect(getString(res.jsonOutput, 'message')).to.include(messages.getMessages('error.ArgumentsRequired')); | ||
expect(getNumber(res.jsonOutput, 'exitCode')).to.equal(1); | ||
}); | ||
|
||
it('alias set without varargs stdout', () => { | ||
const res: string = execCmd('alias set', { | ||
ensureExitCode: 1, | ||
}).shellOutput.stderr; | ||
|
||
expect(res).to.include(messages.getMessages('error.ArgumentsRequired')); | ||
}); | ||
}); | ||
}); |