Skip to content

Commit e3b78a6

Browse files
authored
Convert audit-logs JS files to TypeScript (#55597)
1 parent b7ae01e commit e3b78a6

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('audit log events docs', () => {
2020
path: '/authentication/keeping-your-account-and-data-secure/security-log-events',
2121
type: 'user',
2222
},
23-
]
23+
] as const
2424

2525
// This test ensures that the audit log event page components and Markdown
2626
// file are in sync. Additionally, it checks all event categories are
@@ -32,7 +32,7 @@ describe('audit log events docs', () => {
3232
// the enterprise events page has no FPT versioned audit log data
3333
if (page.type === 'enterprise' && version === 'free-pro-team@latest') continue
3434

35-
const auditLogEvents = getCategorizedAuditLogEvents(page.type, version, true)
35+
const auditLogEvents = getCategorizedAuditLogEvents(page.type, version)
3636

3737
if (Object.keys(auditLogEvents).length === 0) {
3838
console.warn(`There are no audit log events for ${page.path} with version '${version}'.`)

src/audit-logs/tests/unit/filter-events.js renamed to src/audit-logs/tests/unit/filter-events.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,90 @@
11
import { describe, expect, test } from 'vitest'
22

33
import { filterByAllowlistValues, filterAndUpdateGhesDataByAllowlistValues } from '../../lib'
4+
import type { RawAuditLogEventT, VersionedAuditLogData } from '../../types'
45

56
describe('audit log event fitering', () => {
67
test('matches single allowlist value', () => {
7-
const eventsToProcess = [
8+
const eventsToProcess: RawAuditLogEventT[] = [
89
{
910
action: 'repo.create',
1011
_allowlists: ['user'],
1112
description: 'repo was created',
13+
docs_reference_links: '',
14+
ghes: {},
1215
},
1316
]
1417

15-
const filteredEvents = filterByAllowlistValues(eventsToProcess, 'user')
18+
const filteredEvents = filterByAllowlistValues(eventsToProcess, 'user', [], {
19+
sha: '',
20+
appendedDescriptions: {},
21+
})
1622
expect(filteredEvents[0].action).toEqual('repo.create')
1723
})
1824

1925
test('matches multiple allowlist values', () => {
20-
const eventsToProcess = [
26+
const eventsToProcess: RawAuditLogEventT[] = [
2127
{
2228
action: 'repo.create',
2329
_allowlists: ['user'],
2430
description: 'repo was created',
31+
docs_reference_links: '',
32+
ghes: {},
2533
},
2634
{
2735
action: 'repo.delete',
2836
_allowlists: ['organization'],
2937
description: 'repo was deleted',
38+
docs_reference_links: '',
39+
ghes: {},
3040
},
3141
]
3242

33-
const filteredEvents = filterByAllowlistValues(eventsToProcess, ['user', 'organization'])
43+
const filteredEvents = filterByAllowlistValues(eventsToProcess, ['user', 'organization'], [], {
44+
sha: '',
45+
appendedDescriptions: {},
46+
})
3447
expect(filteredEvents[0].action).toEqual('repo.create')
3548
expect(filteredEvents.length).toEqual(2)
3649
})
3750

3851
test('does not match non-matching allowlist value', () => {
39-
const eventsToProcess = [
52+
const eventsToProcess: RawAuditLogEventT[] = [
4053
{
4154
action: 'repo.create',
4255
_allowlists: ['user'],
4356
description: 'repo was created',
57+
docs_reference_links: '',
58+
ghes: {},
4459
},
4560
]
4661

47-
const filteredEvents = filterByAllowlistValues(eventsToProcess, 'organization')
62+
const filteredEvents = filterByAllowlistValues(eventsToProcess, 'organization', [], {
63+
sha: '',
64+
appendedDescriptions: {},
65+
})
4866
expect(filteredEvents.length).toBe(0)
4967
})
5068

5169
test('ghes filters and updates multiple ghes versions', () => {
52-
const eventsToProcess = [
70+
const eventsToProcess: RawAuditLogEventT[] = [
5371
{
5472
action: 'repo.create',
5573
description: 'repo was created',
74+
docs_reference_links: '',
75+
_allowlists: [],
5676
ghes: {
5777
'3.10': {
5878
_allowlists: ['user'],
5979
},
60-
3.11: {
80+
'3.11': {
6181
_allowlists: ['user'],
6282
},
6383
},
6484
},
6585
]
6686

67-
const currentEvents = {
87+
const currentEvents: VersionedAuditLogData = {
6888
'ghes-3.11': {
6989
organization: [
7090
{
@@ -90,10 +110,13 @@ describe('audit log event fitering', () => {
90110
eventsToProcess,
91111
'user',
92112
currentEvents,
93-
{},
113+
{
114+
sha: '',
115+
appendedDescriptions: {},
116+
},
94117
auditLogPage,
95118
)
96-
const getActions = (version) =>
119+
const getActions = (version: string) =>
97120
currentEvents[version][auditLogPage].map((event) => event.action)
98121
expect(getActions('ghes-3.10').includes('repo.create')).toBe(true)
99122
expect(getActions('ghes-3.11').includes('repo.create')).toBe(true)

0 commit comments

Comments
 (0)