Skip to content

Commit

Permalink
test: improve domain coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrunton committed Jan 13, 2023
1 parent e8109ce commit d10c23f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
19 changes: 19 additions & 0 deletions __tests__/entities/policies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {isValidTTL} from '@entities/policies'

describe('isValidTTL', () => {
it('returns true for valid TTL policies', () => {
expect(isValidTTL({days: 1})).toEqual(true)
expect(isValidTTL({hours: 1})).toEqual(true)
expect(isValidTTL({minutes: 1})).toEqual(true)
})

it('treats 0 time units as valid', () => {
expect(isValidTTL({days: 0})).toEqual(true)
expect(isValidTTL({hours: 0})).toEqual(true)
expect(isValidTTL({minutes: 0})).toEqual(true)
})

it('returns false for invalid TTL policies', () => {
expect(isValidTTL({})).toEqual(false)
})
})
10 changes: 10 additions & 0 deletions __tests__/usecases/checks/stack-age-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ describe('StackAgeCheck', () => {
})
})

it('passes when the stack is exactly the age of the ttl policy', async () => {
const threeHoursAgo = sub(now, {hours: 3, minutes: 30})
const result = await check(stack(threeHoursAgo))
expect(result).toEqual({
isLegacy: false,
description:
'checked stack age [2021-01-01T08:30:00.000Z] against ttl [3 hours 30 minutes]'
})
})

it('fails when the stack is older than the ttl policy', async () => {
const fourHoursAgo = sub(now, {hours: 4})
const result = await check(stack(fourHoursAgo))
Expand Down
4 changes: 2 additions & 2 deletions __tests__/usecases/parse-policies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('parsePolicies', () => {
it('parses valid yaml', () => {
const yaml = `
policies:
clean-staging:
clean-dev:
match:
tags:
environment: 'dev*'
Expand All @@ -20,7 +20,7 @@ describe('parsePolicies', () => {
const policy = parsePolicies(yaml)
expect(policy).toEqual([
{
name: 'clean-staging',
name: 'clean-dev',
match: {
tags: [{pattern: 'dev*', tag: 'environment'}]
},
Expand Down

0 comments on commit d10c23f

Please sign in to comment.