-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b64136
commit 8314de3
Showing
2 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-return */ | ||
/** | ||
* External dependencies | ||
*/ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { CommandTracker } from '../../src/lib/tracker'; | ||
import { PhpMyAdminCommand } from '../../src/commands/phpmyadmin'; | ||
import API from '../../src/lib/api'; | ||
import { beforeEach, describe, expect, it, jest } from '@jest/globals'; | ||
import opn from 'opn'; | ||
|
||
const mutationMock = jest.fn( async () => { | ||
return Promise.resolve( { | ||
data: { | ||
generatePHPMyAdminAccess: { | ||
url: 'http://test-url.com', | ||
}, | ||
}, | ||
} ); | ||
} ); | ||
|
||
jest.mock( '../../src/lib/api' ); | ||
jest.mock( 'opn' ); | ||
jest.mocked( API ).mockImplementation( () => { | ||
return Promise.resolve( { | ||
mutate: mutationMock, | ||
} as any ); | ||
} ); | ||
|
||
describe( 'commands/PhpMyAdminCommand', () => { | ||
beforeEach( () => {} ); | ||
|
||
describe( '.run', () => { | ||
const app = { id: 123 }; | ||
const env = { id: 456, jobs: [] }; | ||
const tracker = jest.fn() as CommandTracker; | ||
const cmd = new PhpMyAdminCommand( app, env, tracker ); | ||
|
||
it( 'should generate a URL by calling the right mutation', async () => { | ||
await cmd.run(); | ||
expect( mutationMock ).toHaveBeenCalledWith( { | ||
mutation: expect.anything(), | ||
variables: { | ||
input: { | ||
environmentId: 456, | ||
}, | ||
}, | ||
} ); | ||
} ); | ||
it( 'should open the generated URL in browser', async () => { | ||
await cmd.run(); | ||
expect( opn ).toHaveBeenCalledWith( 'http://test-url.com', { wait: false } ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters