UNPKG

4.11 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/*
4 * Copyright (c) 2018, salesforce.com, inc.
5 * All rights reserved.
6 * SPDX-License-Identifier: BSD-3-Clause
7 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8 */
9const oclifTest = require("@oclif/test");
10const test_1 = require("@oclif/test");
11exports.command = test_1.command;
12exports.Config = test_1.Config;
13exports.expect = test_1.expect;
14exports.FancyTypes = test_1.FancyTypes;
15const core_1 = require("@salesforce/core");
16const testSetup_1 = require("@salesforce/core/lib/testSetup");
17const ts_types_1 = require("@salesforce/ts-types");
18// Need to prevent typescript error
19const IConfig = require("@oclif/config/lib/config");
20exports.IConfig = IConfig;
21const load_config_1 = require("@oclif/test/lib/load-config");
22exports.loadConfig = load_config_1.loadConfig;
23load_config_1.loadConfig.root = ts_types_1.ensure(module.parent).filename;
24const $$ = testSetup_1.testSetup();
25exports.$$ = $$;
26const withOrg = (org = {}, setAsDefault = true) => {
27 return {
28 // tslint:disable-next-line:no-any TODO: properly type the dictionary
29 run(ctx) {
30 if (!ctx.orgs) {
31 ctx.orgs = {};
32 }
33 if (!org.username) {
34 org.username = 'test@org.com';
35 }
36 // Override org if it exists on context
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};
74function find(orgs, predicate) {
75 return ts_types_1.definiteValuesOf(orgs).filter(predicate)[0];
76}
77const withConnectionRequest = (fakeFunction) => {
78 return {
79 run(ctx) {
80 $$.fakeConnectionRequest = fakeFunction;
81 }
82 };
83};
84const 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};
99const test = oclifTest.test
100 .register('withOrg', withOrg)
101 .register('withConnectionRequest', withConnectionRequest)
102 .register('withProject', withProject);
103exports.test = test;
104exports.default = test;
105//# sourceMappingURL=index.js.map
\No newline at end of file