Skip to content

Commit

Permalink
test: update existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Mar 20, 2024
1 parent 3c564da commit 21ad284
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 96 deletions.
6 changes: 3 additions & 3 deletions test/integration/fixtures/metadata.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export interface IMetadataTestContext {

export const metadataContextFixture: IMetadataTestContext = {
payloads: [
payloadPullRequestOpened as PullRequestOpenedEvent,
payloadPullRequestReopened as PullRequestReopenedEvent,
payloadPullRequestSynchronize as PullRequestSynchronizeEvent,
payloadPullRequestOpened as unknown as PullRequestOpenedEvent,
payloadPullRequestReopened as unknown as PullRequestReopenedEvent,
payloadPullRequestSynchronize as unknown as PullRequestSynchronizeEvent,
],
};
34 changes: 0 additions & 34 deletions test/unit/__snapshots__/config.test.ts.snap

This file was deleted.

116 changes: 78 additions & 38 deletions test/unit/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,78 @@
import { describe, it, expect, beforeEach, test } from 'vitest';

import { Config } from '../../src/config';

import {
configContextFixture,
IConfigTestContext,
} from './fixtures/config.fixture';
import { CustomOctokit } from '../../src/octokit';

describe('Config Object', () => {
beforeEach<IConfigTestContext>(context => {
context.configs = configContextFixture.configs;
});
let config: Config;
let configRaw = {
policy: [
{
tags: ['alpha', 'beta'],
feedback: {
'frozen-state': 'This is No-No',
'unfreeze-state': 'This is Yes-Yes',
},
},
{
tags: [`^(v\d*)-rc\d$`],
labels: {
allow: ['regression ⚠️'],
},
feedback: {
'frozen-state': `We are currently in a development freeze phase.\nPlease ...`,
'unfreeze-state': `We had successfully released a new major release.\nWe are no longer in a development freeze phase.`,
},
},
],
};

it<IConfigTestContext>('can be instantiated', context => {
context.configs.map(item => expect(item).toBeDefined());
beforeEach(() => {
config = new Config(configRaw);
});

test<IConfigTestContext>('get policy()', context => {
context.configs.map(configItem => {
expect(configItem.policy).toMatchSnapshot();
it('can be instantiated', () => {
expect(config).toBeDefined();
expect(config).toBeInstanceOf(Config);
});

configItem.policy.map(policyItem => {
expect(policyItem.tags).toMatchSnapshot();
expect(policyItem.feedback).toMatchSnapshot();
expect(policyItem.feedback['frozen-state']).toMatchSnapshot();
expect(policyItem.feedback['unfreeze-state']).toMatchSnapshot();
});
});
test('get policy()', () => {
expect(config.policy).toMatchInlineSnapshot(`
[
{
"feedback": {
"frozen-state": "This is No-No",
"unfreeze-state": "This is Yes-Yes",
},
"tags": [
"alpha",
"beta",
],
},
{
"feedback": {
"frozen-state": "We are currently in a development freeze phase.
Please ...",
"unfreeze-state": "We had successfully released a new major release.
We are no longer in a development freeze phase.",
},
"labels": {
"allow": [
"regression ⚠️",
],
},
"tags": [
"^(vd*)-rcd$",
],
},
]
`);
});

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) => {
Expand All @@ -66,7 +92,7 @@ describe('Config Object', () => {
} as unknown as CustomOctokit;
};

let config = await Config.getConfig(octokit(configObject));
let config = await Config.getConfig(octokit(configRaw));
expect(config.policy).toMatchInlineSnapshot(`
[
{
Expand All @@ -79,6 +105,22 @@ describe('Config Object', () => {
"beta",
],
},
{
"feedback": {
"frozen-state": "We are currently in a development freeze phase.
Please ...",
"unfreeze-state": "We had successfully released a new major release.
We are no longer in a development freeze phase.",
},
"labels": {
"allow": [
"regression ⚠️",
],
},
"tags": [
"^(vd*)-rcd$",
],
},
]
`);

Expand All @@ -89,10 +131,8 @@ describe('Config Object', () => {
);
});

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

expect(Config.isConfigEmpty(null)).toEqual(true);
});
Expand Down
21 changes: 0 additions & 21 deletions test/unit/fixtures/config.fixture.ts

This file was deleted.

0 comments on commit 21ad284

Please sign in to comment.