From 022ad367fb2a1863f58ddcb76df6ad6a051e6719 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Fri, 14 Oct 2022 12:53:26 +0200 Subject: [PATCH] test: `tag.ts` --- test/unit/__snapshots__/tag.test.ts.snap | 65 ++++++++++++++++++++++++ test/unit/fixtures/tag.fixture.ts | 6 +++ test/unit/tag.test.ts | 26 ++++++++-- 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 test/unit/__snapshots__/tag.test.ts.snap diff --git a/test/unit/__snapshots__/tag.test.ts.snap b/test/unit/__snapshots__/tag.test.ts.snap new file mode 100644 index 0000000..c725c17 --- /dev/null +++ b/test/unit/__snapshots__/tag.test.ts.snap @@ -0,0 +1,65 @@ +// Vitest Snapshot v1 + +exports[`Tag Object > get latest() 1`] = `"v0.0.1"`; + +exports[`Tag Object > get latest() 2`] = `"v1"`; + +exports[`Tag Object > get latest() 3`] = `"latest"`; + +exports[`Tag Object > get latest() 4`] = `"v1-rc1"`; + +exports[`Tag Object > get latest() 5`] = `"v1-beta"`; + +exports[`Tag Object > get latest() 6`] = `"alpha"`; + +exports[`Tag Object > get latest() 7`] = `"beta"`; + +exports[`Tag Object > get latest() 8`] = `"rc1"`; + +exports[`Tag Object > isFreezed() 1`] = `false`; + +exports[`Tag Object > isFreezed() 2`] = `false`; + +exports[`Tag Object > isFreezed() 3`] = `false`; + +exports[`Tag Object > isFreezed() 4`] = `false`; + +exports[`Tag Object > isFreezed() 5`] = `false`; + +exports[`Tag Object > isFreezed() 6`] = `false`; + +exports[`Tag Object > isFreezed() 7`] = `false`; + +exports[`Tag Object > isFreezed() 8`] = `false`; + +exports[`Tag Object > isFreezed() 9`] = `true`; + +exports[`Tag Object > isFreezed() 10`] = `false`; + +exports[`Tag Object > isFreezed() 11`] = `false`; + +exports[`Tag Object > isFreezed() 12`] = `false`; + +exports[`Tag Object > isFreezed() 13`] = `false`; + +exports[`Tag Object > isFreezed() 14`] = `true`; + +exports[`Tag Object > isFreezed() 15`] = `false`; + +exports[`Tag Object > isFreezed() 16`] = `false`; + +exports[`Tag Object > isFreezed() 17`] = `true`; + +exports[`Tag Object > isFreezed() 18`] = `false`; + +exports[`Tag Object > isFreezed() 19`] = `false`; + +exports[`Tag Object > isFreezed() 20`] = `true`; + +exports[`Tag Object > isFreezed() 21`] = `false`; + +exports[`Tag Object > isFreezed() 22`] = `false`; + +exports[`Tag Object > isFreezed() 23`] = `false`; + +exports[`Tag Object > isFreezed() 24`] = `false`; diff --git a/test/unit/fixtures/tag.fixture.ts b/test/unit/fixtures/tag.fixture.ts index 13f908a..9b191c7 100644 --- a/test/unit/fixtures/tag.fixture.ts +++ b/test/unit/fixtures/tag.fixture.ts @@ -2,6 +2,7 @@ import { Tag } from '../../../src/tag'; export interface ITagTestContext { tags: Tag[]; + tagPolicy: string[][]; invalid: Tag[]; } @@ -12,8 +13,13 @@ export const tagContextFixture: ITagTestContext = { new Tag('latest'), new Tag('v1-rc1'), new Tag('v1-beta'), + new Tag('alpha'), + new Tag('beta'), + new Tag('rc1'), ], + tagPolicy: [['^S*-rcd$'], ['alpha', 'beta'], ['latest']], + invalid: [ // @ts-expect-error: Let's ignore a type error, it's required for testing new Tag(), diff --git a/test/unit/tag.test.ts b/test/unit/tag.test.ts index 73bae36..379e870 100644 --- a/test/unit/tag.test.ts +++ b/test/unit/tag.test.ts @@ -1,14 +1,32 @@ -import { describe, it, expect, beforeEach } from 'vitest'; +import { describe, it, expect, beforeEach, test } from 'vitest'; import { tagContextFixture, ITagTestContext } from './fixtures/tag.fixture'; 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(item => expect(item).toBeDefined()); - }); + 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())); + + test('isFreezed()', context => + context.tags.map(tagsItem => + context.tagPolicy.map(tagPolicyItem => + expect(tagsItem.isFreezed(tagPolicyItem)).toMatchSnapshot() + ) + )); });