Skip to content

Commit

Permalink
fix: use default options off the constructor
Browse files Browse the repository at this point in the history
also update all the incorrect docs for AsyncCreatable
  • Loading branch information
amphro committed Feb 8, 2019
1 parent 3cafa64 commit 368a5f1
Show file tree
Hide file tree
Showing 19 changed files with 693 additions and 337 deletions.
14 changes: 4 additions & 10 deletions examples/examples/aliasEditor/aliasEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function run() {

const orgs = authFiles.map(authfile => authfile.replace('.json', ''));
const orgsWithAliases = {};
const aliases = await Aliases.create();
const aliases = await Aliases.create({});

// Map the aliases onto the orgs
for (const org of orgs) {
Expand All @@ -19,9 +19,7 @@ export async function run() {
}

// Buffer length for displaying to the user
const len =
(_.max(_.map(_.values(orgsWithAliases), element => element || 0)) as string)
.length + 4;
const len = (_.max(_.map(_.values(orgsWithAliases), element => element || 0)) as string).length + 4;

// Have the user select a user to add or remove alias
const answer = await select(
Expand All @@ -43,9 +41,7 @@ export async function run() {
const [alias, username] = strip(answer).split(/\s*: /);

// Enter a new alias
const { newAlias } = await inquirer.prompt([
{ name: 'newAlias', message: 'Enter a new alias (empty to remove):' }
]);
const { newAlias } = await inquirer.prompt([{ name: 'newAlias', message: 'Enter a new alias (empty to remove):' }]);

if (alias !== 'N/A') {
// Remove the old one
Expand All @@ -55,9 +51,7 @@ export async function run() {

if (newAlias) {
aliases.set(newAlias, username);
console.log(
`Set alias ${chalk.green(newAlias)} to username ${chalk.green(username)}`
);
console.log(`Set alias ${chalk.green(newAlias)} to username ${chalk.green(username)}`);
}
await aliases.write();
}
Expand Down
28 changes: 6 additions & 22 deletions examples/examples/apexLogStream/apexLogStream.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
import {
AuthInfo,
DefaultStreamingOptions,
Org,
StatusResult,
StreamingClient,
StreamingOptions
} from '@salesforce/core';
import { AuthInfo, Org, StatusResult, StreamingClient } from '@salesforce/core';
import { JsonMap } from '@salesforce/ts-types';
import chalk from 'chalk';
import * as inquirer from 'inquirer';

let org: Org;

export async function run() {
function streamProcessor(message: JsonMap): StatusResult<string> {
console.log(
chalk.blue('Apex Log Found:'),
chalk.green(message.sobject['Id'])
);
console.log(
org
.getConnection()
.request(`/sobjects/ApexLog/${message.sobject['Id']}/Body`)
);
function streamProcessor(message: JsonMap): StatusResult {
console.log(chalk.blue('Apex Log Found:'), chalk.green(message.sobject['Id']));
console.log(org.getConnection().request(`/sobjects/ApexLog/${message.sobject['Id']}/Body`));
// Listen forever to get all the logs until the stream timesout
return { completed: false };
}

async function startStream(username) {
org = await Org.create(username);
const options: StreamingOptions<string> = new DefaultStreamingOptions(
const options: StreamingClient.Options = new StreamingClient.DefaultOptions(
org,
'/systemTopic/Logging',
streamProcessor
);

const asyncStatusClient: StreamingClient<
string
> = await StreamingClient.init(options);
const asyncStatusClient = await StreamingClient.create(options);

await asyncStatusClient.handshake();
console.log('Handshaked!');
Expand Down
6 changes: 2 additions & 4 deletions examples/examples/apiExplorer/apiExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function run() {

// Connect to the user
const authInfo = await AuthInfo.create(connectionOrg);
const connection = await Connection.create(authInfo);
const connection = await Connection.create({ authInfo });

console.log('Connected!\n');

Expand All @@ -28,9 +28,7 @@ export async function run() {
// noinspection InfiniteLoopJS
while (true) {
try {
response = await connection.request(
await select('Select endpoint', options)
);
response = await connection.request(await select('Select endpoint', options));
console.log('\n', chalk.green(JSON.stringify(response, null, 4)), '\n');

// Only change the options if they are urls
Expand Down
6 changes: 6 additions & 0 deletions examples/examples/test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--require ts-node/register
--require source-map-support/register
--watch-extensions ts
--recursive
--reporter spec
--timeout 5000
8 changes: 5 additions & 3 deletions examples/examples/test/unit/MockAuthInfoTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { strictEqual } from 'assert';
import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
import { AuthInfo } from '@salesforce/core';
import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
import { strictEqual } from 'assert';

const $$ = testSetup();

Expand All @@ -10,7 +10,9 @@ describe('Mocking Auth data', () => {
$$.setConfigStubContents('AuthInfoConfig', {
contents: await testData.getConfig()
});
const auth: AuthInfo = await AuthInfo.create(testData.username);
const auth: AuthInfo = await AuthInfo.create({
username: testData.username
});
strictEqual(auth.getUsername(), testData.username);
});
});
8 changes: 5 additions & 3 deletions examples/examples/test/unit/MockConnectionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ describe('Mocking an SFDX connection', () => {
$$.setConfigStubContents('AuthInfoConfig', {
contents: await testData.getConfig()
});
const connection: Connection = await Connection.create(
await AuthInfo.create(testData.username)
);
const connection: Connection = await Connection.create({
authInfo: await AuthInfo.create({
username: testData.username
})
});
strictEqual(connection.accessToken, testData.accessToken);
});
});
14 changes: 5 additions & 9 deletions examples/examples/test/unit/MockServerRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ describe('Mocking a force server call', () => {
if (request && ensureString(_request.url).includes('Account')) {
return Promise.resolve(records);
} else {
return Promise.reject(
new SfdxError(`Unexpected request: ${_request.url}`)
);
return Promise.reject(new SfdxError(`Unexpected request: ${_request.url}`));
}
};
const connection: Connection = await Connection.create(
await AuthInfo.create(testData.username)
);
const result: QueryResult<{}> = await connection.query(
'select Id From Account'
);
const connection: Connection = await Connection.create({
authInfo: await AuthInfo.create({ username: testData.username })
});
const result: QueryResult<{}> = await connection.query('select Id From Account');
deepStrictEqual(result, records);
});
});
2 changes: 1 addition & 1 deletion examples/examples/test/unit/TestSandbox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { strictEqual } from 'assert';
import { testSetup } from '@salesforce/core/lib/testSetup';
import { stubMethod } from '@salesforce/ts-sinon';
import { strictEqual } from 'assert';
import * as os from 'os';

const $$ = testSetup();
Expand Down
14 changes: 8 additions & 6 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
"description": "Examples using the SFDX Core libraries to interact with SFDX projects, orgs, and APIs.",
"main": "index.js",
"license": "BSD-3-Clause",
"scripts": {},
"scripts": {
"test": "mocha examples/test/unit/** --opts examples/test/mocha.opts"
},
"keywords": [
"sfdx",
"sfdx-core",
"Salesforce DX",
"Salesforce CLI"
],
"dependencies": {
"@salesforce/core": "^0.23.3",
"@salesforce/core": "^1",
"chalk": "^2.4.1",
"inquirer": "^6.0.0",
"lodash": "^4.17.10",
"strip-ansi": "^4.0.0",
"@salesforce/ts-types": "0.14.0"
"strip-ansi": "^4.0.0"
},
"devDependencies": {
"@salesforce/dev-config": "^1.1.2",
"@salesforce/ts-sinon": "^0.2.2",
"@salesforce/ts-types": "^1",
"@salesforce/dev-config": "^1.4.4",
"@salesforce/ts-sinon": "^1",
"@types/lodash": "^4.14.104",
"@types/node": "^9.4.7",
"@types/mocha": "^5.2.5",
Expand Down
Loading

0 comments on commit 368a5f1

Please sign in to comment.