diff --git a/test/integration/fixtures/metadata.fixture.ts b/test/integration/fixtures/metadata.fixture.ts index b1dc5b5..a68b325 100644 --- a/test/integration/fixtures/metadata.fixture.ts +++ b/test/integration/fixtures/metadata.fixture.ts @@ -4,35 +4,22 @@ import { PullRequestSynchronizeEvent, } from '@octokit/webhooks-types'; -import { events } from '../../../src/events'; - import payloadPullRequestOpened from '../fixtures/payloads/pull-request-opened.json'; import payloadPullRequestReopened from '../fixtures/payloads/pull-request-reopened.json'; import payloadPullRequestSynchronize from '../fixtures/payloads/pull-request-synchronize.json'; export interface IMetadataTestContext { - payloads: { - type: (typeof events.pull_request)[number]; - payload: - | PullRequestOpenedEvent - | PullRequestReopenedEvent - | PullRequestSynchronizeEvent; - }[]; + payloads: ( + | PullRequestOpenedEvent + | PullRequestReopenedEvent + | PullRequestSynchronizeEvent + )[]; } export const metadataContextFixture: IMetadataTestContext = { payloads: [ - { - type: 'pull_request.opened', - payload: payloadPullRequestOpened as PullRequestOpenedEvent, - }, - { - type: 'pull_request.reopened', - payload: payloadPullRequestReopened as PullRequestReopenedEvent, - }, - { - type: 'pull_request.synchronize', - payload: payloadPullRequestSynchronize as PullRequestSynchronizeEvent, - }, + payloadPullRequestOpened as PullRequestOpenedEvent, + payloadPullRequestReopened as PullRequestReopenedEvent, + payloadPullRequestSynchronize as PullRequestSynchronizeEvent, ], }; 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) diff --git a/test/unit/fixtures/metadata.fixture.ts b/test/unit/fixtures/metadata.fixture.ts index c63023e..670eb58 100644 --- a/test/unit/fixtures/metadata.fixture.ts +++ b/test/unit/fixtures/metadata.fixture.ts @@ -4,7 +4,6 @@ import { Metadata } from '../../../src/metadata'; export interface IMetadataTestContext { metadata: Metadata[]; - invalid: Metadata[]; } const controller = {} as MetadataController; @@ -16,23 +15,4 @@ export const metadataContextFixture: IMetadataTestContext = { new Metadata(0, controller, { tag: undefined, commentID: '123456789' }), new Metadata(0, controller, { tag: 'v1', commentID: '123456789' }), ], - - invalid: [ - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Metadata(), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Metadata(null), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Metadata(undefined), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Metadata(''), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Metadata({}), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Metadata([]), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Metadata({ tag: null, commentID: null }), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Metadata({ tag: undefined, commentID: 123456789 }), - ], }; diff --git a/test/unit/fixtures/tag.fixture.ts b/test/unit/fixtures/tag.fixture.ts index 9b191c7..02f0c88 100644 --- a/test/unit/fixtures/tag.fixture.ts +++ b/test/unit/fixtures/tag.fixture.ts @@ -3,7 +3,6 @@ import { Tag } from '../../../src/tag'; export interface ITagTestContext { tags: Tag[]; tagPolicy: string[][]; - invalid: Tag[]; } export const tagContextFixture: ITagTestContext = { @@ -19,17 +18,4 @@ export const tagContextFixture: ITagTestContext = { ], tagPolicy: [['^S*-rcd$'], ['alpha', 'beta'], ['latest']], - - invalid: [ - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Tag(), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Tag(null), - new Tag(undefined), - new Tag(''), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Tag({}), - // @ts-expect-error: Let's ignore a type error, it's required for testing - new Tag([]), - ], }; diff --git a/test/unit/metadata.test.ts b/test/unit/metadata.test.ts index dfa68a9..bfb0f29 100644 --- a/test/unit/metadata.test.ts +++ b/test/unit/metadata.test.ts @@ -8,14 +8,11 @@ import { describe('Metadata Object', () => { beforeEach(context => { context.metadata = metadataContextFixture.metadata; - context.invalid = metadataContextFixture.invalid; }); it('can be instantiated', context => context.metadata.map(metadataItem => expect(metadataItem).toBeDefined())); - it.todo('is invalid'); - test('get tag()', context => context.metadata.map(metadataItem => expect(metadataItem.tag).toMatchSnapshot() diff --git a/test/unit/tag.test.ts b/test/unit/tag.test.ts index 379e870..6c10065 100644 --- a/test/unit/tag.test.ts +++ b/test/unit/tag.test.ts @@ -6,20 +6,11 @@ describe('Tag Object', () => { beforeEach(context => { context.tags = tagContextFixture.tags; context.tagPolicy = tagContextFixture.tagPolicy; - context.invalid = tagContextFixture.invalid; }); it('can be instantiated', context => context.tags.map(tagsItem => expect(tagsItem).toBeDefined())); - it.todo( - 'is invalid' /*, async context => { - context.invalid.map(async item => - expect(Metadata.validate(item)).resolves.toMatchSnapshot() - ); - }*/ - ); - test('get latest()', context => context.tags.map(tagsItem => expect(tagsItem.latest).toMatchSnapshot()));