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