Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
fix: fix fancy test types and stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Mar 21, 2022
1 parent e7c2e45 commit 507fb91
Showing 1 changed file with 20 additions and 39 deletions.
59 changes: 20 additions & 39 deletions src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ import { command, Config, expect, FancyTypes } from '@oclif/test';
import { Config as OclifConfig } from '@oclif/core';
import { AuthFields, SfProject } from '@salesforce/core';
import { TestContext, testSetup } from '@salesforce/core/lib/testSetup';
import {
AnyJson,
asJsonMap,
definiteValuesOf,
Dictionary,
ensure,
ensureString,
JsonMap,
Optional,
} from '@salesforce/ts-types';
import { AnyJson, asJsonMap, definiteValuesOf, Dictionary, ensure, JsonMap, Optional } from '@salesforce/ts-types';

import { loadConfig } from '@oclif/test/lib/load-config';
import { SinonStub } from 'sinon';
Expand All @@ -44,44 +35,34 @@ const withOrg = (org: Partial<AuthFields> = {}, setAsDefault = true): Plugin<Dic
if (!org.username) {
org.username = '[email protected]';
}
ctx.orgs[org.username] = {};

// Override org if it exists on context
ctx.orgs[org.username] = Object.assign(
{
orgId: '0x012123',
instanceUrl: 'http://na30.salesforce.com',
loginUrl: 'https://login.salesforce.com',
created: '1519163543003',
isDevHub: false,
},
org
);

ctx.orgs[org.username].default = setAsDefault;
ctx.orgs[org.username].orgs = {
[org.username]: Object.assign(
{
orgId: '0x012123',
instanceUrl: 'http://na30.salesforce.com',
loginUrl: 'https://login.salesforce.com',
created: '1519163543003',
isDevHub: false,
default: setAsDefault,
},
org
),
};

// eslint-disable-next-line @typescript-eslint/require-await
const readOrg = async function (this: { path: string }): Promise<JsonMap> {
const path = this.path;
return asJsonMap(
find(ctx.orgs, (val) => {
return path.includes(ensureString(val.username));
}),
{}
);
return asJsonMap(ctx.orgs[org.username as string], {});
};
// eslint-disable-next-line @typescript-eslint/require-await
const writeOrg = async function (this: { path: string }): Promise<JsonMap> {
const path = this.path;
const foundOrg = asJsonMap(
find(ctx.orgs, (val) => {
return path.includes(ensureString(val.username));
}),
{}
);
return (ensure($$.configStubs.AuthInfoConfig).contents = foundOrg);
const foundOrg = asJsonMap(ctx.orgs[org.username as string], {});
return (ensure($$.configStubs.GlobalInfo).contents = { orgs: { [org.username as string]: foundOrg } });
};

$$.configStubs.AuthInfoConfig = {
$$.configStubs.GlobalInfo = {
retrieveContents: readOrg,
updateContents: writeOrg,
};
Expand Down Expand Up @@ -129,7 +110,7 @@ const withProject = (SfProjectJson?: JsonMap): Plugin<unknown> => {
};
};

const test: typeof oclifTest.test = oclifTest.test
const test = oclifTest.test
.register('withOrg', withOrg)
.register('withConnectionRequest', withConnectionRequest)
.register('withProject', withProject);
Expand Down

0 comments on commit 507fb91

Please sign in to comment.