From 1bc473fc36ff70edbb1145b1c2f3ae6e0a4331ee Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 22 Dec 2020 15:53:02 -0600 Subject: [PATCH 01/12] fix: prevent DNS ENOTFOUND from hitting stdout --- src/connection.ts | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/connection.ts b/src/connection.ts index 744ac3ac95..0f7d59fce2 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -4,7 +4,7 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ - +import { URL } from 'url'; import { maxBy, merge } from '@salesforce/kit'; import { asString, ensure, getNumber, isString, JsonCollection, JsonMap, Optional } from '@salesforce/ts-types'; import { @@ -16,7 +16,10 @@ import { RequestInfo, Tooling as JSForceTooling, } from 'jsforce'; +import { Duration } from '@salesforce/kit'; import { AuthFields, AuthInfo } from './authInfo'; +import { MyDomainResolver } from './status/myDomainResolver'; + import { ConfigAggregator } from './config/configAggregator'; import { Logger } from './logger'; import { SfdxError } from './sfdxError'; @@ -119,8 +122,12 @@ export class Connection extends JSForceConnection { const conn = new this(options); await conn.init(); - if (!versionFromConfig) { - await conn.useLatestApiVersion(); + if (!versionFromConfig && conn.options?.connectionOptions?.instanceUrl) { + try { + await conn.useLatestApiVersion(); + } catch (e) { + conn.logger.error(`Cannot connect to the org at ${conn.options?.connectionOptions?.instanceUrl}`); + } } return conn; } @@ -178,11 +185,28 @@ export class Connection extends JSForceConnection { * Retrieves the highest api version that is supported by the target server instance. */ public async retrieveMaxApiVersion(): Promise { - type Versioned = { version: string }; - const versions = (await this.request(`${this.instanceUrl}/services/data`)) as Versioned[]; - this.logger.debug(`response for org versions: ${versions}`); - const max = ensure(maxBy(versions, (version: Versioned) => version.version)); - return max.version; + // errors go to stdout from within jsforce (maybe even further down the stack) if org's url doesn't exist. (not a 404 from the domain but a DNS ENOTFOUND) + // We need to verify that the org can be connected to BEFORE asking about it's api version. This will throw on DNS errors + if (!this.options.connectionOptions?.instanceUrl) { + throw new Error('Connection has no instanceUrl'); + } + const resolver = await MyDomainResolver.create({ + url: new URL(this.options.connectionOptions.instanceUrl), + timeout: Duration.minutes(0), + }); + const ipAddress = await resolver.resolve(); + + if (ipAddress) { + type Versioned = { version: string }; + const versions = (await this.request( + `${this.options.connectionOptions.instanceUrl}/services/data` + )) as Versioned[]; + this.logger.debug(`response for org versions: ${versions}`); + const max = ensure(maxBy(versions, (version: Versioned) => version.version)); + return max.version; + } + + throw new Error(); } /** * Use the latest API version available on `this.instanceUrl`. From cd8ea5b4ba56f9ace54646e17789b67c6c7419cb Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 22 Dec 2020 15:56:08 -0600 Subject: [PATCH 02/12] test: adjust tests where instanceUrl is required for dns check --- test/unit/connectionTest.ts | 30 +++++++++++++++++++++++++----- test/unit/orgTest.ts | 6 ++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/test/unit/connectionTest.ts b/test/unit/connectionTest.ts index 9db998b507..a3de8413e5 100644 --- a/test/unit/connectionTest.ts +++ b/test/unit/connectionTest.ts @@ -9,12 +9,15 @@ import { get, JsonMap } from '@salesforce/ts-types'; import { assert, expect } from 'chai'; import * as jsforce from 'jsforce'; import { AuthInfo } from '../../src/authInfo'; +import { MyDomainResolver } from '../../src/status/myDomainResolver'; + import { ConfigAggregator, ConfigInfo } from '../../src/config/configAggregator'; import { Connection, SFDX_HTTP_HEADERS } from '../../src/connection'; import { testSetup } from '../../src/testSetup'; // Setup the test environment. const $$ = testSetup(); +const TEST_IP = '1.1.1.1'; describe('Connection', () => { const testConnectionOptions = { loginUrl: 'connectionTest/loginUrl' }; @@ -27,9 +30,19 @@ describe('Connection', () => { getConnectionOptions: () => testConnectionOptions, }; + const testAuthInfoWithDomain = { + ...testAuthInfo, + getConnectionOptions: () => ({ + ...testConnectionOptions, + instanceUrl: 'https://connectionTest/instanceUrl', + }), + }; + beforeEach(() => { $$.SANDBOXES.CONNECTION.restore(); $$.SANDBOX.stub(process, 'emitWarning'); + $$.SANDBOX.stub(MyDomainResolver.prototype, 'resolve').resolves(TEST_IP); + initializeStub = $$.SANDBOX.stub(jsforce.Connection.prototype, 'initialize').returns(); requestMock = $$.SANDBOX.stub(jsforce.Connection.prototype, 'request') .onFirstCall() @@ -73,8 +86,9 @@ describe('Connection', () => { headers: SFDX_HTTP_HEADERS, }; - const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); - + const conn = await Connection.create({ + authInfo: testAuthInfoWithDomain as AuthInfo, + }); // Test passing a string to conn.request() const response1 = await conn.request(testUrl); expect(requestMock.called).to.be.true; @@ -88,7 +102,9 @@ describe('Connection', () => { requestMock.onSecondCall().returns(Promise.resolve(testResponse)); const testUrl = 'connectionTest/request/url/describe'; - const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); + const conn = await Connection.create({ + authInfo: testAuthInfoWithDomain as AuthInfo, + }); // Test passing a RequestInfo object and options to conn.request() const requestInfo = { method: 'POST', url: testUrl }; @@ -107,7 +123,9 @@ describe('Connection', () => { const testResponse = { success: true }; requestMock.onSecondCall().returns(Promise.resolve(testResponse)); - const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); + const conn = await Connection.create({ + authInfo: testAuthInfoWithDomain as AuthInfo, + }); const testUrl = '/services/data/v42.0/tooling/sobjects'; const requestInfo = { method: 'GET', url: testUrl }; @@ -197,7 +215,9 @@ describe('Connection', () => { it('autoFetch() should reject the promise upon query error', async () => { const errorMsg = 'QueryFailed'; requestMock.onSecondCall().throws(new Error(errorMsg)); - const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); + const conn = await Connection.create({ + authInfo: testAuthInfoWithDomain as AuthInfo, + }); try { await conn.autoFetchQuery('TEST_SOQL'); diff --git a/test/unit/orgTest.ts b/test/unit/orgTest.ts index 60f09efe1d..09673305ef 100644 --- a/test/unit/orgTest.ts +++ b/test/unit/orgTest.ts @@ -27,6 +27,7 @@ import { Global } from '../../src/global'; import { Org } from '../../src/org'; import { MockTestOrgData, testSetup } from '../../src/testSetup'; import { fs } from '../../src/util/fs'; +import { MyDomainResolver } from '../../src/status/myDomainResolver'; const $$ = testSetup(); @@ -38,6 +39,8 @@ describe('Org Tests', () => { beforeEach(async () => { testData = new MockTestOrgData(); $$.configStubs.AuthInfoConfig = { contents: await testData.getConfig() }; + $$.SANDBOX.stub(MyDomainResolver.prototype, 'resolve').resolves('1.1.1.1'); + stubMethod($$.SANDBOX, Connection.prototype, 'useLatestApiVersion').returns(Promise.resolve()); }); @@ -122,6 +125,9 @@ describe('Org Tests', () => { const org: Org = await Org.create({ connection: await Connection.create({ authInfo: await AuthInfo.create({ username: testData.username }), + connectionOptions: { + instanceUrl: 'https://orgTest.instanceUrl', + }, }), }); const apiVersion = await org.retrieveMaxApiVersion(); From 20c897739d077a15945701843fac9c2c3457dff4 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 29 Dec 2020 17:15:14 -0600 Subject: [PATCH 03/12] fix: better error messaging and Steve feedback --- src/connection.ts | 69 ++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/connection.ts b/src/connection.ts index 0f7d59fce2..a9ed1db8a5 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -5,7 +5,7 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import { URL } from 'url'; -import { maxBy, merge } from '@salesforce/kit'; +import { Duration, maxBy, merge } from '@salesforce/kit'; import { asString, ensure, getNumber, isString, JsonCollection, JsonMap, Optional } from '@salesforce/ts-types'; import { Connection as JSForceConnection, @@ -16,7 +16,6 @@ import { RequestInfo, Tooling as JSForceTooling, } from 'jsforce'; -import { Duration } from '@salesforce/kit'; import { AuthFields, AuthInfo } from './authInfo'; import { MyDomainResolver } from './status/myDomainResolver'; @@ -122,12 +121,10 @@ export class Connection extends JSForceConnection { const conn = new this(options); await conn.init(); - if (!versionFromConfig && conn.options?.connectionOptions?.instanceUrl) { - try { - await conn.useLatestApiVersion(); - } catch (e) { - conn.logger.error(`Cannot connect to the org at ${conn.options?.connectionOptions?.instanceUrl}`); - } + // verifies that subsequent requests to org will not hit DNS errors + + if (!versionFromConfig) { + await conn.useLatestApiVersion(); } return conn; } @@ -185,28 +182,12 @@ export class Connection extends JSForceConnection { * Retrieves the highest api version that is supported by the target server instance. */ public async retrieveMaxApiVersion(): Promise { - // errors go to stdout from within jsforce (maybe even further down the stack) if org's url doesn't exist. (not a 404 from the domain but a DNS ENOTFOUND) - // We need to verify that the org can be connected to BEFORE asking about it's api version. This will throw on DNS errors - if (!this.options.connectionOptions?.instanceUrl) { - throw new Error('Connection has no instanceUrl'); - } - const resolver = await MyDomainResolver.create({ - url: new URL(this.options.connectionOptions.instanceUrl), - timeout: Duration.minutes(0), - }); - const ipAddress = await resolver.resolve(); - - if (ipAddress) { - type Versioned = { version: string }; - const versions = (await this.request( - `${this.options.connectionOptions.instanceUrl}/services/data` - )) as Versioned[]; - this.logger.debug(`response for org versions: ${versions}`); - const max = ensure(maxBy(versions, (version: Versioned) => version.version)); - return max.version; - } - - throw new Error(); + await this.isResolvable(); + type Versioned = { version: string }; + const versions = (await this.request(`${this.instanceUrl}/services/data`)) as Versioned[]; + this.logger.debug(`response for org versions: ${versions}`); + const max = ensure(maxBy(versions, (version: Versioned) => version.version)); + return max.version; } /** * Use the latest API version available on `this.instanceUrl`. @@ -215,11 +196,39 @@ export class Connection extends JSForceConnection { try { this.setApiVersion(await this.retrieveMaxApiVersion()); } catch (err) { + if (err.name === 'Org Not Found') { + throw err; // throws on DNS connection errors + } // Don't fail if we can't use the latest, just use the default this.logger.warn('Failed to set the latest API version:', err); } } + /** + * Verify that instance has a reachable DNS entry, otherwise will throw error + */ + public async isResolvable(): Promise { + if (!this.options.connectionOptions?.instanceUrl) { + throw new SfdxError('Connection has no instanceUrl', 'NoInstanceUrl', [ + 'Make sure the instanceUrl is set in your command or config', + ]); + } + const resolver = await MyDomainResolver.create({ + url: new URL(this.options.connectionOptions.instanceUrl), + timeout: Duration.seconds(10), + frequency: Duration.seconds(10), + }); + try { + await resolver.resolve(); + return true; + } catch (e) { + throw new SfdxError('The org cannot be found', 'Org Not Found', [ + 'Verify that the org still exists', + 'If your org is newly created, wait a minute and run your command again', + ]); + } + } + /** * Get the API version used for all connection requests. */ From 89c497c106a58de00ccdf880c122acfcf2b3ec5f Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 29 Dec 2020 17:48:56 -0600 Subject: [PATCH 04/12] test: simulate DNS fail --- test/unit/connectionTest.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/unit/connectionTest.ts b/test/unit/connectionTest.ts index a3de8413e5..a8466d60d4 100644 --- a/test/unit/connectionTest.ts +++ b/test/unit/connectionTest.ts @@ -13,7 +13,7 @@ import { MyDomainResolver } from '../../src/status/myDomainResolver'; import { ConfigAggregator, ConfigInfo } from '../../src/config/configAggregator'; import { Connection, SFDX_HTTP_HEADERS } from '../../src/connection'; -import { testSetup } from '../../src/testSetup'; +import { testSetup, shouldThrow } from '../../src/testSetup'; // Setup the test environment. const $$ = testSetup(); @@ -49,6 +49,17 @@ describe('Connection', () => { .returns(Promise.resolve([{ version: '42.0' }])); }); + it('create() should throw on DNS errors', async () => { + $$.SANDBOX.restore(); + $$.SANDBOX.stub(MyDomainResolver.prototype, 'resolve').rejects({ name: 'Org Not Found' }); + + try { + await shouldThrow(Connection.create({ authInfo: testAuthInfoWithDomain as AuthInfo })); + } catch (e) { + expect(e).to.have.property('name', 'Org Not Found'); + } + }); + it('create() should create a connection using AuthInfo and SFDX options', async () => { const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); From 92ced7e7de418c4dc36af6d12be930adcf801706 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 29 Dec 2020 17:49:23 -0600 Subject: [PATCH 05/12] fix: error name as a constant --- src/connection.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/connection.ts b/src/connection.ts index a9ed1db8a5..74dd5d5ebf 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -38,6 +38,8 @@ export const SFDX_HTTP_HEADERS = { 'user-agent': clientId, }; +const ORG_NOT_FOUND_ERROR_NAME = 'Org Not Found'; + // This interface is so we can add the autoFetchQuery method to both the Connection // and Tooling classes and get nice typing info for it within editors. JSForce is // unlikely to accept a PR for this method, but that would be another approach. @@ -196,7 +198,7 @@ export class Connection extends JSForceConnection { try { this.setApiVersion(await this.retrieveMaxApiVersion()); } catch (err) { - if (err.name === 'Org Not Found') { + if (err.name === ORG_NOT_FOUND_ERROR_NAME) { throw err; // throws on DNS connection errors } // Don't fail if we can't use the latest, just use the default @@ -222,7 +224,7 @@ export class Connection extends JSForceConnection { await resolver.resolve(); return true; } catch (e) { - throw new SfdxError('The org cannot be found', 'Org Not Found', [ + throw new SfdxError('The org cannot be found', ORG_NOT_FOUND_ERROR_NAME, [ 'Verify that the org still exists', 'If your org is newly created, wait a minute and run your command again', ]); From 43cac980bba0bf276a28cd7d90b4bc3656cacd3b Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 30 Dec 2020 08:47:13 -0600 Subject: [PATCH 06/12] fix: better error name --- src/connection.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/connection.ts b/src/connection.ts index 74dd5d5ebf..a75dafec83 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -38,7 +38,7 @@ export const SFDX_HTTP_HEADERS = { 'user-agent': clientId, }; -const ORG_NOT_FOUND_ERROR_NAME = 'Org Not Found'; +const ORG_NOT_FOUND_ERROR_NAME = 'Domain Not Found'; // This interface is so we can add the autoFetchQuery method to both the Connection // and Tooling classes and get nice typing info for it within editors. JSForce is @@ -227,6 +227,7 @@ export class Connection extends JSForceConnection { throw new SfdxError('The org cannot be found', ORG_NOT_FOUND_ERROR_NAME, [ 'Verify that the org still exists', 'If your org is newly created, wait a minute and run your command again', + "If you deployed or updated the org's My Domain, update your instanceUrl", ]); } } From fda9ce0a802917cbcf496dc03450182f3ec5f79a Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 30 Dec 2020 09:05:15 -0600 Subject: [PATCH 07/12] fix: export name for testing --- src/connection.ts | 6 +++--- test/unit/connectionTest.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/connection.ts b/src/connection.ts index a75dafec83..e22f606cc6 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -38,7 +38,7 @@ export const SFDX_HTTP_HEADERS = { 'user-agent': clientId, }; -const ORG_NOT_FOUND_ERROR_NAME = 'Domain Not Found'; +export const DNS_ERROR_NAME = 'Domain Not Found'; // This interface is so we can add the autoFetchQuery method to both the Connection // and Tooling classes and get nice typing info for it within editors. JSForce is @@ -198,7 +198,7 @@ export class Connection extends JSForceConnection { try { this.setApiVersion(await this.retrieveMaxApiVersion()); } catch (err) { - if (err.name === ORG_NOT_FOUND_ERROR_NAME) { + if (err.name === DNS_ERROR_NAME) { throw err; // throws on DNS connection errors } // Don't fail if we can't use the latest, just use the default @@ -224,7 +224,7 @@ export class Connection extends JSForceConnection { await resolver.resolve(); return true; } catch (e) { - throw new SfdxError('The org cannot be found', ORG_NOT_FOUND_ERROR_NAME, [ + throw new SfdxError('The org cannot be found', DNS_ERROR_NAME, [ 'Verify that the org still exists', 'If your org is newly created, wait a minute and run your command again', "If you deployed or updated the org's My Domain, update your instanceUrl", diff --git a/test/unit/connectionTest.ts b/test/unit/connectionTest.ts index a8466d60d4..dcdb74cbe6 100644 --- a/test/unit/connectionTest.ts +++ b/test/unit/connectionTest.ts @@ -12,7 +12,7 @@ import { AuthInfo } from '../../src/authInfo'; import { MyDomainResolver } from '../../src/status/myDomainResolver'; import { ConfigAggregator, ConfigInfo } from '../../src/config/configAggregator'; -import { Connection, SFDX_HTTP_HEADERS } from '../../src/connection'; +import { Connection, SFDX_HTTP_HEADERS, DNS_ERROR_NAME } from '../../src/connection'; import { testSetup, shouldThrow } from '../../src/testSetup'; // Setup the test environment. @@ -51,12 +51,12 @@ describe('Connection', () => { it('create() should throw on DNS errors', async () => { $$.SANDBOX.restore(); - $$.SANDBOX.stub(MyDomainResolver.prototype, 'resolve').rejects({ name: 'Org Not Found' }); + $$.SANDBOX.stub(MyDomainResolver.prototype, 'resolve').rejects({ name: DNS_ERROR_NAME }); try { await shouldThrow(Connection.create({ authInfo: testAuthInfoWithDomain as AuthInfo })); } catch (e) { - expect(e).to.have.property('name', 'Org Not Found'); + expect(e).to.have.property('name', DNS_ERROR_NAME); } }); From 837f8526090268a7134d7b30657009af384aed05 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 30 Dec 2020 17:22:15 -0600 Subject: [PATCH 08/12] docs: myDomain changes from Peter's feedback --- src/connection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection.ts b/src/connection.ts index e22f606cc6..4f053c600b 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -227,7 +227,7 @@ export class Connection extends JSForceConnection { throw new SfdxError('The org cannot be found', DNS_ERROR_NAME, [ 'Verify that the org still exists', 'If your org is newly created, wait a minute and run your command again', - "If you deployed or updated the org's My Domain, update your instanceUrl", + "If you deployed or updated the org's My Domain, logout from the CLI and authenticate again", ]); } } From 89e4dc7d46e7b3b553329c7eb125caa75015dce1 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 5 Jan 2021 08:10:17 -0600 Subject: [PATCH 09/12] fix: line spacing --- test/unit/connectionTest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/connectionTest.ts b/test/unit/connectionTest.ts index dcdb74cbe6..e28c01ccb9 100644 --- a/test/unit/connectionTest.ts +++ b/test/unit/connectionTest.ts @@ -10,7 +10,6 @@ import { assert, expect } from 'chai'; import * as jsforce from 'jsforce'; import { AuthInfo } from '../../src/authInfo'; import { MyDomainResolver } from '../../src/status/myDomainResolver'; - import { ConfigAggregator, ConfigInfo } from '../../src/config/configAggregator'; import { Connection, SFDX_HTTP_HEADERS, DNS_ERROR_NAME } from '../../src/connection'; import { testSetup, shouldThrow } from '../../src/testSetup'; From d82fe3e8a41c177bd905ee3278332db375dc9761 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 5 Jan 2021 10:56:26 -0600 Subject: [PATCH 10/12] fix: log versions as string --- src/connection.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/connection.ts b/src/connection.ts index 4f053c600b..dcc2b5b967 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -187,8 +187,9 @@ export class Connection extends JSForceConnection { await this.isResolvable(); type Versioned = { version: string }; const versions = (await this.request(`${this.instanceUrl}/services/data`)) as Versioned[]; - this.logger.debug(`response for org versions: ${versions}`); + this.logger.debug(`response for org versions: ${versions.map((item) => item.version).join(',')}`); const max = ensure(maxBy(versions, (version: Versioned) => version.version)); + return max.version; } /** From e1dc134ef17b2e93f0347b9fdc0d66efe9b5dae7 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 13 Jan 2021 14:33:48 -0600 Subject: [PATCH 11/12] style: semicolon linter --- test/unit/connectionTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/connectionTest.ts b/test/unit/connectionTest.ts index b432504c48..6c671490f0 100644 --- a/test/unit/connectionTest.ts +++ b/test/unit/connectionTest.ts @@ -12,7 +12,7 @@ import { AuthInfo } from '../../src/authInfo'; import { MyDomainResolver } from '../../src/status/myDomainResolver'; import { ConfigAggregator, ConfigInfo } from '../../src/config/configAggregator'; import { Connection, SFDX_HTTP_HEADERS, DNS_ERROR_NAME, SingleRecordQueryErrors } from '../../src/connection'; -import { testSetup, shouldThrow } from '../../src/testSetup' +import { testSetup, shouldThrow } from '../../src/testSetup'; // Setup the test environment. const $$ = testSetup(); From 794c99b2689c291483c9157b7d21988ac48c8f47 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 13 Jan 2021 15:43:32 -0600 Subject: [PATCH 12/12] test: add domain to authinfo --- test/unit/connectionTest.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/unit/connectionTest.ts b/test/unit/connectionTest.ts index 6c671490f0..fee948d9e3 100644 --- a/test/unit/connectionTest.ts +++ b/test/unit/connectionTest.ts @@ -45,7 +45,7 @@ describe('Connection', () => { initializeStub = $$.SANDBOX.stub(jsforce.Connection.prototype, 'initialize').returns(); requestMock = $$.SANDBOX.stub(jsforce.Connection.prototype, 'request') .onFirstCall() - .returns(Promise.resolve([{ version: '42.0' }])); + .resolves([{ version: '42.0' }]); }); it('create() should throw on DNS errors', async () => { @@ -242,10 +242,11 @@ describe('Connection', () => { id: '123', name: 'testName', }; - requestMock.returns(Promise.resolve({ totalSize: 1, records: [mockSingleRecord] })); const soql = 'TEST_SOQL'; + requestMock.onSecondCall().resolves({ totalSize: 1, records: [mockSingleRecord] }); + + const conn = await Connection.create({ authInfo: testAuthInfoWithDomain as AuthInfo }); - const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); const queryResult = await conn.singleRecordQuery(soql); expect(queryResult).to.deep.equal({ ...mockSingleRecord, @@ -254,7 +255,7 @@ describe('Connection', () => { it('singleRecordQuery throws on no-records', async () => { requestMock.returns(Promise.resolve({ totalSize: 0, records: [] })); - const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); + const conn = await Connection.create({ authInfo: testAuthInfoWithDomain as AuthInfo }); try { await conn.singleRecordQuery('TEST_SOQL'); @@ -266,7 +267,7 @@ describe('Connection', () => { it('singleRecordQuery throws on multiple records', async () => { requestMock.returns(Promise.resolve({ totalSize: 2, records: [{ id: 1 }, { id: 2 }] })); - const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); + const conn = await Connection.create({ authInfo: testAuthInfoWithDomain as AuthInfo }); try { await conn.singleRecordQuery('TEST_SOQL'); @@ -278,7 +279,7 @@ describe('Connection', () => { it('singleRecordQuery throws on multiple records with options', async () => { requestMock.returns(Promise.resolve({ totalSize: 2, records: [{ id: 1 }, { id: 2 }] })); - const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); + const conn = await Connection.create({ authInfo: testAuthInfoWithDomain as AuthInfo }); try { await conn.singleRecordQuery('TEST_SOQL', { returnChoicesOnMultiple: true, choiceField: 'id' }); @@ -297,7 +298,7 @@ describe('Connection', () => { requestMock.returns(Promise.resolve({ totalSize: 1, records: [mockSingleRecord] })); const soql = 'TEST_SOQL'; - const conn = await Connection.create({ authInfo: testAuthInfo as AuthInfo }); + const conn = await Connection.create({ authInfo: testAuthInfoWithDomain as AuthInfo }); const toolingQuerySpy = $$.SANDBOX.spy(conn.tooling, 'query'); const queryResults = await conn.singleRecordQuery(soql, { tooling: true }); expect(queryResults).to.deep.equal({