Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions __tests__/commands/export-sql.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from 'chalk';
import fs from 'fs';

import {
Expand Down Expand Up @@ -258,8 +259,9 @@ describe( 'commands/ExportSQLCommand', () => {
expect( stepSuccessSpy ).toHaveBeenCalledWith( 'create' );
expect( stepSuccessSpy ).toHaveBeenCalledWith( 'confirmEnoughStorage' );
expect( stepSuccessSpy ).toHaveBeenCalledWith( 'downloadLink', [
'https://test-backup.sql.gz',
`${ chalk.green( 'Download URL' ) }: https://test-backup.sql.gz`,
] );

expect( stepSuccessSpy ).toHaveBeenCalledWith( 'download' );
expect( downloadMock ).toHaveBeenCalledWith(
'https://test-backup.sql.gz',
Expand All @@ -274,7 +276,7 @@ describe( 'commands/ExportSQLCommand', () => {
const stepSkippedSpy = jest.spyOn( exportCommandWithUrl.progressTracker, 'stepSkipped' );
const confirmEnoughStorageSpyUrl = jest.spyOn( exportCommandWithUrl, 'confirmEnoughStorage' );
const downloadMock = jest.spyOn( downloadFileModule, 'downloadFile' ).mockResolvedValue();
const consoleLogSpy = jest.spyOn( console, 'log' ).mockImplementation();
const stdoutSpy = jest.spyOn( process.stdout, 'write' ).mockImplementation();

confirmEnoughStorageSpyUrl.mockResolvedValue( { continue: true, isPromptShown: false } );

Expand All @@ -288,15 +290,14 @@ describe( 'commands/ExportSQLCommand', () => {
expect( confirmEnoughStorageSpyUrl ).not.toHaveBeenCalled();
expect( downloadMock ).not.toHaveBeenCalled();

// Should output the download URL
expect( consoleLogSpy ).toHaveBeenCalledWith(
expect.stringContaining( 'https://test-backup.sql.gz' )
expect( stdoutSpy ).toHaveBeenCalledWith(
expect.stringContaining( `${ chalk.green( 'Download URL' ) }: https://test-backup.sql.gz` )
);

stepSuccessSpyUrl.mockRestore();
stepSkippedSpy.mockRestore();
confirmEnoughStorageSpyUrl.mockRestore();
consoleLogSpy.mockRestore();
stdoutSpy.mockRestore();
} );
} );

Expand Down
16 changes: 11 additions & 5 deletions src/commands/export-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,12 @@ export class ExportSQLCommand {
size = Number( bytesWrittenMeta.value );
}

const downloadURLString = `\n${ chalk.green( 'Download URL' ) }:\n${ url }\n\n`;

if ( this.skipDownload ) {
this.progressTracker.stepSkipped( this.steps.CONFIRM_ENOUGH_STORAGE );
this.progressTracker.stepSkipped( this.steps.DOWNLOAD );
this.progressTracker.print();
this.progressTracker.stopPrinting();
console.log( downloadURLString );

return;
}

Expand Down Expand Up @@ -475,6 +473,10 @@ export class ExportSQLCommand {
}
}

private generateDownloadURLOutputString( url: string ): string {
return `${ chalk.green( 'Download URL' ) }: ${ url }`;
}

private async runBackup() {
if ( this.generateBackup ) {
await this.runBackupJob();
Expand Down Expand Up @@ -557,7 +559,9 @@ export class ExportSQLCommand {
this.progressTracker.stepSuccess( this.steps.CREATE );

const url = await generateDownloadLink( this.app.id, this.env.id, latestBackup.id );
this.progressTracker.stepSuccess( this.steps.DOWNLOAD_LINK, [ url ] );
this.progressTracker.stepSuccess( this.steps.DOWNLOAD_LINK, [
this.generateDownloadURLOutputString( url ),
] );

return url;
}
Expand Down Expand Up @@ -590,7 +594,9 @@ export class ExportSQLCommand {
} );
this.progressTracker.stepSuccess( this.steps.CREATE );

this.progressTracker.stepSuccess( this.steps.DOWNLOAD_LINK, [ result.url ] );
this.progressTracker.stepSuccess( this.steps.DOWNLOAD_LINK, [
this.generateDownloadURLOutputString( result.url ),
] );

return result;
} catch ( err ) {
Expand Down