Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deployRecentValidation #389

Merged
merged 6 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"postcompile": "tsc -p test; tsc -p typedocExamples",
"prepack": "sf-build",
"pretest": "sf-compile-test",
"test": "sf-test --require ts-node/register"
"test": "sf-test"
},
"keywords": [
"force",
Expand Down
32 changes: 32 additions & 0 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const SFDX_HTTP_HEADERS = {
};

export const DNS_ERROR_NAME = 'Domain Not Found';
type recentValidationOptions = { id: string; rest?: boolean };

// 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
Expand Down Expand Up @@ -210,6 +211,37 @@ export class Connection extends JSForceConnection {
return super._baseUrl();
}

/**
* TODO: This should be moved into JSForce V2 once ready
* this is only a temporary solution to support both REST and SOAP APIs
*
* Will deploy a recently validated deploy request
*
* @param options.id = the deploy ID that's been validated already from a previous checkOnly deploy request
* @param options.rest = a boolean whether or not to use the REST API
*/
public async deployRecentValidation(options: recentValidationOptions): Promise<JsonCollection> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know anything about this code base but it seems strange to me that this method would be inside connection.ts and the Connection class. Is this something all connections will need/use?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It belongs in JSForce but we aren't going to put it there until we move over to v2. These will be removed in the v2 of core that uses v2 of jsforce. @WillieRuemmele can you put comments on these methods you are adding saying that, and that it is just to add the rest option for existing soap operations in jsforce.

if (options.rest) {
const url = `${this.baseUrl()}/metadata/deployRequest`;
const messageBody = JSON.stringify({
validatedDeployRequestId: options.id,
});
const requestInfo = {
method: 'POST',
url,
body: messageBody,
};
const requestOptions = { headers: 'json' };
return this.request(requestInfo, requestOptions);
} else {
// the _invoke is private in jsforce, we can call the SOAP deployRecentValidation like this
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
return this.metadata['_invoke']('deployRecentValidation', {
validationId: options.id,
}) as JsonCollection;
}
}
/**
* Retrieves the highest api version that is supported by the target server instance.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/keyChainImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class KeychainAccess implements PasswordStore {
}

// eslint-disable-next-line @typescript-eslint/no-misused-promises
credManager.on('close', async (code) => {
credManager.on('close', async (code: number) => {
try {
return await this.osImpl.onGetCommandClose(code, stdout, stderr, opts, fn);
} catch (e) {
Expand Down
22 changes: 22 additions & 0 deletions test/unit/connectionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,28 @@ describe('Connection', () => {
}
});

describe('deployRecentValidation', () => {
it('deployRecentValidation() should call request directly for REST', async () => {
const conn = await Connection.create({ authInfo: fromStub(testAuthInfo) });
conn.instanceUrl = 'myNewInstance@salesforce.com';
const requestStub = $$.SANDBOX.stub(conn, 'request');

await conn.deployRecentValidation({ id: '0Afxx00000000lWCAQ', rest: true });
expect(requestStub.callCount).to.equal(1);
});

it('deployRecentValidation() should call jsforce for SOAP', async () => {
const conn = await Connection.create({ authInfo: fromStub(testAuthInfo) });
conn.instanceUrl = 'myNewInstance@salesforce.com';
// @ts-ignore private method
const requestStub = $$.SANDBOX.stub(conn.metadata, '_invoke');

await conn.deployRecentValidation({ id: '0Afxx00000000lWCAQ' });
expect(requestStub.callCount).to.equal(1);
expect(requestStub.args[0][0]).to.equal('deployRecentValidation');
});
});

it('singleRecordQuery returns single-record result properly', async () => {
const mockSingleRecord = {
id: '123',
Expand Down