-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcreate.nut.ts
More file actions
103 lines (95 loc) · 4.22 KB
/
create.nut.ts
File metadata and controls
103 lines (95 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright 2025, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { join } from 'node:path';
import { expect } from 'chai';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { AuthInfo, Connection } from '@salesforce/core';
import { CreateUserOutput } from '../../src/commands/org/create/user.js';
import { AuthList } from '../../src/commands/org/list/users.js';
let session: TestSession;
describe('creates a user from a file and verifies', () => {
let createdUserId: string;
before(async () => {
session = await TestSession.create({
project: {
sourceDir: join('test', 'df17AppBuilding'),
},
devhubAuthStrategy: 'AUTO',
scratchOrgs: [
{
setDefault: true,
config: join('config', 'project-scratch-def.json'),
tracksSource: false,
},
],
});
execCmd('project:deploy:start', { ensureExitCode: 0, cli: 'sf' });
});
it('creates a user with set-unique-username from username on commandline', () => {
const testUsername = 'test@test.test';
const output = execCmd<CreateUserOutput>(
`org:create:user --json --set-unique-username username=${testUsername} profileName="Chatter Free User"`,
{
ensureExitCode: 0,
}
).jsonOutput;
expect(output?.result).to.have.all.keys(['orgId', 'permissionSetAssignments', 'fields']);
const usernameResult = output?.result.fields.username as string;
expect(usernameResult.startsWith(testUsername)).to.be.true;
// ends with . followed by the prefix for orgId (lowercased!) and 15 more lowercase characters or digits
expect(usernameResult).matches(/.*\.00d[a-z|\d]{15}$/);
});
it('creates a user with set-unique-username without username on commandline', () => {
const output = execCmd<CreateUserOutput>(
`org:create:user --json -f ${join('config', 'fileWithUsername.json')} --set-unique-username`,
{
ensureExitCode: 0,
}
).jsonOutput;
expect(output?.result).to.have.all.keys(['orgId', 'permissionSetAssignments', 'fields']);
const usernameResult = output?.result.fields.username as string;
expect(usernameResult).matches(/not\.unique@test\.test\.00d[a-z|\d]{15}$/);
});
it('creates a secondary user with password and permsets assigned', () => {
const output = execCmd<CreateUserOutput>(
`org:create:user --json -a Other -f ${join('config', 'complexUser.json')}`,
{ ensureExitCode: 0 }
).jsonOutput;
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', async () => {
const connection = await Connection.create({
authInfo: await AuthInfo.create({ username: session.orgs.get('default')?.username }),
});
const queryResult = await connection.query<{ Id: string; PermissionSet: { Name: string } }>(
`select PermissionSet.Name from PermissionSetAssignment where AssigneeId = '${createdUserId}'`
);
// there will also be a profile in there, too, with a cryptic name on it
expect(queryResult.records.some((assignment) => assignment.PermissionSet.Name === 'VolunteeringApp'));
});
it('verifies the new user appears in list of users for the org', () => {
const output = execCmd<AuthList[]>(`org:list:users --json -u ${session.orgs.get('default')?.username}`, {
ensureExitCode: 0,
}).jsonOutput;
expect(output?.result.find((user) => user.userId === createdUserId)).to.be.ok;
});
after(async () => {
await session.zip(undefined, 'artifacts');
await session.clean();
});
});