This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
set.nut.ts
122 lines (109 loc) · 4.37 KB
/
set.nut.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright (c) 2020, 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 { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { getNumber, getString } from '@salesforce/ts-types';
import { expect } from '@salesforce/command/lib/test';
let testSession: TestSession;
function unsetAll() {
execCmd('sfdx alias:unset DevHub');
execCmd('sfdx alias:unset Admin');
execCmd('sfdx alias:unset user');
}
describe('alias:set NUTs', async () => {
testSession = await TestSession.create();
describe('initial alias setup', () => {
beforeEach(() => {
unsetAll();
});
it('alias:set multiple values and json', () => {
const res = execCmd('alias:set [email protected] [email protected] --json', {
ensureExitCode: 0,
});
expect(res.jsonOutput).to.deep.equal({
result: [
{ alias: 'DevHub', value: '[email protected]' },
{ alias: 'Admin', value: '[email protected]' },
],
status: 0,
});
});
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');
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 res = execCmd('alias:set [email protected] [email protected] --json', {
ensureExitCode: 0,
});
expect(res.jsonOutput).to.deep.equal({
result: [
// newdevhub verified
{ alias: 'DevHub', value: '[email protected]' },
{ alias: 'Admin', value: '[email protected]' },
],
status: 0,
});
});
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');
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= sets DevHub entry to undefined stdout', () => {
const res: string = execCmd('alias:set DevHub=', {
ensureExitCode: 0,
}).shellOutput;
expect(res).to.include('=== Alias Set');
expect(res).to.include('Alias Value');
expect(res).to.include('DevHub');
expect(res).to.not.include('[email protected]');
});
});
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('VarargsRequired');
expect(getString(res.jsonOutput, 'stack')).to.contain('VarargsRequired');
expect(getString(res.jsonOutput, 'message')).to.equal(
'Provide required name=value pairs for the command. Enclose any values that contain spaces in double quotes.'
);
expect(getNumber(res.jsonOutput, 'exitCode')).to.equal(1);
expect(getNumber(res.jsonOutput, 'status')).to.equal(1);
});
it('alias:set without varargs stdout', () => {
const res: string = execCmd('alias:set ').shellOutput.stderr;
expect(res).to.include(
'ERROR running alias:set: Provide required name=value pairs for the command. Enclose any values that contain spaces in double quotes.'
);
});
});
});
afterEach(async () => {
await testSession?.clean();
});