Skip to content

Commit

Permalink
test: getConfig()
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Nov 9, 2023
1 parent 6b14516 commit 67aec4a
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
configContextFixture,
IConfigTestContext,
} from './fixtures/config.fixture';
import { CustomOctokit } from '../../src/octokit';

describe('Config Object', () => {
beforeEach<IConfigTestContext>(context => {
Expand All @@ -29,6 +30,65 @@ describe('Config Object', () => {
});
});

test('getConfig()', async () => {
process.env['INPUT_CONFIG-PATH'] = '.github/development-freeze.yml';
process.env['GITHUB_REPOSITORY'] = 'test/test';

const configObject = {
policy: [
{
tags: ['alpha', 'beta'],
feedback: {
'frozen-state': 'This is No-No',
'unfreeze-state': 'This is Yes-Yes',
},
random: 'random',
},
],
};

const noConfigObject = undefined;

const octokit = (data: unknown) => {
return {
config: {
get: async (options: {
owner: string;
repo: string;
path: string;
}) => {
return {
config: data,
files: [options.path],
};
},
},
} as unknown as CustomOctokit;
};

let config = await Config.getConfig(octokit(configObject));
expect(config.policy).toMatchInlineSnapshot(`
[
{
"feedback": {
"frozen-state": "This is No-No",
"unfreeze-state": "This is Yes-Yes",
},
"tags": [
"alpha",
"beta",
],
},
]
`);

await expect(
Config.getConfig(octokit(noConfigObject))
).rejects.toThrowErrorMatchingInlineSnapshot(
"\"Missing configuration. Please setup 'devel-freezer' Action using '.github/development-freeze.yml' file.\""
);
});

test<IConfigTestContext>('is config empty', context => {
context.configs.map(async item =>
expect(Config.isConfigEmpty(item)).toEqual(false)
Expand Down

0 comments on commit 67aec4a

Please sign in to comment.