Skip to content

Commit

Permalink
fix: updated various logic and QOL on User and PermissionSetAssignment
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Nov 11, 2020
1 parent 52be813 commit 1bab28f
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 306 deletions.
4 changes: 2 additions & 2 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class Connection extends JSForceConnection {
// We want to use 1 logger for this class and the jsForce base classes so override
// the jsForce connection.tooling.logger and connection.logger.
private logger!: Logger;
private transport!: { httpRequest: (info: RequestInfo) => JsonMap };
private _transport!: { httpRequest: (info: RequestInfo) => JsonMap };
private _normalizeUrl!: (url: string) => string;
private options: Connection.Options;

Expand Down Expand Up @@ -158,7 +158,7 @@ export class Connection extends JSForceConnection {

merge(headers, SFDX_HTTP_HEADERS, request.headers);

return this.transport.httpRequest({
return this._transport.httpRequest({
method: request.method,
url: request.url,
headers,
Expand Down
2 changes: 2 additions & 0 deletions src/exported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export { MyDomainResolver } from './status/myDomainResolver';

export { DefaultUserFields, REQUIRED_FIELDS, User, UserFields } from './user';

export { PermissionSetAssignment, PermissionSetAssignmentFields } from './permissionSetAssignment';

// Utility sub-modules
export * from './util/fs';
export * from './util/sfdc';
2 changes: 1 addition & 1 deletion src/permissionSetAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class PermissionSetAssignment {
.sobject('PermissionSetAssignment')
.create(mapKeys(assignment, (value: unknown, key: string) => upperFirst(key)));

if (hasArray(createResponse, 'errors')) {
if (hasArray(createResponse, 'errors') && createResponse.errors.length > 0) {
const messages: Messages = Messages.loadMessages('@salesforce/core', 'permissionSetAssignment');
let message = messages.getMessage('errorsEncounteredCreatingAssignment');

Expand Down
7 changes: 4 additions & 3 deletions src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { SecureBuffer } from './secureBuffer';
import { SfdxError } from './sfdxError';
import { sfdc } from './util/sfdc';

const PASSWORD_LENGTH = 10;
const PASSWORD_LENGTH = 13;
const LOWER = 'abcdefghijklmnopqrstuvwxyz';
const UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const NUMBERS = '1234567890';
Expand Down Expand Up @@ -404,6 +404,7 @@ export class User extends AsyncCreatable<User.Options> {
if (!fields) {
throw SfdxError.create('@salesforce/core', 'user', 'missingFields');
}
const conn: Connection = this.org.getConnection();

const body = JSON.stringify({
username: fields.username,
Expand All @@ -421,7 +422,7 @@ export class User extends AsyncCreatable<User.Options> {

this.logger.debug(`user create request body: ${body}`);

const scimUrl = this.org.getConnection().normalizeUrl(scimEndpoint);
const scimUrl = conn.normalizeUrl(scimEndpoint);
this.logger.debug(`scimUrl: ${scimUrl}`);

const info: RequestInfo = {
Expand All @@ -431,7 +432,7 @@ export class User extends AsyncCreatable<User.Options> {
body,
};

const response = await this.org.getConnection().requestRaw(info);
const response = await conn.requestRaw(info);
const responseBody = parseJsonMap(ensureString(response['body']));
const statusCode = asNumber(response.statusCode);

Expand Down
2 changes: 1 addition & 1 deletion test/unit/permissionSetAssignmentTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('permission set assignment tests', () => {
try {
await shouldThrow(assignment.create('123456', `${NS}__${PERM_SET_NAME}`));
} catch (e) {
expect(e).to.have.property('name', 'notSuccessfulButNoErrorsReported');
expect(e).to.have.property('name', 'UnexpectedResult');
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/userTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('User Tests', () => {
it('Should generate a password', () => {
const password: SecureBuffer<void> = User.generatePasswordUtf8();
password.value((buffer: Buffer): void => {
expect(buffer.toString('utf8').length).to.be.equal(6);
expect(buffer.toString('utf8').length).to.be.equal(9);
});
});
});
Expand Down
Loading

0 comments on commit 1bab28f

Please sign in to comment.