1
0
Fork 0
toolkit/packages/artifact/__tests__/retention.test.ts

66 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

2023-08-10 00:42:14 +00:00
import {Timestamp} from '../src/generated'
import * as retention from '../src/internal/upload/retention'
describe('retention', () => {
beforeEach(() => {
delete process.env['GITHUB_RETENTION_DAYS']
})
it('should return the inputted retention days if it is less than the max retention days', () => {
// setup
const mockDate = new Date('2020-01-01')
jest.useFakeTimers().setSystemTime(mockDate)
process.env['GITHUB_RETENTION_DAYS'] = '90'
const exp = retention.getExpiration(30)
expect(exp).toBeDefined()
2023-08-10 00:48:53 +00:00
if (exp) {
const expDate = Timestamp.toDate(exp)
const expected = new Date()
expected.setDate(expected.getDate() + 30)
2023-08-10 00:42:14 +00:00
2023-08-10 00:48:53 +00:00
expect(expDate).toEqual(expected)
}
2023-08-10 00:42:14 +00:00
})
it('should return the max retention days if the inputted retention days is greater than the max retention days', () => {
// setup
const mockDate = new Date('2020-01-01')
jest.useFakeTimers().setSystemTime(mockDate)
process.env['GITHUB_RETENTION_DAYS'] = '90'
const exp = retention.getExpiration(120)
expect(exp).toBeDefined()
2023-08-10 00:48:53 +00:00
if (exp) {
const expDate = Timestamp.toDate(exp) // we check whether exp is defined above
const expected = new Date()
expected.setDate(expected.getDate() + 90)
2023-08-10 00:42:14 +00:00
2023-08-10 00:48:53 +00:00
expect(expDate).toEqual(expected)
}
2023-08-10 00:42:14 +00:00
})
it('should return undefined if the inputted retention days is undefined', () => {
const exp = retention.getExpiration()
expect(exp).toBeUndefined()
})
it('should return the inputted retention days if there is no max retention days', () => {
// setup
const mockDate = new Date('2020-01-01')
jest.useFakeTimers().setSystemTime(mockDate)
const exp = retention.getExpiration(30)
expect(exp).toBeDefined()
2023-08-10 00:48:53 +00:00
if (exp) {
const expDate = Timestamp.toDate(exp) // we check whether exp is defined above
const expected = new Date()
expected.setDate(expected.getDate() + 30)
2023-08-10 00:42:14 +00:00
2023-08-10 00:48:53 +00:00
expect(expDate).toEqual(expected)
}
2023-08-10 00:42:14 +00:00
})
})