Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix unit test
  • Loading branch information
Goggags123 committed Nov 9, 2021
commit d437404b178e5de214ad7413fe74e277ce17d646
88 changes: 80 additions & 8 deletions src/Config/Config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Config } from './Config';

const MOCK_ARGS = [
const PR_MOCK_ARGS = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'--url=https://github.com/codeleague/codecoach.git',
Expand All @@ -11,13 +11,25 @@ const MOCK_ARGS = [
'-o=./tmp/out.json',
];

const MOCK_ARGS_W_CONFIG_YAML = [
const PR_MOCK_ARGS_W_COMMAND = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'comment',
'--url=https://github.com/codeleague/codecoach.git',
'--removeOldComment',
'--token=placeyourtokenhere',
'--pr=15',
'-f=dotnetbuild;./sample/dotnetbuild/build.content;/repo/src',
'-o=./tmp/out.json',
];

const PR_MOCK_ARGS_W_CONFIG_YAML = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'--config=sample/config/config.yaml',
];

export const EXPECTED_MOCK_ARGS = [
export const PR_EXPECTED_MOCK_ARGS = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'https://github.com/codeleague/codecoach.git',
Expand All @@ -28,23 +40,83 @@ export const EXPECTED_MOCK_ARGS = [
'./tmp/out.json',
];

describe('Config Test', () => {
const DATA_MOCK_ARGS = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'collect',
'--url=https://github.com/codeleague/codecoach.git',
'-r=3',
'-c=latestcommitsha',
'--token=placeyourtokenhere',
'-f=dotnetbuild;./sample/dotnetbuild/build.content;/repo/src',
'-o=./tmp/out.json',
];

const DATA_MOCK_ARGS_W_CONFIG_YAML = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'collect',
'--config=sample/config/dataConfig.yaml',
];

export const DATA_EXPECTED_MOCK_ARGS = [
'/usr/local/Cellar/node/15.13.0/bin/node',
'/Users/codecoach/src/app.ts',
'https://github.com/codeleague/codecoach.git',
3,
'latestcommitsha',
'placeyourtokenhere',
'dotnetbuild;./sample/dotnetbuild/build.content;/repo/src',
'./tmp/out.json',
];

describe('PR config Test', () => {
let config: typeof Config;

beforeEach(() => {
jest.resetModules();
});

it('Should able to parse this args and run without throwing error', async () => {
process.argv = PR_MOCK_ARGS;
config = (await import('./Config')).Config;
let fullfillConfig = await config;
expect(fullfillConfig.provider.repoUrl).toBe(PR_EXPECTED_MOCK_ARGS[2]);
expect(fullfillConfig.provider.removeOldComment).toBe(PR_EXPECTED_MOCK_ARGS[3]);

process.argv = PR_MOCK_ARGS_W_COMMAND;
config = (await import('./Config')).Config;
fullfillConfig = await config;
expect(fullfillConfig.provider.repoUrl).toBe(PR_EXPECTED_MOCK_ARGS[2]);
expect(fullfillConfig.provider.removeOldComment).toBe(PR_EXPECTED_MOCK_ARGS[3]);
});

it('Should able to use a config file without passing other args', async () => {
process.argv = PR_MOCK_ARGS_W_CONFIG_YAML;
config = (await import('./Config')).Config;
const fullfillConfig = await config;
expect(fullfillConfig.app.buildLogFiles[0].type).toBe('tslint');
});
});

describe('Data config Test', () => {
let config: typeof Config;

beforeEach(() => {
jest.resetModules();
});

it('Should able to parse this args and run without throwing error', async () => {
process.argv = MOCK_ARGS;
process.argv = DATA_MOCK_ARGS;
config = (await import('./Config')).Config;
const fullfillConfig = await config;
expect(fullfillConfig.provider.repoUrl).toBe(EXPECTED_MOCK_ARGS[2]);
expect(fullfillConfig.provider.removeOldComment).toBe(EXPECTED_MOCK_ARGS[3]);
expect(fullfillConfig.provider.repoUrl).toBe(DATA_EXPECTED_MOCK_ARGS[2]);
expect(fullfillConfig.provider.runId).toBe(DATA_EXPECTED_MOCK_ARGS[3]);
expect(fullfillConfig.provider.latestCommit).toBe(DATA_EXPECTED_MOCK_ARGS[4]);
});

it('Should able to use a config file without passing other args', async () => {
process.argv = MOCK_ARGS_W_CONFIG_YAML;
process.argv = DATA_MOCK_ARGS_W_CONFIG_YAML;
config = (await import('./Config')).Config;
const fullfillConfig = await config;
expect(fullfillConfig.app.buildLogFiles[0].type).toBe('tslint');
Expand Down
14 changes: 12 additions & 2 deletions src/Config/YML.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { COMMAND } from './constants/defaults';
import { YML } from './YML';

describe('YML Test', () => {
describe('PR YML Test', () => {
it('Should able to validate yaml file correctly', async () => {
const config = await YML.parse('sample/config/config.yaml');
const config = await YML.parse('sample/config/config.yaml', COMMAND.DEFAULT);
expect(config.output).toBe('./output.json');
expect(config.repo.pr).toBe(40);
expect(config.repo.removeOldComment).toBe(false);
});
});

describe('Data YML Test', () => {
it('Should able to validate yaml file correctly', async () => {
const config = await YML.parse('sample/config/dataConfig.yaml', COMMAND.COLLECT);
expect(config.output).toBe('./output.json');
expect(config.repo.runId).toBe(40);
expect(config.repo.latestCommit).toBe('123qwe123qwe123qwe123qwe123qwe123qwe123q');
});
});