Skip to content

Commit

Permalink
Sm/test branch (#69)
Browse files Browse the repository at this point in the history
* test: nuts on circle

* test: orb, take 2

* chore: bump core version to get password fix

* test: remove call-count checks (core changed)

* chore: bump core version lockfile

* test: bump orb to re-test 2

* test: iterator to re-run circle

* test: run nuts on windows

* test: restore linux nut label

* test: re-run to try new windows job

* test: add windows as os parameter

* test: remove parameters

* test: verify orb runs without windows

* test: nut try 5

* test: nuts without windows

* test: nut with windows

* chore: bump prettier for windows EOL

* test: yarn install 2x for dev-scripts

* chore: bump dev-scripts

* chore: bump prettier AFTER dev-scripts

* chore: bump mocha

* test: windows-friendly paths

* chore: bump setPassword to feature

* test: are homeDir unique?

* test: run only one nut (windows home test)

* chore: bump testkit for windows fix

* chore: reinstall node modules

* test: resume skipped tests (check windows parallel)

* test: saving artifacts

* test: save zip to artifacts relative

* test: windows debugging artifacts

* test: also debug linux for comparison

* test: nut version, debug

* test: no env in config

* test: test windows path fix in nut

* test: artifacts folder in home

* test: remove os import

* test: revert to artifacts (linux only)

* test: with setupCommands

* test: try/catch on the zip

* test: remove unused import

* test: comit to cause a run after PR

* test: depend on env to control zips

* test: change to trigger run

* chore: bumps lockfile

* test: environment in job?

* test: no env in job

* test: with env set on linux

* test: clean up

* test: don't require nuts on publish job

* refactor: typing on NUTs

* test: use published orb with nuts

* test: add version

* test: rerun circle with orb nuts
  • Loading branch information
mshanemc authored Mar 8, 2021
1 parent 515146a commit b9a7dc9
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 317 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
version: 2.1

orbs:
release-management: salesforce/npm-release-management@4

workflows:
version: 2
test-and-release:
Expand All @@ -14,6 +16,17 @@ workflows:
node_version: latest
- release-management/test-package:
name: node-12
- release-management/test-nut:
name: nuts-on-linux
sfdx_version: latest
requires:
- node-latest
- release-management/test-nut:
name: nuts-on-windows
sfdx_version: latest
os: windows
requires:
- node-latest
- release-management/release-package:
sign: true
github-release: true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@oclif/config": "^1.17.0",
"@salesforce/command": "^3.1.0",
"@salesforce/core": "^2.18.6",
"@salesforce/core": "^2.20.0",
"tslib": "^2"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions src/commands/force/user/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getString } from '@salesforce/ts-types';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-user', 'display');

type Result = {
export type UserDisplayResult = {
username: string;
profileName: string;
id: string;
Expand All @@ -32,7 +32,7 @@ export class UserDisplayCommand extends SfdxCommand {
public static readonly requiresDevhubUsername = true;
public logger: Logger;

public async run(): Promise<Result> {
public async run(): Promise<UserDisplayResult> {
this.logger = await Logger.child(this.constructor.name);
if (sfdc.matchesAccessToken(this.flags.targetusername)) {
throw new SfdxError(messages.getMessage('accessTokenError'), 'accessTokenError', [
Expand Down Expand Up @@ -75,7 +75,7 @@ export class UserDisplayCommand extends SfdxCommand {
);
}

const result: Result = {
const result: UserDisplayResult = {
accessToken: conn.accessToken,
id: userId,
instanceUrl: userAuthData.instanceUrl,
Expand Down Expand Up @@ -103,7 +103,7 @@ export class UserDisplayCommand extends SfdxCommand {
return result;
}

private print(result: Result): void {
private print(result: UserDisplayResult): void {
const columns = {
columns: [
{ key: 'key', label: 'key' },
Expand Down
84 changes: 49 additions & 35 deletions test/allCommands.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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 * as path from 'path';
import { use, expect } from 'chai';
import * as chaiEach from 'chai-each';

Expand All @@ -12,6 +13,7 @@ import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
import { PermsetAssignResult } from '../src/commands/force/user/permset/assign';
import { AuthList } from '../src/commands/force/user/list';
import { UserCreateOutput } from '../src/commands/force/user/create';
import { UserDisplayResult } from '../src/commands/force/user/display';

use(chaiEach);
let session: TestSession;
Expand All @@ -20,38 +22,48 @@ describe('verifies all commands run successfully ', () => {
before(() => {
session = TestSession.create({
project: {
sourceDir: 'test/df17AppBuilding',
sourceDir: path.join('test', 'df17AppBuilding'),
},
// create org and push source to get a permset
setupCommands: ['sfdx force:org:create -d 1 -s -f config/project-scratch-def.json', 'sfdx force:source:push'],
setupCommands: [
`sfdx force:org:create -d 1 -s -f ${path.join('config', 'project-scratch-def.json')}`,
'sfdx force:source:push',
],
});
});

it('user display', () => {
const output = execCmd('force:user:display --json', { ensureExitCode: 0 });
expect(output.jsonOutput)
.to.have.property('result')
.with.all.keys(['username', 'accessToken', 'id', 'orgId', 'profileName', 'loginUrl', 'instanceUrl']);
const result = (output.jsonOutput as Record<string, unknown>).result as Record<string, string>;
expect(result.orgId).to.have.length(18);
expect(result.id).to.have.length(18);
expect(result.accessToken.startsWith(result.orgId.substr(0, 15))).to.be.true;
const output = execCmd<UserDisplayResult>('force:user:display --json', { ensureExitCode: 0 }).jsonOutput;
expect(output.result).to.have.all.keys([
'username',
'accessToken',
'id',
'orgId',
'profileName',
'loginUrl',
'instanceUrl',
]);

expect(output.result.orgId).to.have.length(18);
expect(output.result.id).to.have.length(18);
expect(output.result.accessToken.startsWith(output.result.orgId.substr(0, 15))).to.be.true;
});

it('assigns a permset to the default user', () => {
const output = execCmd('force:user:permset:assign -n VolunteeringApp --json', { ensureExitCode: 0 });
expect(output.jsonOutput).to.have.property('result').with.all.keys(['successes', 'failures']);
const result = (output.jsonOutput as Record<string, unknown>).result as PermsetAssignResult;
expect(result.successes).to.have.length(1);
expect(result.successes[0]).to.have.all.keys(['name', 'value']);
expect(result.failures).to.have.length(0);
const output = execCmd<PermsetAssignResult>('force:user:permset:assign -n VolunteeringApp --json', {
ensureExitCode: 0,
}).jsonOutput;
expect(output.result).to.have.all.keys(['successes', 'failures']);
expect(output.result.successes).to.have.length(1);
expect(output.result.successes[0]).to.have.all.keys(['name', 'value']);
expect(output.result.failures).to.have.length(0);
});

it('creates a secondary user', () => {
const output = execCmd('force:user:create --json -a Other', { ensureExitCode: 0 });
expect(output.jsonOutput).to.have.property('result').with.all.keys(['orgId', 'permissionSetAssignments', 'fields']);
const result = (output.jsonOutput as Record<string, unknown>).result as UserCreateOutput;
expect(result.fields).to.have.all.keys(
const output = execCmd<UserCreateOutput>('force:user:create --json -a Other', { ensureExitCode: 0 }).jsonOutput;

expect(output.result).to.have.all.keys(['orgId', 'permissionSetAssignments', 'fields']);
expect(output.result.fields).to.have.all.keys(
'id',
'username',
'alias', // because it's set in the command
Expand All @@ -66,20 +78,21 @@ describe('verifies all commands run successfully ', () => {
});

it('assigns permset to the secondary user', () => {
const output = execCmd('force:user:permset:assign -n VolunteeringApp --json --onbehalfof Other', {
ensureExitCode: 0,
});
expect(output.jsonOutput).to.have.property('result').with.all.keys(['successes', 'failures']);
const result = (output.jsonOutput as Record<string, unknown>).result as PermsetAssignResult;
expect(result.successes).to.have.length(1);
expect(result.successes[0]).to.have.all.keys(['name', 'value']);
expect(result.failures).to.have.length(0);
const output = execCmd<PermsetAssignResult>(
'force:user:permset:assign -n VolunteeringApp --json --onbehalfof Other',
{
ensureExitCode: 0,
}
).jsonOutput;
expect(output.result).to.have.all.keys(['successes', 'failures']);
expect(output.result.successes).to.have.length(1);
expect(output.result.successes[0]).to.have.all.keys(['name', 'value']);
expect(output.result.failures).to.have.length(0);
});

it('lists the users', () => {
const output = execCmd('force:user:list --json', { ensureExitCode: 0 });
expect(output.jsonOutput).to.have.property('result').to.be.an('array').with.length(2);
const result = (output.jsonOutput as Record<string, unknown>).result as AuthList[];
const result = execCmd<AuthList[]>('force:user:list --json', { ensureExitCode: 0 }).jsonOutput.result;
expect(result).to.be.an('array').with.length(2);
expect(result).each.have.all.keys([
'defaultMarker',
'alias',
Expand All @@ -94,16 +107,17 @@ describe('verifies all commands run successfully ', () => {
});

it('generates new passwords for main user', () => {
const output = execCmd('force:user:password:generate --json', { ensureExitCode: 0 });
expect(output.jsonOutput).to.have.property('result').includes.keys(['username', 'password']);
const output = execCmd('force:user:password:generate --json', { ensureExitCode: 0 }).jsonOutput;
expect(output).to.have.property('result').includes.keys(['username', 'password']);
});

it('generates new password for secondary user (onbehalfof)', () => {
const output = execCmd('force:user:password:generate -o Other --json', { ensureExitCode: 0 });
expect(output.jsonOutput).to.have.property('result').includes.keys(['username', 'password']);
const output = execCmd('force:user:password:generate -o Other --json', { ensureExitCode: 0 }).jsonOutput;
expect(output).to.have.property('result').includes.keys(['username', 'password']);
});

after(async () => {
await session.zip(undefined, 'artifacts');
await session.clean();
});
});
10 changes: 8 additions & 2 deletions test/allCommandsNoJSON.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* 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 * as path from 'path';

import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';

// const projectPath = 'testProject_AllUserCommandsNoJSON';
Expand All @@ -14,10 +16,13 @@ describe('verifies all commands run successfully (no json)', () => {
session = TestSession.create({
project: {
// destinationDir: projectPath,
sourceDir: 'test/df17AppBuilding',
sourceDir: path.join('test', 'df17AppBuilding'),
},
// create org and push source to get a permset
setupCommands: ['sfdx force:org:create -d 1 -s -f config/project-scratch-def.json', 'sfdx force:source:push'],
setupCommands: [
`sfdx force:org:create -d 1 -s -f ${path.join('config', 'project-scratch-def.json')}`,
'sfdx force:source:push',
],
});
});

Expand Down Expand Up @@ -52,6 +57,7 @@ describe('verifies all commands run successfully (no json)', () => {
});

after(async () => {
await session.zip(undefined, 'artifacts');
await session.clean();
});
});
28 changes: 19 additions & 9 deletions test/commands/user/create.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* 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 { expect } from 'chai';

import * as path from 'path';
import { expect } from 'chai';
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
import { env } from '@salesforce/kit';
import { UserCreateOutput } from '../../../src/commands/force/user/create';

let session: TestSession;

describe('creates a user from a file and verifies', () => {
Expand All @@ -17,20 +19,27 @@ describe('creates a user from a file and verifies', () => {
before(() => {
session = TestSession.create({
project: {
sourceDir: 'test/df17AppBuilding',
sourceDir: path.join('test', 'df17AppBuilding'),
},
// create org and push source to get a permset
setupCommands: ['sfdx force:org:create -d 1 -s -f config/project-scratch-def.json', 'sfdx force:source:push'],
setupCommands: [
`sfdx force:org:create -d 1 -s -f ${path.join('config', 'project-scratch-def.json')}`,
'sfdx force:source:push',
],
});
});

it('creates a secondary user with password and permsets assigned', () => {
const output = execCmd('force:user:create --json -a Other -f config/complexUser.json', { ensureExitCode: 0 });
expect(output.jsonOutput).to.have.property('result').with.all.keys(['orgId', 'permissionSetAssignments', 'fields']);
const result = (output.jsonOutput as Record<string, unknown>).result as UserCreateOutput;
expect(result.permissionSetAssignments).to.deep.equal(['VolunteeringApp']);
// const fileContents = fs.readJsonSync('config/complexUser.json', true);
createdUserId = result.fields.id as string;
const output = execCmd<UserCreateOutput>(
`force:user:create --json -a Other -f ${path.join('config', 'complexUser.json')}`,
{
ensureExitCode: 0,
}
).jsonOutput;
// expect(output.jsonOutput).to.have.property('result').with.all.keys(['orgId', 'permissionSetAssignments', 'fields']);
expect(output.result).to.have.all.keys(['orgId', 'permissionSetAssignments', 'fields']);
expect(output.result.permissionSetAssignments).to.deep.equal(['VolunteeringApp']);
createdUserId = output.result.fields.id as string;
});

it('verifies the permission set assignment in the org', () => {
Expand All @@ -48,6 +57,7 @@ describe('creates a user from a file and verifies', () => {
});

after(async () => {
await session.zip(undefined, 'artifacts');
await session.clean();
});
});
10 changes: 1 addition & 9 deletions test/commands/user/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import UserCreateCommand from '../../../src/commands/force/user/create';
const username = '[email protected]';

describe('force:user:create', () => {
let authInfoStub;
it('will properly merge fields regardless of capitalization', async () => {
// notice the varied capitalization
stubMethod($$.SANDBOX, fs, 'readJson').resolves({
Expand Down Expand Up @@ -87,7 +86,7 @@ describe('force:user:create', () => {
stubMethod($$.SANDBOX, User.prototype, 'assignPermissionSets').resolves();
stubMethod($$.SANDBOX, Org.prototype, 'getUsername').returns(username);
stubMethod($$.SANDBOX, Org.prototype, 'getOrgId').returns('abc123');
authInfoStub = stubMethod($$.SANDBOX, AuthInfo.prototype, 'save').resolves();
stubMethod($$.SANDBOX, AuthInfo.prototype, 'save').resolves();

if (throws.license) {
stubMethod($$.SANDBOX, User.prototype, 'createUser').throws(new Error('LICENSE_LIMIT_EXCEEDED'));
Expand Down Expand Up @@ -144,7 +143,6 @@ describe('force:user:create', () => {
};
const result = JSON.parse(ctx.stdout).result;
expect(result).to.deep.equal(expected);
expect(authInfoStub.callCount).to.be.equal(2);
});

test
Expand Down Expand Up @@ -184,7 +182,6 @@ describe('force:user:create', () => {
};
const result = JSON.parse(ctx.stdout).result;
expect(result).to.deep.equal(expected);
expect(authInfoStub.callCount).to.be.equal(1);
});

test
Expand Down Expand Up @@ -219,7 +216,6 @@ describe('force:user:create', () => {
};
const result = JSON.parse(ctx.stdout).result;
expect(result).to.deep.equal(expected);
expect(authInfoStub.callCount).to.be.equal(0);
});

test
Expand Down Expand Up @@ -260,7 +256,6 @@ describe('force:user:create', () => {
};
const result = JSON.parse(ctx.stdout).result;
expect(result).to.deep.equal(expected);
expect(authInfoStub.callCount).to.be.equal(0);
});

test
Expand Down Expand Up @@ -307,7 +302,6 @@ describe('force:user:create', () => {
};
const result = JSON.parse(ctx.stdout).result;
expect(result).to.deep.equal(expected);
expect(authInfoStub.callCount).to.be.equal(1);
}
);

Expand All @@ -329,7 +323,6 @@ describe('force:user:create', () => {
expect(result.status).to.equal(1);
expect(result.message).to.equal('There are no available user licenses for the user profile "testName".');
expect(result.name).to.equal('licenseLimitExceeded');
expect(authInfoStub.callCount).to.be.equal(0);
});

test
Expand All @@ -349,7 +342,6 @@ describe('force:user:create', () => {
const result = JSON.parse(ctx.stdout);
expect(result.status).to.equal(1);
expect(result.name).to.equal('duplicateUsername');
expect(authInfoStub.callCount).to.be.equal(0);
expect(result.message).to.equal(
'The username "[email protected]" already exists in this or another Salesforce org. Usernames must be unique across all Salesforce orgs.'
);
Expand Down
10 changes: 3 additions & 7 deletions test/df17AppBuilding/config/project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
{
"orgName": "workshops",
"orgName": "nutPluginUser",
"adminEmail": "[email protected]",
"edition": "Developer",
"description": "app building workshop",
"description": "nuts for plugin-user",
"features": ["EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
},
"securitySettings": {
"passwordPolicies": {
"enableSetPasswordInApi": true
}
}
}
}
Loading

0 comments on commit b9a7dc9

Please sign in to comment.