Skip to content

Commit

Permalink
Improve gmsaas executable unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
d4vidi committed Dec 29, 2024
1 parent 863ebe1 commit 101a7ed
Showing 1 changed file with 8 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ describe('Genymotion-cloud executable', () => {
const givenSuccessJSONResult = () => exec.mockResolvedValue({
stdout: JSON.stringify(successResponse),
});
const givenSuccessTextResult = () => exec.mockResolvedValue({
const givenSuccessTextualResult = () => exec.mockResolvedValue({
stdout: successResponse,
});
const givenErrorJSONResult = () => exec.mockRejectedValue({
stderr: JSON.stringify(failResponse),
});
const givenErrorResult = (errorMessage) => exec.mockRejectedValue({
const givenErrorTextualResult = (errorMessage) => exec.mockRejectedValue({
stderr: errorMessage,
});

Expand Down Expand Up @@ -59,18 +59,8 @@ describe('Genymotion-cloud executable', () => {
it('should execute command by name', async () => {
givenSuccessJSONResult();

const expectedOptions = {
...expectedExecOptions,
statusLogs: {
retrying: true,
}
};

await commandExecFn();
expect(exec).toHaveBeenCalledWith(
expectedExec,
expectedOptions,
);
expect(exec).toHaveBeenCalledWith(expectedExec, expect.objectContaining(expectedExecOptions || {}));
});

it('should return the result', async () => {
Expand All @@ -88,37 +78,27 @@ describe('Genymotion-cloud executable', () => {
});
});

describe('Text command', () => {
describe('Textual command', () => {
describe.each([
['Doctor', () => uut.doctor(), `"mock/path/to/gmsaas" --format text doctor`, { retries: 0 }],
])(`%s`, (commandName, commandExecFn, expectedExec, expectedExecOptions) => {
it('should execute command by name', async () => {
givenSuccessTextResult();

const expectedOptions = {
...expectedExecOptions,
statusLogs: {
retrying: true,
}
};
givenSuccessTextualResult();

await commandExecFn();
expect(exec).toHaveBeenCalledWith(
expectedExec,
expectedOptions,
);
expect(exec).toHaveBeenCalledWith(expectedExec, expect.objectContaining(expectedExecOptions || {}));
});

it('should return the result', async () => {
givenSuccessTextResult();
givenSuccessTextualResult();

const result = await commandExecFn();
expect(result).toEqual(successResponse);
});

it('should fail upon an error result', async () => {
const errorMessage = 'Oh no, mocked error has occurred!';
givenErrorResult(errorMessage);
givenErrorTextualResult(errorMessage);

await expect(commandExecFn()).rejects.toThrowError(errorMessage);
});
Expand Down

0 comments on commit 101a7ed

Please sign in to comment.