Skip to content

Commit 0dffaa1

Browse files
committed
fix: update listBundles test to use new API signature and fix lint errors
- Update push.test.ts to use the new listBundles({projectSlug}, auth) signature - Change import style in download.ts to use named imports per eslint rules
1 parent fcfcea5 commit 0dffaa1

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

packages/b2c-cli/src/commands/mrt/bundle/download.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* SPDX-License-Identifier: Apache-2
44
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
55
*/
6-
import * as fs from 'node:fs';
7-
import * as path from 'node:path';
6+
import {createWriteStream, mkdirSync} from 'node:fs';
7+
import {dirname, resolve} from 'node:path';
88
import {pipeline} from 'node:stream/promises';
99
import {Args, Flags} from '@oclif/core';
1010
import {MrtCommand} from '@salesforce/b2c-tooling-sdk/cli';
@@ -92,7 +92,7 @@ export default class MrtBundleDownload extends MrtCommand<typeof MrtBundleDownlo
9292

9393
// Download the file
9494
const outputPath = this.flags.output ?? `bundle-${bundleId}.tgz`;
95-
const absolutePath = path.resolve(outputPath);
95+
const absolutePath = resolve(outputPath);
9696

9797
this.log(
9898
t('commands.mrt.bundle.download.downloading', 'Downloading bundle {{bundleId}} to {{filePath}}...', {
@@ -115,13 +115,13 @@ export default class MrtBundleDownload extends MrtCommand<typeof MrtBundleDownlo
115115
}
116116

117117
// Ensure directory exists
118-
const dir = path.dirname(absolutePath);
118+
const dir = dirname(absolutePath);
119119
if (dir !== '.') {
120-
fs.mkdirSync(dir, {recursive: true});
120+
mkdirSync(dir, {recursive: true});
121121
}
122122

123123
// Stream the response to file
124-
const fileStream = fs.createWriteStream(absolutePath);
124+
const fileStream = createWriteStream(absolutePath);
125125
await pipeline(response.body, fileStream);
126126

127127
if (!this.jsonEnabled()) {

packages/b2c-tooling-sdk/test/operations/mrt/push.test.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ describe('operations/mrt/push', () => {
174174
);
175175

176176
const auth = new MockAuthStrategy();
177-
const client = createMrtClient({}, auth);
178177

179-
const bundles = await listBundles(client, 'my-project');
178+
const result = await listBundles({projectSlug: 'my-project'}, auth);
180179

181-
expect(bundles).to.have.length(2);
182-
expect(bundles[0]).to.deep.include({id: 123, message: 'Bundle 1'});
183-
expect(bundles[1]).to.deep.include({id: 124, message: 'Bundle 2'});
180+
expect(result.bundles).to.have.length(2);
181+
expect(result.bundles[0]).to.deep.include({id: 123, message: 'Bundle 1'});
182+
expect(result.bundles[1]).to.deep.include({id: 124, message: 'Bundle 2'});
183+
expect(result.count).to.equal(2);
184184
});
185185

186186
it('passes pagination options', async () => {
@@ -189,14 +189,13 @@ describe('operations/mrt/push', () => {
189189
server.use(
190190
http.get(`${DEFAULT_BASE_URL}/api/projects/:projectSlug/bundles/`, ({request}) => {
191191
queryParams = new URL(request.url).searchParams;
192-
return HttpResponse.json({results: []});
192+
return HttpResponse.json({count: 0, results: []});
193193
}),
194194
);
195195

196196
const auth = new MockAuthStrategy();
197-
const client = createMrtClient({}, auth);
198197

199-
await listBundles(client, 'my-project', {limit: 10, offset: 20});
198+
await listBundles({projectSlug: 'my-project', limit: 10, offset: 20}, auth);
200199

201200
expect(queryParams?.get('limit')).to.equal('10');
202201
expect(queryParams?.get('offset')).to.equal('20');
@@ -213,11 +212,11 @@ describe('operations/mrt/push', () => {
213212
);
214213

215214
const auth = new MockAuthStrategy();
216-
const client = createMrtClient({}, auth);
217215

218-
const bundles = await listBundles(client, 'my-project');
216+
const result = await listBundles({projectSlug: 'my-project'}, auth);
219217

220-
expect(bundles).to.have.length(0);
218+
expect(result.bundles).to.have.length(0);
219+
expect(result.count).to.equal(0);
221220
});
222221

223222
it('throws error on API failure', async () => {
@@ -228,10 +227,9 @@ describe('operations/mrt/push', () => {
228227
);
229228

230229
const auth = new MockAuthStrategy();
231-
const client = createMrtClient({}, auth);
232230

233231
try {
234-
await listBundles(client, 'my-project');
232+
await listBundles({projectSlug: 'my-project'}, auth);
235233
expect.fail('Should have thrown');
236234
} catch (error) {
237235
expect((error as Error).message).to.include('Failed to list bundles');

0 commit comments

Comments
 (0)