UNPKG

4.76 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.$$ = exports.test = exports.OclifConfig = exports.loadConfig = exports.command = exports.Config = exports.FancyTypes = exports.expect = void 0;
4const oclifTest = require("@oclif/test");
5const test_1 = require("@oclif/test");
6Object.defineProperty(exports, "command", { enumerable: true, get: function () { return test_1.command; } });
7Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return test_1.Config; } });
8Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_1.expect; } });
9Object.defineProperty(exports, "FancyTypes", { enumerable: true, get: function () { return test_1.FancyTypes; } });
10const core_1 = require("@oclif/core");
11Object.defineProperty(exports, "OclifConfig", { enumerable: true, get: function () { return core_1.Config; } });
12const core_2 = require("@salesforce/core");
13const testSetup_1 = require("@salesforce/core/lib/testSetup");
14const ts_types_1 = require("@salesforce/ts-types");
15const load_config_1 = require("@oclif/test/lib/load-config");
16Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return load_config_1.loadConfig; } });
17load_config_1.loadConfig.root = (0, ts_types_1.ensure)(module.parent).filename;
18const $$ = (0, testSetup_1.testSetup)();
19exports.$$ = $$;
20function find(orgs, predicate) {
21 return (0, ts_types_1.definiteValuesOf)(orgs).filter(predicate)[0];
22}
23const withOrg = (org = {}, setAsDefault = true) => {
24 return {
25 // TODO: properly type the dictionary
26 // eslint-disable-next-line @typescript-eslint/no-explicit-any
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 // Override org if it exists on context
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 // eslint-disable-next-line @typescript-eslint/require-await
47 const readOrg = async function () {
48 return (0, ts_types_1.asJsonMap)(ctx.orgs[org.username], {});
49 };
50 // eslint-disable-next-line @typescript-eslint/require-await
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};
70const withConnectionRequest = (fakeFunction) => {
71 return {
72 run() {
73 $$.fakeConnectionRequest = fakeFunction;
74 },
75 };
76};
77const withProject = (SfProjectJson) => {
78 return {
79 run() {
80 // Restore first if already stubbed by $$.inProject()
81 /* eslint-disable-next-line @typescript-eslint/unbound-method */
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};
98const test = oclifTest.test
99 .register('withOrg', withOrg)
100 .register('withConnectionRequest', withConnectionRequest)
101 .register('withProject', withProject);
102exports.test = test;
103exports.default = test;
104//# sourceMappingURL=index.js.map
\No newline at end of file