Skip to content

Commit

Permalink
fix: handle missing createdOrgInstance field
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Jan 11, 2024
1 parent befa9d2 commit 99315fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/commands/org/create/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { EOL } from 'node:os';
import fs from 'node:fs';


import {
AuthInfo,
Connection,
Expand All @@ -34,7 +33,7 @@ import {
} from '@salesforce/sf-plugins-core';
import { Interfaces } from '@oclif/core';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-user', 'create');

type SuccessMsg = {
Expand Down Expand Up @@ -320,7 +319,7 @@ const getValidatedConnection = async (targetOrg: Org, apiVersion?: string): Prom
if (
conn.getAuthInfo().isJwt() &&
// hyperforce sandbox instances end in S like USA254S
targetOrg.getField<string>(Org.Fields.CREATED_ORG_INSTANCE).endsWith('S')
targetOrg.getField<string>(Org.Fields.CREATED_ORG_INSTANCE)?.endsWith('S')
) {
throw messages.createError('error.jwtHyperforce');
}
Expand Down
30 changes: 29 additions & 1 deletion test/commands/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const username = '[email protected]';
const originalUserId = '0052D0000043PawWWR';
const newUserId = '0052D0000044PawWWR';

const createdOrgInstanceMissing = 'MISSING';

describe('org:create:user', () => {
const $$ = new TestContext();

Expand Down Expand Up @@ -121,7 +123,9 @@ describe('org:create:user', () => {
$$.SANDBOX.stub(Org.prototype, 'getOrgId').returns(testOrg.orgId);
$$.SANDBOX.stub(Org.prototype, 'getField')
.withArgs(Org.Fields.CREATED_ORG_INSTANCE)
.returns(throws.createdOrgInstance ?? testOrg.orgId);
.returns(
throws.createdOrgInstance === createdOrgInstanceMissing ? undefined : throws.createdOrgInstance ?? testOrg.orgId
);
$$.SANDBOX.stub(Org.prototype, 'determineIfScratch').resolves(throws.nonScratch ? false : true);

if (throws.license) {
Expand Down Expand Up @@ -351,6 +355,30 @@ describe('org:create:user', () => {
const result = await createCommand.run();
expect(result).to.deep.equal(expected);
});

it('works if JWT but missing createdOrgInstance auth field', async () => {
await prepareStubs({ isJWT: true, createdOrgInstance: createdOrgInstanceMissing }, true);
const expected = {
orgId: testOrg.orgId,
permissionSetAssignments: [],
fields: {
alias: 'testAlias',
email: username,
emailencodingkey: 'UTF-8',
id: newUserId,
languagelocalekey: 'en_US',
lastname: 'User',
localesidkey: 'en_US',
profileid: '12345678',
profilename: 'profileFromArgs',
timezonesidkey: 'America/Los_Angeles',
username: '[email protected]',
},
};
const createCommand = new CreateUserCommand(['--json', '--target-org', testOrg.username], {} as Config);
const result = await createCommand.run();
expect(result).to.deep.equal(expected);
});
});

describe('exceptions', () => {
Expand Down

0 comments on commit 99315fa

Please sign in to comment.