Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmurphy committed Aug 10, 2023
1 parent 7ef37f3 commit 31afeba
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
26 changes: 26 additions & 0 deletions __tests__/config.test.ts
Expand Up @@ -171,3 +171,29 @@ describe('licenses that are not valid SPDX licenses', () => {
)
})
})

test('it parses the comment-summary-in-pr input', async () => {
setInput('comment-summary-in-pr', 'true')
let config = await readConfig()
expect(config.comment_summary_in_pr).toBe('always')

clearInputs()
setInput('comment-summary-in-pr', 'false')
config = await readConfig()
expect(config.comment_summary_in_pr).toBe('never')

clearInputs()
setInput('comment-summary-in-pr', 'always')
config = await readConfig()
expect(config.comment_summary_in_pr).toBe('always')

clearInputs()
setInput('comment-summary-in-pr', 'never')
config = await readConfig()
expect(config.comment_summary_in_pr).toBe('never')

clearInputs()
setInput('comment-summary-in-pr', 'on-failure')
config = await readConfig()
expect(config.comment_summary_in_pr).toBe('on-failure')
})
2 changes: 1 addition & 1 deletion __tests__/summary.test.ts
Expand Up @@ -26,7 +26,7 @@ const defaultConfig: ConfigurationOptions = {
deny_licenses: [],
deny_packages: [],
deny_groups: [],
comment_summary_in_pr: 'never'
comment_summary_in_pr: true
}

const changesWithEmptyManifests: Changes = [
Expand Down
24 changes: 10 additions & 14 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/schemas.ts
Expand Up @@ -2,11 +2,6 @@ import * as z from 'zod'

export const SEVERITIES = ['critical', 'high', 'moderate', 'low'] as const
export const SCOPES = ['unknown', 'runtime', 'development'] as const
export const COMMENT_SUMMARY_OPTIONS = [
'always',
'never',
'on-failure'
] as const

export const SeveritySchema = z.enum(SEVERITIES).default('low')

Expand Down Expand Up @@ -55,7 +50,13 @@ export const ConfigurationOptionsSchema = z
base_ref: z.string().optional(),
head_ref: z.string().optional(),
comment_summary_in_pr: z
.union([z.boolean(), z.enum(COMMENT_SUMMARY_OPTIONS)])
.union([
z.preprocess(
val => (val === 'true' ? true : val === 'false' ? false : val),
z.boolean()
),
z.enum(['always', 'never', 'on-failure'])
])
.default('never')
})
.transform(config => {
Expand Down

0 comments on commit 31afeba

Please sign in to comment.