generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpackageVersionCreateManaged.nut.ts
More file actions
136 lines (117 loc) · 5.12 KB
/
packageVersionCreateManaged.nut.ts
File metadata and controls
136 lines (117 loc) · 5.12 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Copyright 2026, 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 * as fs from 'node:fs';
import * as path from 'node:path';
import { expect } from 'chai';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { Org, SfProject } from '@salesforce/core';
import { Duration } from '@salesforce/kit';
import { PackageVersionCreateRequestResult } from '@salesforce/packaging';
import { FileDownloadEntry } from '../../../src/commands/package/version/retrieve.js';
let packageName: string;
let devHubOrg: Org;
describe('package:version:create with managed package (--generate-pkg-zip)', () => {
let session: TestSession;
let managedPackageId: string;
before('setup managed package', async function () {
// TODO: Remove once 260 is released to instance the CI dev hub is running on
this.skip();
this.timeout(Duration.minutes(5).milliseconds);
session = await TestSession.create({
devhubAuthStrategy: 'AUTO',
project: { name: 'managed-pkg-test' },
});
devHubOrg = await Org.create({ aliasOrUsername: session.hubOrg.username });
// Query for existing managed package
const existingPkgQuery = `
SELECT Id, Name, NamespacePrefix
FROM Package2
WHERE ContainerOptions = 'Managed'
AND IsDeprecated = false
AND Name = 'pnhmanaged'
LIMIT 1
`;
const existingPkgRecords = (
await devHubOrg
.getConnection()
.tooling.query<{ Id: string; Name: string; NamespacePrefix: string }>(existingPkgQuery)
).records;
managedPackageId = existingPkgRecords[0].Id;
// Create minimal source structure for a custom object
const objectName = 'TestObject__c';
const objectDir = path.join(session.project.dir, 'force-app', 'main', 'default', 'objects', objectName);
fs.mkdirSync(objectDir, { recursive: true });
fs.writeFileSync(
path.join(objectDir, `${objectName}.object-meta.xml`),
`<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<deploymentStatus>Deployed</deploymentStatus>
<label>Test Object</label>
<nameField>
<label>Test Object Name</label>
<type>Text</type>
</nameField>
<pluralLabel>Test Objects</pluralLabel>
<sharingModel>ReadWrite</sharingModel>
</CustomObject>`
);
// Configure the project for the managed package
const project = await SfProject.resolve(session.project.dir);
const projectJson = project.getSfProjectJson();
const namespacePrefix = existingPkgRecords[0].NamespacePrefix;
packageName = existingPkgRecords[0].Name;
const packageDirectory = {
path: 'force-app',
package: existingPkgRecords[0].Name,
versionNumber: '1.0.0.NEXT',
ancestorVersion: 'NONE',
versionName: 'v1',
default: true,
};
projectJson.set('packageDirectories', [packageDirectory]);
projectJson.set('packageAliases', { [packageName]: managedPackageId });
projectJson.set('namespace', namespacePrefix);
projectJson.writeSync();
});
after(async () => {
await session?.clean();
});
it('should create a managed package version with --generate-pkg-zip flag and retrieve the metadata', async function () {
this.timeout(Duration.minutes(25).milliseconds);
const createResult = execCmd<PackageVersionCreateRequestResult>(
`package:version:create --package ${packageName} --wait 20 -x --generate-pkg-zip --version-description "Test pkg zip" --json --skip-ancestor-check`,
{ ensureExitCode: 0, timeout: Duration.minutes(20).milliseconds }
).jsonOutput?.result;
// Debug: verify the flag was actually set
const pvcRequestId = createResult?.Id;
const verifyQuery = `SELECT Id, IsDevUsePkgZipRequested FROM Package2VersionCreateRequest WHERE Id = '${pvcRequestId}'`;
const verifyResult = await devHubOrg
.getConnection()
.tooling.query<{ Id: string; IsDevUsePkgZipRequested: boolean }>(verifyQuery);
// eslint-disable-next-line no-console
console.log('IsDevUsePkgZipRequested:', verifyResult.records[0]?.IsDevUsePkgZipRequested);
expect(createResult?.Status).to.equal('Success');
const subscriberPkgVersionId = createResult?.SubscriberPackageVersionId;
expect(subscriberPkgVersionId).to.match(/04t.{15}/);
const retrieveOutputDir = 'pkg-zip-test-output';
const retrieveResult = execCmd<FileDownloadEntry[]>(
`package:version:retrieve --package ${subscriberPkgVersionId} --output-dir ${retrieveOutputDir} --json`,
{ ensureExitCode: 0 }
).jsonOutput?.result;
expect(retrieveResult).to.be.an('array');
expect(retrieveResult?.length).to.be.greaterThan(0);
});
});