Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aswasif007 committed May 24, 2024
1 parent a01d7f5 commit 746d705
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion __tests__/commands/phpmyadmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* External dependencies
*/
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
import nock from 'nock';

/**
* Internal dependencies
Expand Down Expand Up @@ -61,7 +62,7 @@ describe( 'commands/PhpMyAdminCommand', () => {

describe( '.run', () => {
const app = { id: 123 };
const env = { id: 456, jobs: [] };
const env = { id: 456, jobs: [], primaryDomain: { name: 'foo.com' } };
const tracker = jest.fn() as CommandTracker;
const cmd = new PhpMyAdminCommand( app, env, tracker );
const openUrl = jest.spyOn( cmd, 'openUrl' );
Expand All @@ -71,6 +72,7 @@ describe( 'commands/PhpMyAdminCommand', () => {
} );

it( 'should open the generated URL in browser', async () => {
jest.spyOn( cmd, 'readyToServe' ).mockResolvedValueOnce( true );
await cmd.run();
expect( pmaEnabledQueryMockTrue ).toHaveBeenCalledWith( {
query: expect.anything(),
Expand All @@ -91,5 +93,25 @@ describe( 'commands/PhpMyAdminCommand', () => {
} );
expect( openUrl ).toHaveBeenCalledWith( 'http://test-url.com' );
} );

describe( 'readyToServe', () => {
const domainNock = nock( 'https://foo.com' );

afterEach( () => {
domainNock.done();
} );

it( 'should do healthcheck', async () => {
domainNock.get( '/.wpvip/pma/health' ).reply( 200, { status: 'Ok' } );
await expect( cmd.readyToServe() ).resolves.toBeTruthy();
expect( domainNock.isDone() ).toBeTruthy();
} );

it( 'should false if healthcheck returns non 200 response', async () => {
domainNock.get( '/.wpvip/pma/health' ).reply( 500, 'Internal Server Error' );
await expect( cmd.readyToServe() ).resolves.toBeFalsy();
expect( domainNock.isDone() ).toBeTruthy();
} );
} );
} );
} );

0 comments on commit 746d705

Please sign in to comment.