1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.$$ = exports.test = exports.OclifConfig = exports.loadConfig = exports.command = exports.Config = exports.FancyTypes = exports.expect = void 0;
|
4 | const oclifTest = require("@oclif/test");
|
5 | const test_1 = require("@oclif/test");
|
6 | Object.defineProperty(exports, "command", { enumerable: true, get: function () { return test_1.command; } });
|
7 | Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return test_1.Config; } });
|
8 | Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_1.expect; } });
|
9 | Object.defineProperty(exports, "FancyTypes", { enumerable: true, get: function () { return test_1.FancyTypes; } });
|
10 | const core_1 = require("@oclif/core");
|
11 | Object.defineProperty(exports, "OclifConfig", { enumerable: true, get: function () { return core_1.Config; } });
|
12 | const core_2 = require("@salesforce/core");
|
13 | const testSetup_1 = require("@salesforce/core/lib/testSetup");
|
14 | const ts_types_1 = require("@salesforce/ts-types");
|
15 | const load_config_1 = require("@oclif/test/lib/load-config");
|
16 | Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return load_config_1.loadConfig; } });
|
17 | load_config_1.loadConfig.root = (0, ts_types_1.ensure)(module.parent).filename;
|
18 | const $$ = (0, testSetup_1.testSetup)();
|
19 | exports.$$ = $$;
|
20 | function find(orgs, predicate) {
|
21 | return (0, ts_types_1.definiteValuesOf)(orgs).filter(predicate)[0];
|
22 | }
|
23 | const withOrg = (org = {}, setAsDefault = true) => {
|
24 | return {
|
25 |
|
26 |
|
27 | run(ctx) {
|
28 | if (!ctx.orgs) {
|
29 | ctx.orgs = {};
|
30 | }
|
31 | if (!org.username) {
|
32 | org.username = 'test@org.com';
|
33 | }
|
34 | ctx.orgs[org.username] = {};
|
35 |
|
36 | ctx.orgs[org.username].orgs = {
|
37 | [org.username]: Object.assign({
|
38 | orgId: '0x012123',
|
39 | instanceUrl: 'http://na30.salesforce.com',
|
40 | loginUrl: 'https://login.salesforce.com',
|
41 | created: '1519163543003',
|
42 | isDevHub: false,
|
43 | default: setAsDefault,
|
44 | }, org),
|
45 | };
|
46 |
|
47 | const readOrg = async function () {
|
48 | return (0, ts_types_1.asJsonMap)(ctx.orgs[org.username], {});
|
49 | };
|
50 |
|
51 | const writeOrg = async function () {
|
52 | const foundOrg = (0, ts_types_1.asJsonMap)(ctx.orgs[org.username], {});
|
53 | return ((0, ts_types_1.ensure)($$.configStubs.GlobalInfo).contents = { orgs: { [org.username]: foundOrg } });
|
54 | };
|
55 | $$.configStubs.GlobalInfo = {
|
56 | retrieveContents: readOrg,
|
57 | updateContents: writeOrg,
|
58 | };
|
59 | const defaultOrg = find(ctx.orgs, (o) => !!o.default && !o.isDevHub);
|
60 | const defaultDevHubOrg = find(ctx.orgs, (o) => !!o.default && !!o.isDevHub);
|
61 | $$.configStubs.Config = {
|
62 | contents: {
|
63 | defaultusername: defaultOrg && defaultOrg.username,
|
64 | defaultdevhubusername: defaultDevHubOrg && defaultDevHubOrg.username,
|
65 | },
|
66 | };
|
67 | },
|
68 | };
|
69 | };
|
70 | const withConnectionRequest = (fakeFunction) => {
|
71 | return {
|
72 | run() {
|
73 | $$.fakeConnectionRequest = fakeFunction;
|
74 | },
|
75 | };
|
76 | };
|
77 | const withProject = (SfProjectJson) => {
|
78 | return {
|
79 | run() {
|
80 |
|
81 |
|
82 | const projPathStub = core_2.SfProject.resolveProjectPath;
|
83 | if (projPathStub.restore) {
|
84 | projPathStub.restore();
|
85 | }
|
86 | $$.SANDBOX.stub(core_2.SfProject, 'resolveProjectPath').callsFake((path) => {
|
87 | return $$.localPathRetriever(path || $$.id);
|
88 | });
|
89 | const DEFAULT_PROJECT_JSON = {
|
90 | sfdcLoginUrl: 'https://login.salesforce.com',
|
91 | };
|
92 | $$.configStubs.SfProjectJson = {
|
93 | contents: Object.assign({}, DEFAULT_PROJECT_JSON, SfProjectJson),
|
94 | };
|
95 | },
|
96 | };
|
97 | };
|
98 | const test = oclifTest.test
|
99 | .register('withOrg', withOrg)
|
100 | .register('withConnectionRequest', withConnectionRequest)
|
101 | .register('withProject', withProject);
|
102 | exports.test = test;
|
103 | exports.default = test;
|
104 |
|
\ | No newline at end of file |