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
9 changes: 1 addition & 8 deletions cli/commands/auth/tests/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { openBrowser } from 'cli/lib/browser';
import { getAppLocale } from 'cli/lib/i18n';
import { Logger, LoggerError } from 'cli/logger';
import { runCommand } from '../login';

jest.mock( '@inquirer/prompts' );
jest.mock( 'common/lib/oauth' );
Expand Down Expand Up @@ -76,15 +77,13 @@ describe( 'Auth Login Command', () => {
it( 'should skip login if already authenticated', async () => {
( getAuthToken as jest.Mock ).mockResolvedValue( mockAppdata.authToken );

const { runCommand } = await import( '../login' );
await runCommand();

expect( openBrowser ).not.toHaveBeenCalled();
expect( input ).not.toHaveBeenCalled();
} );

it( 'should complete the login process successfully', async () => {
const { runCommand } = await import( '../login' );
await runCommand();

expect( getAuthenticationUrl ).toHaveBeenCalledWith(
Expand All @@ -111,7 +110,6 @@ describe( 'Auth Login Command', () => {
} );

it( 'should proceed with login if existing token is invalid', async () => {
const { runCommand } = await import( '../login' );
await runCommand();

expect( openBrowser ).toHaveBeenCalled();
Expand All @@ -122,7 +120,6 @@ describe( 'Auth Login Command', () => {
const browserError = new LoggerError( 'Failed to open browser' );
( openBrowser as jest.Mock ).mockRejectedValue( browserError );

const { runCommand } = await import( '../login' );
await runCommand();

expect( input ).toHaveBeenCalled();
Expand All @@ -132,7 +129,6 @@ describe( 'Auth Login Command', () => {
const apiError = new LoggerError( 'Failed to fetch user info' );
( getUserInfo as jest.Mock ).mockRejectedValue( apiError );

const { runCommand } = await import( '../login' );
await runCommand();

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -144,7 +140,6 @@ describe( 'Auth Login Command', () => {
const saveError = new Error( 'Failed to save' );
( saveAppdata as jest.Mock ).mockRejectedValue( saveError );

const { runCommand } = await import( '../login' );
await runCommand();

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -157,7 +152,6 @@ describe( 'Auth Login Command', () => {
const lockError = new Error( 'Failed to lock' );
( lockAppdata as jest.Mock ).mockRejectedValue( lockError );

const { runCommand } = await import( '../login' );
await runCommand();

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -167,7 +161,6 @@ describe( 'Auth Login Command', () => {
it( 'should use provided locale', async () => {
( getAppLocale as jest.Mock ).mockResolvedValue( 'fr' );

const { runCommand } = await import( '../login' );
await runCommand();

expect( getAuthenticationUrl ).toHaveBeenCalledWith(
Expand Down
5 changes: 1 addition & 4 deletions cli/commands/auth/tests/logout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
unlockAppdata,
} from 'cli/lib/appdata';
import { Logger, LoggerError } from 'cli/logger';
import { runCommand } from '../logout';

jest.mock( 'cli/lib/appdata' );
jest.mock( 'cli/logger' );
Expand Down Expand Up @@ -55,7 +56,6 @@ describe( 'Auth Logout Command', () => {
} );

it( 'should complete the logout process successfully', async () => {
const { runCommand } = await import( '../logout' );
await runCommand();

expect( getAuthToken ).toHaveBeenCalled();
Expand All @@ -72,7 +72,6 @@ describe( 'Auth Logout Command', () => {
it( 'should report an error if revoking the token fails', async () => {
( revokeAuthToken as jest.Mock ).mockRejectedValue( new Error( 'Failed to revoke token' ) );

const { runCommand } = await import( '../logout' );
await runCommand();

expect( getAuthToken ).toHaveBeenCalled();
Expand All @@ -87,7 +86,6 @@ describe( 'Auth Logout Command', () => {
it( 'should report already logged out if no auth token exists', async () => {
( getAuthToken as jest.Mock ).mockRejectedValue( new Error( 'No auth token' ) );

const { runCommand } = await import( '../logout' );
await runCommand();

expect( getAuthToken ).toHaveBeenCalled();
Expand All @@ -101,7 +99,6 @@ describe( 'Auth Logout Command', () => {
it( 'should unlock appdata even if save fails', async () => {
( saveAppdata as jest.Mock ).mockRejectedValue( new Error( 'Failed to save' ) );

const { runCommand } = await import( '../logout' );
await runCommand();

expect( revokeAuthToken ).toHaveBeenCalled();
Expand Down
5 changes: 1 addition & 4 deletions cli/commands/auth/tests/status.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getUserInfo } from 'cli/lib/api';
import { getAuthToken } from 'cli/lib/appdata';
import { Logger, LoggerError } from 'cli/logger';
import { runCommand } from '../status';

jest.mock( 'cli/lib/api' );
jest.mock( 'cli/lib/appdata' );
Expand Down Expand Up @@ -44,7 +45,6 @@ describe( 'Auth Status Command', () => {
} );

it( 'should report success when authenticated', async () => {
const { runCommand } = await import( '../status' );
await runCommand();

expect( mockLogger.reportStart ).toHaveBeenCalled();
Expand All @@ -58,7 +58,6 @@ describe( 'Auth Status Command', () => {
it( 'should report error when token is invalid', async () => {
( getAuthToken as jest.Mock ).mockRejectedValue( new Error( 'Token error' ) );

const { runCommand } = await import( '../status' );
await runCommand();

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -70,7 +69,6 @@ describe( 'Auth Status Command', () => {
const apiError = new LoggerError( 'API error' );
( getUserInfo as jest.Mock ).mockRejectedValue( apiError );

const { runCommand } = await import( '../status' );
await runCommand();

expect( mockLogger.reportError ).toHaveBeenCalledWith( apiError );
Expand All @@ -79,7 +77,6 @@ describe( 'Auth Status Command', () => {
it( 'should wrap unknown error when getUserInfo fails', async () => {
( getUserInfo as jest.Mock ).mockRejectedValue( new Error( 'Unknown error' ) );

const { runCommand } = await import( '../status' );
await runCommand();

expect( mockLogger.reportError ).toHaveBeenCalledWith( expect.any( LoggerError ) );
Expand Down
10 changes: 1 addition & 9 deletions cli/commands/preview/tests/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getAuthToken, getSiteByFolder } from 'cli/lib/appdata';
import { archiveSiteContent, cleanup } from 'cli/lib/archive';
import { saveSnapshotToAppdata } from 'cli/lib/snapshots';
import { Logger, LoggerError } from 'cli/logger';
import { runCommand } from '../create';

jest.mock( 'common/lib/get-wordpress-version' );
jest.mock( 'cli/lib/appdata', () => ( {
Expand Down Expand Up @@ -79,7 +80,6 @@ describe( 'Preview Create Command', () => {

it( 'should complete the preview creation process successfully', async () => {
( getWordPressVersion as jest.Mock ).mockReturnValue( '6.8.1' );
const { runCommand } = await import( '../create' );
await runCommand( mockFolder );

expect( getSiteByFolder ).toHaveBeenCalledWith( mockFolder );
Expand Down Expand Up @@ -124,7 +124,6 @@ describe( 'Preview Create Command', () => {
} );

it( 'should use current directory when no folder is specified', async () => {
const { runCommand } = await import( '../create' );
await runCommand( process.cwd() );

expect( getSiteByFolder ).toHaveBeenCalledWith( process.cwd() );
Expand All @@ -137,7 +136,6 @@ describe( 'Preview Create Command', () => {
throw new LoggerError( errorMessage );
} );

const { runCommand } = await import( '../create' );
await runCommand( mockFolder );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -152,7 +150,6 @@ describe( 'Preview Create Command', () => {
throw new LoggerError( errorMessage );
} );

const { runCommand } = await import( '../create' );
await runCommand( mockFolder );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -166,7 +163,6 @@ describe( 'Preview Create Command', () => {
throw new LoggerError( errorMessage );
} );

const { runCommand } = await import( '../create' );
await runCommand( mockFolder );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -180,7 +176,6 @@ describe( 'Preview Create Command', () => {
throw new LoggerError( errorMessage );
} );

const { runCommand } = await import( '../create' );
await runCommand( mockFolder );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -194,7 +189,6 @@ describe( 'Preview Create Command', () => {
throw new LoggerError( errorMessage );
} );

const { runCommand } = await import( '../create' );
await runCommand( mockFolder );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -208,7 +202,6 @@ describe( 'Preview Create Command', () => {
throw new LoggerError( errorMessage );
} );

const { runCommand } = await import( '../create' );
await runCommand( mockFolder );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -220,7 +213,6 @@ describe( 'Preview Create Command', () => {
throw new LoggerError( 'Upload failed' );
} );

const { runCommand } = await import( '../create' );
await runCommand( mockFolder );

expect( cleanup ).toHaveBeenCalledWith( mockArchivePath );
Expand Down
6 changes: 1 addition & 5 deletions cli/commands/preview/tests/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { deleteSnapshot } from 'cli/lib/api';
import { getAuthToken } from 'cli/lib/appdata';
import { getSnapshotsFromAppdata, deleteSnapshotFromAppdata } from 'cli/lib/snapshots';
import { Logger, LoggerError } from 'cli/logger';
import { runCommand } from '../delete';

jest.mock( 'cli/lib/appdata', () => ( {
...jest.requireActual( 'cli/lib/appdata' ),
Expand Down Expand Up @@ -52,7 +53,6 @@ describe( 'Preview Delete Command', () => {
} );

it( 'should complete the preview deletion process successfully', async () => {
const { runCommand } = await import( '../delete' );
await runCommand( mockSiteUrl );

expect( getAuthToken ).toHaveBeenCalled();
Expand All @@ -73,7 +73,6 @@ describe( 'Preview Delete Command', () => {
throw new LoggerError( errorMessage );
} );

const { runCommand } = await import( '../delete' );
await runCommand( mockSiteUrl );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -84,7 +83,6 @@ describe( 'Preview Delete Command', () => {
it( 'should handle snapshot not found errors', async () => {
( getSnapshotsFromAppdata as jest.Mock ).mockResolvedValue( [] );

const { runCommand } = await import( '../delete' );
await runCommand( mockSiteUrl );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -98,7 +96,6 @@ describe( 'Preview Delete Command', () => {
throw new LoggerError( errorMessage );
} );

const { runCommand } = await import( '../delete' );
await runCommand( mockSiteUrl );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand All @@ -112,7 +109,6 @@ describe( 'Preview Delete Command', () => {
throw new LoggerError( errorMessage );
} );

const { runCommand } = await import( '../delete' );
await runCommand( mockSiteUrl );

expect( mockLogger.reportError ).toHaveBeenCalled();
Expand Down
4 changes: 1 addition & 3 deletions cli/commands/preview/tests/list.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAuthToken, getSiteByFolder } from 'cli/lib/appdata';
import { getSnapshotsFromAppdata } from 'cli/lib/snapshots';
import { Logger } from 'cli/logger';
import { runCommand } from '../list';

jest.mock( 'cli/lib/appdata', () => ( {
...jest.requireActual( 'cli/lib/appdata' ),
Expand Down Expand Up @@ -65,7 +66,6 @@ describe( 'Preview List Command', () => {
} );

it( 'should list preview sites successfully', async () => {
const { runCommand } = await import( '../list' );
await runCommand( mockFolder, 'table' );

expect( getSiteByFolder ).toHaveBeenCalledWith( mockFolder );
Expand All @@ -80,7 +80,6 @@ describe( 'Preview List Command', () => {
} );

it( 'should handle validation errors', async () => {
const { runCommand } = await import( '../list' );
( getSiteByFolder as jest.Mock ).mockImplementation( () => {
throw new Error( 'Invalid site folder' );
} );
Expand All @@ -91,7 +90,6 @@ describe( 'Preview List Command', () => {
} );

it( 'should handle no snapshots found', async () => {
const { runCommand } = await import( '../list' );
( getSnapshotsFromAppdata as jest.Mock ).mockResolvedValue( [] );

await runCommand( mockFolder, 'table' );
Expand Down
Loading
Loading