@salesforce/core 3.21.6 → 3.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +75 -9
- package/lib/exported.d.ts +2 -2
- package/lib/exported.js +2 -4
- package/lib/sfProject.js +6 -2
- package/lib/testSetup.d.ts +67 -4
- package/lib/testSetup.js +64 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [3.22.0](https://github.com/forcedotcom/sfdx-core/compare/v3.21.6...v3.22.0) (2022-06-23)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- modify uniqid to accept length and template ([#604](https://github.com/forcedotcom/sfdx-core/issues/604)) ([1fd1b5c](https://github.com/forcedotcom/sfdx-core/commit/1fd1b5c40ab7f9b4d66eada94f3ecfa149b263b7))
|
|
10
|
+
|
|
5
11
|
### [3.21.6](https://github.com/forcedotcom/sfdx-core/compare/v3.21.5...v3.21.6) (2022-06-23)
|
|
6
12
|
|
|
7
13
|
### [3.21.5](https://github.com/forcedotcom/sfdx-core/compare/v3.21.4...v3.21.5) (2022-06-23)
|
package/README.md
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/@salesforce/core)
|
|
2
2
|
[](https://circleci.com/gh/forcedotcom/sfdx-core)
|
|
3
3
|
|
|
4
|
+
- [Description](#description)
|
|
5
|
+
- [Usage](#usage)
|
|
6
|
+
- [Contributing](#contributing)
|
|
7
|
+
- [Using TestSetup](#using-testsetup)
|
|
8
|
+
- [Mocking Authorizations](#mocking-authorizations)
|
|
9
|
+
- [Mocking Config Files](#mocking-config-files)
|
|
10
|
+
- [Using the Built-in Sinon Sandboxes](#using-the-built-in-sinon-sandboxes)
|
|
11
|
+
- [Testing Expected Failures](#testing-expected-failures)
|
|
12
|
+
- [Testing Log Lines](#testing-log-lines)
|
|
13
|
+
|
|
4
14
|
# Description
|
|
5
15
|
|
|
6
|
-
The @salesforce/core library provides client-side management of Salesforce DX projects, org authentication, connections to Salesforce APIs, and other utilities. Much of the core functionality that powers the
|
|
16
|
+
The @salesforce/core library provides client-side management of Salesforce DX projects, org authentication, connections to Salesforce APIs, and other utilities. Much of the core functionality that powers the Salesforce CLI plugins comes from this library. You can use this functionality in your plugins too.
|
|
7
17
|
|
|
8
18
|
# Usage
|
|
9
19
|
|
|
@@ -13,16 +23,11 @@ See the [API documentation](https://forcedotcom.github.io/sfdx-core/).
|
|
|
13
23
|
|
|
14
24
|
If you are interested in contributing, please take a look at the [CONTRIBUTING](CONTRIBUTING.md) guide.
|
|
15
25
|
|
|
16
|
-
# Related Docs and Repositories
|
|
17
|
-
|
|
18
|
-
- [@salesforce/command](https://github.com/forcedotcom/cli-packages/tree/main/packages/command) - Contains base Salesforce CLI command, `SfdxCommand`.
|
|
19
|
-
- [@salesforce/plugin-generator](https://github.com/forcedotcom/sfdx-plugin-generate) - The generator plug-in for building plug-ins for Salesforce CLI.
|
|
20
|
-
|
|
21
26
|
# Using TestSetup
|
|
22
27
|
|
|
23
28
|
The Salesforce DX Core Library provides a unit testing utility to help with mocking and sand-boxing core components. This feature allows unit tests to execute without needing to make API calls to salesforce.com.
|
|
24
29
|
|
|
25
|
-
## Mocking
|
|
30
|
+
## Mocking Authorizations
|
|
26
31
|
|
|
27
32
|
Here you can mock authorization for a Salesforce scratch org.
|
|
28
33
|
|
|
@@ -77,6 +82,43 @@ describe('Mocking a force server call', () => {
|
|
|
77
82
|
});
|
|
78
83
|
```
|
|
79
84
|
|
|
85
|
+
## Mocking Config Files
|
|
86
|
+
|
|
87
|
+
You can mock the contents of various config files
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { strictEqual } from 'assert';
|
|
91
|
+
import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
|
|
92
|
+
import { StateAggregator, OrgConfigProperties } from '@salesforce/core';
|
|
93
|
+
|
|
94
|
+
const $$ = testSetup();
|
|
95
|
+
|
|
96
|
+
describe('Mocking Aliases', () => {
|
|
97
|
+
it('example', async () => {
|
|
98
|
+
const testData = new MockTestOrgData();
|
|
99
|
+
await $$.stubAliases({ myAlias: testData.username });
|
|
100
|
+
const alias = (await StateAggregator.getInstance()).aliases.get(testData.username);
|
|
101
|
+
strictEqual(alias, 'myAlais');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('Mocking Config', () => {
|
|
106
|
+
it('example', async () => {
|
|
107
|
+
const testData = new MockTestOrgData();
|
|
108
|
+
await $$.stubConfig({ [OrgConfigProperties.TARGET_ORG]: testData.username });
|
|
109
|
+
const {value} = (await ConfigAggregator.create()).getInfo(OrgConfigProperties.TARGET_ORG);
|
|
110
|
+
strictEqual(value, testData.username);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('Mocking Arbitrary Config Files', () => {
|
|
115
|
+
it('example', async () => {
|
|
116
|
+
// MyConfigFile must extend the ConfigFile class in order for this to work properly.
|
|
117
|
+
$$.setConfigStubContents('MyConfigFile', { contents: { foo: 'bar' } });
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
80
122
|
## Using the Built-in Sinon Sandboxes
|
|
81
123
|
|
|
82
124
|
sfdx-core uses Sinon as its underlying mocking system. If you're unfamiliar with Sinon and it's sandboxing concept you can find more information here:
|
|
@@ -126,6 +168,30 @@ describe('Testing for expected errors', () => {
|
|
|
126
168
|
});
|
|
127
169
|
```
|
|
128
170
|
|
|
171
|
+
You can also use `shouldThrowSync` for syncrhonous functions you expect to fail
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { SfError } from '@salesforce/core';
|
|
175
|
+
import { shouldThrowSync } from '@salesforce/core/lib/testSetup';
|
|
176
|
+
import { strictEqual } from 'assert';
|
|
177
|
+
|
|
178
|
+
class TestObject {
|
|
179
|
+
public static method() {
|
|
180
|
+
throw new SfError('Error', 'ExpectedError');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
describe('Testing for expected errors', () => {
|
|
185
|
+
it('example', async () => {
|
|
186
|
+
try {
|
|
187
|
+
shouldThrowSync(() => TestObject.method());
|
|
188
|
+
} catch (e) {
|
|
189
|
+
strictEqual(e.name, 'ExpectedError');
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
129
195
|
## Testing Log Lines
|
|
130
196
|
|
|
131
197
|
It's also useful to check expected values and content from log lines. TestSetup configures the sfdx-core logger to use an in memory LogLine storage structure. These can be easily accessed from tests.
|
|
@@ -151,9 +217,9 @@ class TestObject {
|
|
|
151
217
|
|
|
152
218
|
describe('Testing log lines', () => {
|
|
153
219
|
it('example', async () => {
|
|
154
|
-
const obj
|
|
220
|
+
const obj = new TestObject($$.TEST_LOGGER);
|
|
155
221
|
obj.method();
|
|
156
|
-
const records
|
|
222
|
+
const records = $$.TEST_LOGGER.getBufferedRecords();
|
|
157
223
|
strictEqual(records.length, 1);
|
|
158
224
|
strictEqual(records[0].msg, TEST_STRING);
|
|
159
225
|
});
|
package/lib/exported.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export { OAuth2Config } from 'jsforce';
|
|
|
2
2
|
export { ConfigFile } from './config/configFile';
|
|
3
3
|
export { TTLConfig } from './config/ttlConfig';
|
|
4
4
|
export { envVars, EnvironmentVariable, SUPPORTED_ENV_VARS, EnvVars } from './config/envVars';
|
|
5
|
-
export {
|
|
6
|
-
export { GlobalInfo,
|
|
5
|
+
export { ConfigContents, ConfigEntry, ConfigStore, ConfigValue } from './config/configStore';
|
|
6
|
+
export { GlobalInfo, SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfToken, SfTokens, StateAggregator } from './stateAggregator';
|
|
7
7
|
export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } from './deviceOauthService';
|
|
8
8
|
export { OrgUsersConfig } from './config/orgUsersConfig';
|
|
9
9
|
export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config, SfdxPropertyKeys, SfConfigProperties, SFDX_ALLOWED_PROPERTIES, SF_ALLOWED_PROPERTIES, } from './config/config';
|
package/lib/exported.js
CHANGED
|
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SfError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.SfProjectJson = exports.SfProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = exports.OrgTypes = exports.SandboxEvents = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.AuthInfo = exports.SfdxConfigAggregator = exports.ConfigAggregator = exports.SandboxRequestCache = exports.SF_ALLOWED_PROPERTIES = exports.SFDX_ALLOWED_PROPERTIES = exports.SfConfigProperties = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.StateAggregator = exports.SfInfoKeys = exports.GlobalInfo = exports.
|
|
20
|
-
exports.ScratchOrgCache = exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = exports.scratchOrgResume = exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS =
|
|
19
|
+
exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SfError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.SfProjectJson = exports.SfProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = exports.OrgTypes = exports.SandboxEvents = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.AuthInfo = exports.SfdxConfigAggregator = exports.ConfigAggregator = exports.SandboxRequestCache = exports.SF_ALLOWED_PROPERTIES = exports.SFDX_ALLOWED_PROPERTIES = exports.SfConfigProperties = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.StateAggregator = exports.SfInfoKeys = exports.GlobalInfo = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.TTLConfig = exports.ConfigFile = void 0;
|
|
20
|
+
exports.ScratchOrgCache = exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = exports.scratchOrgResume = exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = void 0;
|
|
21
21
|
const messages_1 = require("./messages");
|
|
22
22
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
23
23
|
var configFile_1 = require("./config/configFile");
|
|
@@ -29,8 +29,6 @@ Object.defineProperty(exports, "envVars", { enumerable: true, get: function () {
|
|
|
29
29
|
Object.defineProperty(exports, "EnvironmentVariable", { enumerable: true, get: function () { return envVars_1.EnvironmentVariable; } });
|
|
30
30
|
Object.defineProperty(exports, "SUPPORTED_ENV_VARS", { enumerable: true, get: function () { return envVars_1.SUPPORTED_ENV_VARS; } });
|
|
31
31
|
Object.defineProperty(exports, "EnvVars", { enumerable: true, get: function () { return envVars_1.EnvVars; } });
|
|
32
|
-
var configStore_1 = require("./config/configStore");
|
|
33
|
-
Object.defineProperty(exports, "BaseConfigStore", { enumerable: true, get: function () { return configStore_1.BaseConfigStore; } });
|
|
34
32
|
var stateAggregator_1 = require("./stateAggregator");
|
|
35
33
|
Object.defineProperty(exports, "GlobalInfo", { enumerable: true, get: function () { return stateAggregator_1.GlobalInfo; } });
|
|
36
34
|
Object.defineProperty(exports, "SfInfoKeys", { enumerable: true, get: function () { return stateAggregator_1.SfInfoKeys; } });
|
package/lib/sfProject.js
CHANGED
|
@@ -68,13 +68,17 @@ class SfProjectJson extends configFile_1.ConfigFile {
|
|
|
68
68
|
return contents;
|
|
69
69
|
}
|
|
70
70
|
async write(newContents) {
|
|
71
|
-
|
|
71
|
+
if (newContents) {
|
|
72
|
+
this.setContents(newContents);
|
|
73
|
+
}
|
|
72
74
|
this.validateKeys();
|
|
73
75
|
await this.schemaValidate();
|
|
74
76
|
return super.write();
|
|
75
77
|
}
|
|
76
78
|
writeSync(newContents) {
|
|
77
|
-
|
|
79
|
+
if (newContents) {
|
|
80
|
+
this.setContents(newContents);
|
|
81
|
+
}
|
|
78
82
|
this.validateKeys();
|
|
79
83
|
this.schemaValidateSync();
|
|
80
84
|
return super.writeSync();
|
package/lib/testSetup.d.ts
CHANGED
|
@@ -164,14 +164,45 @@ export interface TestContext {
|
|
|
164
164
|
* @param value The actual stub contents. The Mock data.
|
|
165
165
|
*/
|
|
166
166
|
setConfigStubContents(name: string, value: ConfigContents): void;
|
|
167
|
+
/**
|
|
168
|
+
* Set stubs for working in the context of a SfProject
|
|
169
|
+
*/
|
|
167
170
|
inProject(inProject: boolean): void;
|
|
171
|
+
/**
|
|
172
|
+
* Stub salesforce org authorizations.
|
|
173
|
+
*/
|
|
168
174
|
stubAuths(...orgs: MockTestOrgData[]): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Stub salesforce sandbox authorizations.
|
|
177
|
+
*/
|
|
169
178
|
stubSandboxes(...orgs: MockTestSandboxData[]): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Stub the aliases in the global aliases config file.
|
|
181
|
+
*/
|
|
170
182
|
stubAliases(aliases: Record<string, string>, group?: AliasGroup): void;
|
|
183
|
+
/**
|
|
184
|
+
* Stub contents in the config file.
|
|
185
|
+
*/
|
|
171
186
|
stubConfig(config: Record<string, string>): void;
|
|
187
|
+
/**
|
|
188
|
+
* Stub the tokens in the global token config file.
|
|
189
|
+
*/
|
|
172
190
|
stubTokens(tokens: Record<string, string>): void;
|
|
173
191
|
}
|
|
174
|
-
|
|
192
|
+
/**
|
|
193
|
+
* A function to generate a unique id and return it in the context of a template, if supplied.
|
|
194
|
+
*
|
|
195
|
+
* A template is a string that can contain `${%s}` to be replaced with a unique id.
|
|
196
|
+
* If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
|
|
197
|
+
*
|
|
198
|
+
* @param options an object with the following properties:
|
|
199
|
+
* - template: a template string.
|
|
200
|
+
* - length: the length of the unique id as presented in hexadecimal.
|
|
201
|
+
*/
|
|
202
|
+
export declare function uniqid(options?: {
|
|
203
|
+
template?: string;
|
|
204
|
+
length?: number;
|
|
205
|
+
}): string;
|
|
175
206
|
/**
|
|
176
207
|
* Instantiate a @salesforce/core test context. This is automatically created by `const $$ = testSetup()`
|
|
177
208
|
* but is useful if you don't want to have a global stub of @salesforce/core and you want to isolate it to
|
|
@@ -258,10 +289,10 @@ export declare const restoreContext: (testContext: TestContext) => void;
|
|
|
258
289
|
* $$.SANDBOX.stub(MyClass.prototype, 'myMethod').returnsFake(() => {});
|
|
259
290
|
*
|
|
260
291
|
* // Set the contents that is used when aliases are read. Same for all config files.
|
|
261
|
-
* $$.
|
|
292
|
+
* $$.stubAliases({ 'myTestAlias': 'user@company.com' });
|
|
262
293
|
*
|
|
263
294
|
* // Will use the contents set above.
|
|
264
|
-
* const username =
|
|
295
|
+
* const username = (await StateAggregator.getInstance()).aliases.resolveUseranme('myTestAlias');
|
|
265
296
|
* expect(username).to.equal('user@company.com');
|
|
266
297
|
* });
|
|
267
298
|
* });
|
|
@@ -416,7 +447,11 @@ export declare class StreamingMockCometClient extends CometClient {
|
|
|
416
447
|
disconnect(): Promise<void>;
|
|
417
448
|
}
|
|
418
449
|
/**
|
|
419
|
-
* Mock class for
|
|
450
|
+
* Mock class for Salesforce Orgs.
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* const testOrg = new MockTestOrgData();
|
|
454
|
+
* await $$.stubAuths(testOrg)
|
|
420
455
|
*/
|
|
421
456
|
export declare class MockTestOrgData {
|
|
422
457
|
testId: string;
|
|
@@ -441,13 +476,38 @@ export declare class MockTestOrgData {
|
|
|
441
476
|
constructor(id?: string, options?: {
|
|
442
477
|
username: string;
|
|
443
478
|
});
|
|
479
|
+
/**
|
|
480
|
+
* Add devhub username to properties.
|
|
481
|
+
*/
|
|
444
482
|
createDevHubUsername(username: string): void;
|
|
483
|
+
/**
|
|
484
|
+
* Mark this org as a devhub.
|
|
485
|
+
*/
|
|
445
486
|
makeDevHub(): void;
|
|
487
|
+
/**
|
|
488
|
+
* Returns a MockTestOrgData that represents a user created in the org.
|
|
489
|
+
*/
|
|
446
490
|
createUser(user: string): MockTestOrgData;
|
|
491
|
+
/**
|
|
492
|
+
* Return mock user information based on this org.
|
|
493
|
+
*/
|
|
447
494
|
getMockUserInfo(): JsonMap;
|
|
495
|
+
/**
|
|
496
|
+
* Return the auth config file contents.
|
|
497
|
+
*/
|
|
448
498
|
getConfig(): Promise<AuthFields>;
|
|
499
|
+
/**
|
|
500
|
+
* Return the Connection for the org.
|
|
501
|
+
*/
|
|
449
502
|
getConnection(): Promise<Connection>;
|
|
450
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Mock class for Salesforce Sandboxes.
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* const testOrg = new MockTestSandboxData();
|
|
509
|
+
* await $$.stubSandboxes(testOrg)
|
|
510
|
+
*/
|
|
451
511
|
export declare class MockTestSandboxData {
|
|
452
512
|
id: string;
|
|
453
513
|
sandboxOrgId: string;
|
|
@@ -459,5 +519,8 @@ export declare class MockTestSandboxData {
|
|
|
459
519
|
name: string;
|
|
460
520
|
username: string;
|
|
461
521
|
}>);
|
|
522
|
+
/**
|
|
523
|
+
* Return the auth config file contents.
|
|
524
|
+
*/
|
|
462
525
|
getConfig(): Promise<SandboxFields>;
|
|
463
526
|
}
|
package/lib/testSetup.js
CHANGED
|
@@ -12,6 +12,7 @@ const crypto_1 = require("crypto");
|
|
|
12
12
|
const events_1 = require("events");
|
|
13
13
|
const os_1 = require("os");
|
|
14
14
|
const path_1 = require("path");
|
|
15
|
+
const util = require("util");
|
|
15
16
|
const kit_1 = require("@salesforce/kit");
|
|
16
17
|
const ts_sinon_1 = require("@salesforce/ts-sinon");
|
|
17
18
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
@@ -29,9 +30,28 @@ const org_1 = require("./org");
|
|
|
29
30
|
const sandboxAccessor_1 = require("./stateAggregator/accessors/sandboxAccessor");
|
|
30
31
|
const aliasesConfig_1 = require("./config/aliasesConfig");
|
|
31
32
|
const global_1 = require("./global");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* A function to generate a unique id and return it in the context of a template, if supplied.
|
|
35
|
+
*
|
|
36
|
+
* A template is a string that can contain `${%s}` to be replaced with a unique id.
|
|
37
|
+
* If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
|
|
38
|
+
*
|
|
39
|
+
* @param options an object with the following properties:
|
|
40
|
+
* - template: a template string.
|
|
41
|
+
* - length: the length of the unique id as presented in hexadecimal.
|
|
42
|
+
*/
|
|
43
|
+
function uniqid(options) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const uniqueString = (0, crypto_1.randomBytes)(Math.ceil(((_a = options === null || options === void 0 ? void 0 : options.length) !== null && _a !== void 0 ? _a : 32) / 2.0))
|
|
46
|
+
.toString('hex')
|
|
47
|
+
.slice(0, (_b = options === null || options === void 0 ? void 0 : options.length) !== null && _b !== void 0 ? _b : 32);
|
|
48
|
+
if (!(options === null || options === void 0 ? void 0 : options.template)) {
|
|
49
|
+
return uniqueString;
|
|
50
|
+
}
|
|
51
|
+
return options.template.includes('%s')
|
|
52
|
+
? util.format(options.template, uniqueString)
|
|
53
|
+
: `${options.template}${uniqueString}`;
|
|
54
|
+
}
|
|
35
55
|
exports.uniqid = uniqid;
|
|
36
56
|
function getTestLocalPath(uid) {
|
|
37
57
|
return (0, path_1.join)((0, os_1.tmpdir)(), uid, 'sfdx_core', 'local');
|
|
@@ -39,11 +59,11 @@ function getTestLocalPath(uid) {
|
|
|
39
59
|
function getTestGlobalPath(uid) {
|
|
40
60
|
return (0, path_1.join)((0, os_1.tmpdir)(), uid, 'sfdx_core', 'global');
|
|
41
61
|
}
|
|
42
|
-
function retrieveRootPathSync(isGlobal, uid =
|
|
62
|
+
function retrieveRootPathSync(isGlobal, uid = uniqid()) {
|
|
43
63
|
return isGlobal ? getTestGlobalPath(uid) : getTestLocalPath(uid);
|
|
44
64
|
}
|
|
45
65
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
46
|
-
async function retrieveRootPath(isGlobal, uid =
|
|
66
|
+
async function retrieveRootPath(isGlobal, uid = uniqid()) {
|
|
47
67
|
return retrieveRootPathSync(isGlobal, uid);
|
|
48
68
|
}
|
|
49
69
|
function defaultFakeConnectionRequest() {
|
|
@@ -99,8 +119,8 @@ const instantiateContext = (sinon) => {
|
|
|
99
119
|
TEST_LOGGER: new logger_1.Logger({
|
|
100
120
|
name: 'SFDX_Core_Test_Logger',
|
|
101
121
|
}).useMemoryLogging(),
|
|
102
|
-
id:
|
|
103
|
-
uniqid
|
|
122
|
+
id: uniqid(),
|
|
123
|
+
uniqid,
|
|
104
124
|
configStubs: {},
|
|
105
125
|
stubs: {},
|
|
106
126
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -365,10 +385,10 @@ const _testSetup = (sinon) => {
|
|
|
365
385
|
* $$.SANDBOX.stub(MyClass.prototype, 'myMethod').returnsFake(() => {});
|
|
366
386
|
*
|
|
367
387
|
* // Set the contents that is used when aliases are read. Same for all config files.
|
|
368
|
-
* $$.
|
|
388
|
+
* $$.stubAliases({ 'myTestAlias': 'user@company.com' });
|
|
369
389
|
*
|
|
370
390
|
* // Will use the contents set above.
|
|
371
|
-
* const username =
|
|
391
|
+
* const username = (await StateAggregator.getInstance()).aliases.resolveUseranme('myTestAlias');
|
|
372
392
|
* expect(username).to.equal('user@company.com');
|
|
373
393
|
* });
|
|
374
394
|
* });
|
|
@@ -564,10 +584,14 @@ class StreamingMockCometClient extends streamingClient_1.CometClient {
|
|
|
564
584
|
}
|
|
565
585
|
exports.StreamingMockCometClient = StreamingMockCometClient;
|
|
566
586
|
/**
|
|
567
|
-
* Mock class for
|
|
587
|
+
* Mock class for Salesforce Orgs.
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* const testOrg = new MockTestOrgData();
|
|
591
|
+
* await $$.stubAuths(testOrg)
|
|
568
592
|
*/
|
|
569
593
|
class MockTestOrgData {
|
|
570
|
-
constructor(id =
|
|
594
|
+
constructor(id = uniqid(), options) {
|
|
571
595
|
this.testId = id;
|
|
572
596
|
this.userId = `user_id_${this.testId}`;
|
|
573
597
|
this.orgId = `${this.testId}`;
|
|
@@ -581,12 +605,21 @@ class MockTestOrgData {
|
|
|
581
605
|
this.refreshToken = `${this.testId}/refreshToken`;
|
|
582
606
|
this.redirectUri = 'http://localhost:1717/OauthRedirect';
|
|
583
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* Add devhub username to properties.
|
|
610
|
+
*/
|
|
584
611
|
createDevHubUsername(username) {
|
|
585
612
|
this.devHubUsername = username;
|
|
586
613
|
}
|
|
614
|
+
/**
|
|
615
|
+
* Mark this org as a devhub.
|
|
616
|
+
*/
|
|
587
617
|
makeDevHub() {
|
|
588
618
|
this.isDevHub = true;
|
|
589
619
|
}
|
|
620
|
+
/**
|
|
621
|
+
* Returns a MockTestOrgData that represents a user created in the org.
|
|
622
|
+
*/
|
|
590
623
|
createUser(user) {
|
|
591
624
|
const userMock = new MockTestOrgData();
|
|
592
625
|
userMock.username = user;
|
|
@@ -604,6 +637,9 @@ class MockTestOrgData {
|
|
|
604
637
|
userMock.isExpired = this.isExpired;
|
|
605
638
|
return userMock;
|
|
606
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Return mock user information based on this org.
|
|
642
|
+
*/
|
|
607
643
|
getMockUserInfo() {
|
|
608
644
|
return {
|
|
609
645
|
Id: this.userId,
|
|
@@ -619,6 +655,9 @@ class MockTestOrgData {
|
|
|
619
655
|
Email: `user_email@${this.testId}.com`,
|
|
620
656
|
};
|
|
621
657
|
}
|
|
658
|
+
/**
|
|
659
|
+
* Return the auth config file contents.
|
|
660
|
+
*/
|
|
622
661
|
async getConfig() {
|
|
623
662
|
const crypto = await crypto_2.Crypto.create();
|
|
624
663
|
const config = {};
|
|
@@ -644,19 +683,32 @@ class MockTestOrgData {
|
|
|
644
683
|
config.isDevHub = this.isDevHub;
|
|
645
684
|
return config;
|
|
646
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* Return the Connection for the org.
|
|
688
|
+
*/
|
|
647
689
|
async getConnection() {
|
|
648
690
|
return (await org_1.Org.create({ aliasOrUsername: this.username })).getConnection();
|
|
649
691
|
}
|
|
650
692
|
}
|
|
651
693
|
exports.MockTestOrgData = MockTestOrgData;
|
|
694
|
+
/**
|
|
695
|
+
* Mock class for Salesforce Sandboxes.
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* const testOrg = new MockTestSandboxData();
|
|
699
|
+
* await $$.stubSandboxes(testOrg)
|
|
700
|
+
*/
|
|
652
701
|
class MockTestSandboxData {
|
|
653
|
-
constructor(id =
|
|
702
|
+
constructor(id = uniqid(), options) {
|
|
654
703
|
this.id = id;
|
|
655
704
|
this.sandboxOrgId = id;
|
|
656
705
|
this.prodOrgUsername = (options === null || options === void 0 ? void 0 : options.prodOrgUsername) || `admin_${id}@gb.org`;
|
|
657
706
|
this.sandboxName = (options === null || options === void 0 ? void 0 : options.name) || `sandbox_${id}`;
|
|
658
707
|
this.username = (options === null || options === void 0 ? void 0 : options.username) || `${this.prodOrgUsername}.sandbox`;
|
|
659
708
|
}
|
|
709
|
+
/**
|
|
710
|
+
* Return the auth config file contents.
|
|
711
|
+
*/
|
|
660
712
|
async getConfig() {
|
|
661
713
|
return {
|
|
662
714
|
sandboxOrgId: this.sandboxOrgId,
|