Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for sdk-tizen/runner #1267

Merged
merged 1 commit into from
Nov 30, 2023
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: 0 additions & 9 deletions packages/sdk-tizen/src/__tests__/index.test.ts

This file was deleted.

76 changes: 76 additions & 0 deletions packages/sdk-tizen/src/__tests__/runner.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { createRnvApi, createRnvContext, execCLI, getContext } from '@rnv/core';
import { configureTizenGlobal, checkTizenStudioCert } from '../runner';
import path from 'path';

jest.mock('path', () => ({
join: jest.fn(),
}));

describe('sdk_tizen runner', () => {
beforeAll(() => {
createRnvContext();
createRnvApi();
});

afterEach(() => {
jest.clearAllMocks();
});

describe('configureTizenGlobal', () => {
const MOCKED_CERT_PATH = './mocked/cert/path.p12';
jest.spyOn(path, 'join').mockReturnValue(MOCKED_CERT_PATH);

it('should resolve if Tizen certificate exists', async () => {
//GIVEN
const c = getContext();
jest.spyOn(require('@rnv/core'), 'fsExistsSync').mockReturnValueOnce(true);
jest.spyOn(require('../runner'), 'checkTizenStudioCert').mockResolvedValueOnce(true);
//WHEN
await expect(configureTizenGlobal(c)).resolves.toBeUndefined();
//THEN
});

it("should resolve after adding Tizen certificate if it doesn't exist in Tizen Studio", async () => {
//GIVEN
const c = getContext();
jest.spyOn(require('@rnv/core'), 'fsExistsSync').mockReturnValueOnce(true);
jest.spyOn(require('../runner'), 'checkTizenStudioCert').mockResolvedValueOnce(false);
jest.spyOn(require('../deviceManager'), 'addDevelopTizenCertificate').mockResolvedValueOnce(undefined);

//WHEN
await expect(configureTizenGlobal(c)).resolves.toBeUndefined();
//THEN
});

it('should resolve after adding Tizen certificate to the "workspace.dir" and Tizen Studio', async () => {
//GIVEN
const c = getContext();
jest.spyOn(require('@rnv/core'), 'fsExistsSync').mockReturnValueOnce(false);
jest.spyOn(require('../deviceManager'), 'createDevelopTizenCertificate').mockResolvedValueOnce(undefined);

//WHEN
await expect(configureTizenGlobal(c)).resolves.toBeUndefined();
//THEN
});
});

describe('checkTizenStudioCert', () => {
it('should return true if the certificate profile exists', async () => {
//GIVEN
const c = getContext();
jest.spyOn(require('@rnv/core'), 'execCLI').mockResolvedValueOnce('');
//WHEN
await expect(checkTizenStudioCert(c)).resolves.toBe(true);
//THEN
});
it("should return false if the certificate profile doesn't exists", async () => {
//GIVEN
const c = getContext();
jest.spyOn(require('@rnv/core'), 'execCLI').mockResolvedValueOnce(new Error('Error'));

//WHEN
await expect(checkTizenStudioCert(c)).resolves.toBe(false);
//THEN
});
});
});
2 changes: 1 addition & 1 deletion packages/sdk-tizen/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { waitForHost } from '@rnv/sdk-utils';

const DEFAULT_CERTIFICATE_NAME_WITH_EXTENSION = `${DEFAULT_CERTIFICATE_NAME}.p12`;

const checkTizenStudioCert = async (c: RnvContext): Promise<boolean> => {
export const checkTizenStudioCert = async (c: RnvContext): Promise<boolean> => {
try {
await execCLI(c, CLI_TIZEN, `security-profiles list -n ${DEFAULTS.certificateProfile}`);
return true;
Expand Down