From 67aec4a153bd9fca5322e1c4dd4d7c419fb36362 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Thu, 9 Nov 2023 13:11:52 +0100 Subject: [PATCH] test: `getConfig()` --- test/unit/config.test.ts | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/unit/config.test.ts b/test/unit/config.test.ts index 029c158..d4f2450 100644 --- a/test/unit/config.test.ts +++ b/test/unit/config.test.ts @@ -6,6 +6,7 @@ import { configContextFixture, IConfigTestContext, } from './fixtures/config.fixture'; +import { CustomOctokit } from '../../src/octokit'; describe('Config Object', () => { beforeEach(context => { @@ -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('is config empty', context => { context.configs.map(async item => expect(Config.isConfigEmpty(item)).toEqual(false)