forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversions.js
More file actions
48 lines (39 loc) · 1.63 KB
/
versions.js
File metadata and controls
48 lines (39 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { jest } from '@jest/globals'
import Ajv from 'ajv'
import { allVersions } from '../../lib/all-versions.js'
import { latest } from '../../lib/enterprise-server-releases.js'
import schema from '../helpers/schemas/versions-schema.js'
import nonEnterpriseDefaultVersion from '../../lib/non-enterprise-default-version.js'
import { formatAjvErrors } from '../helpers/schemas.js'
jest.useFakeTimers({ legacyFakeTimers: true })
const ajv = new Ajv({ allErrors: true })
const validate = ajv.compile(schema)
describe('versions module', () => {
test('is an object with versions as keys', () => {
expect(nonEnterpriseDefaultVersion in allVersions).toBe(true)
expect(`enterprise-server@${latest}` in allVersions).toBe(true)
})
test('every version is valid', () => {
Object.values(allVersions).forEach((versionObj) => {
const valid = validate(versionObj)
let errors
if (!valid) {
errors = `version '${versionObj.version}': ${formatAjvErrors(validate.errors)}`
}
expect(valid, errors).toBe(true)
})
})
test('check REST api calendar date versioned versions set to correct latestApiVersion', () => {
Object.values(allVersions).forEach((versionObj) => {
if (versionObj.apiVersions.length > 0) {
const latestApiVersion = versionObj.latestApiVersion
const apiVersions = versionObj.apiVersions
expect(apiVersions).toContain(latestApiVersion)
const latestApiDate = new Date(latestApiVersion).getTime()
for (const version of apiVersions) {
expect(latestApiDate).toBeGreaterThanOrEqual(new Date(version).getTime())
}
}
})
})
})