Skip to content

Commit

Permalink
feat(cli): ChangelogCommand
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Oct 7, 2023
1 parent 8db3a7e commit 781362a
Show file tree
Hide file tree
Showing 15 changed files with 796 additions and 190 deletions.
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
outputs:
prerelease: ${{ steps.dist-tag.outputs.prerelease }}
tag: ${{ steps.tag.outputs.result }}
version: ${{ steps.version.outputs.result }}
steps:
- id: debug
name: Print environment variables and event payload
Expand Down
342 changes: 212 additions & 130 deletions CHANGELOG.md

Large diffs are not rendered by default.

215 changes: 215 additions & 0 deletions src/cli/commands/__tests__/changelog.command.functional.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/**
* @file Functional Tests - ChangelogCommand
* @module grease/cli/commands/tests/functional/ChangelogCommand
*/

import to from '#fixtures/git/grease/sha'
import GreaseService from '#src/grease.service'
import type { Mock } from '#tests/interfaces'
import { CliUtilityService } from '@flex-development/nest-commander'
import { CommandTestFactory } from '@flex-development/nest-commander/testing'
import type { TestingModule } from '@nestjs/testing'
import TestSubject from '../changelog.command'

describe('functional:cli/commands/ChangelogCommand', () => {
let args: ['changelog']
let changelog: Mock<GreaseService['changelog']>
let command: TestingModule

beforeAll(() => {
args = ['changelog']
})

beforeEach(async () => {
command = await CommandTestFactory.createTestingCommand({
providers: [
CliUtilityService,
TestSubject,
{
provide: GreaseService,
useValue: {
changelog: changelog = vi.fn().mockName('GreaseService#changelog')
}
}
]
})

vi.stubEnv('GREASE_CONFIG', '0')
})

describe('--infile, -i <path>', () => {
let infile: string

beforeAll(() => {
infile = 'CHANGELOG.md'
})

it('should parse flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, `--infile=${infile}`])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ infile })
})

it('should parse short flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, '-i', infile])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ infile })
})
})

describe('--outfile, -o <outfile>', () => {
let outfile: string

beforeAll(() => {
outfile = 'CHANGELOG.md'
})

it('should parse flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, `--outfile=${outfile}`])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ outfile })
})

it('should parse short flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, '-o', outfile])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ outfile })
})
})

describe('--releases, -r <count>', () => {
let releases: number

beforeAll(() => {
releases = 0
})

it('should parse flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, `--releases=${releases}`])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ releases })
})

it('should parse short flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, '-r', `${releases}`])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ releases })
})
})

describe('--samefile, -s', () => {
let samefile: boolean

beforeAll(() => {
samefile = true
})

it('should parse flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, '--samefile'])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ samefile })
})

it('should parse short flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, '-s'])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ samefile })
})
})

describe('--to, -t <commitish>', () => {
it('should parse flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, `--to=${to}`])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ to })
})

it('should parse short flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, '-t', to])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ to })
})
})

describe('--unstable, -u [choice]', () => {
let unstable: boolean

beforeAll(() => {
unstable = false
})

it('should parse flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, `--unstable=${unstable}`])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ unstable })
})

it('should parse short flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, '-u', '0'])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ unstable })
})
})

describe('--write, -w', () => {
let write: boolean

beforeAll(() => {
write = true
})

it('should parse flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, '--write'])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ write })
})

it('should parse short flag', async () => {
// Act
await CommandTestFactory.run(command, [...args, '-w'])

// Expect
expect(changelog).toHaveBeenCalledOnce()
expect(changelog.mock.lastCall?.[0]).toMatchObject({ write })
})
})
})
17 changes: 17 additions & 0 deletions src/cli/commands/changelog.command.opts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file Commands - ChangelogCommandOpts
* @module grease/commands/ChangelogCommandOpts
*/

import type { ChangelogOperation } from '#src/changelog'

/**
* Parsed `changelog` command options.
*
* @see {@linkcode ChangelogOperation}
*
* @extends {ChangelogOperation}
*/
interface ChangelogCommandOpts extends ChangelogOperation {}

export type { ChangelogCommandOpts as default }
Loading

0 comments on commit 781362a

Please sign in to comment.