diff --git a/src/audit-logs/tests/rendering.js b/src/audit-logs/tests/rendering.ts similarity index 99% rename from src/audit-logs/tests/rendering.js rename to src/audit-logs/tests/rendering.ts index 42bd0d585f..84f7f9a320 100644 --- a/src/audit-logs/tests/rendering.js +++ b/src/audit-logs/tests/rendering.ts @@ -20,7 +20,7 @@ describe('audit log events docs', () => { path: '/authentication/keeping-your-account-and-data-secure/security-log-events', type: 'user', }, - ] + ] as const // This test ensures that the audit log event page components and Markdown // file are in sync. Additionally, it checks all event categories are @@ -32,7 +32,7 @@ describe('audit log events docs', () => { // the enterprise events page has no FPT versioned audit log data if (page.type === 'enterprise' && version === 'free-pro-team@latest') continue - const auditLogEvents = getCategorizedAuditLogEvents(page.type, version, true) + const auditLogEvents = getCategorizedAuditLogEvents(page.type, version) if (Object.keys(auditLogEvents).length === 0) { console.warn(`There are no audit log events for ${page.path} with version '${version}'.`) diff --git a/src/audit-logs/tests/unit/filter-events.js b/src/audit-logs/tests/unit/filter-events.ts similarity index 72% rename from src/audit-logs/tests/unit/filter-events.js rename to src/audit-logs/tests/unit/filter-events.ts index 626779a028..40d4bea2a6 100644 --- a/src/audit-logs/tests/unit/filter-events.js +++ b/src/audit-logs/tests/unit/filter-events.ts @@ -1,70 +1,90 @@ import { describe, expect, test } from 'vitest' import { filterByAllowlistValues, filterAndUpdateGhesDataByAllowlistValues } from '../../lib' +import type { RawAuditLogEventT, VersionedAuditLogData } from '../../types' describe('audit log event fitering', () => { test('matches single allowlist value', () => { - const eventsToProcess = [ + const eventsToProcess: RawAuditLogEventT[] = [ { action: 'repo.create', _allowlists: ['user'], description: 'repo was created', + docs_reference_links: '', + ghes: {}, }, ] - const filteredEvents = filterByAllowlistValues(eventsToProcess, 'user') + const filteredEvents = filterByAllowlistValues(eventsToProcess, 'user', [], { + sha: '', + appendedDescriptions: {}, + }) expect(filteredEvents[0].action).toEqual('repo.create') }) test('matches multiple allowlist values', () => { - const eventsToProcess = [ + const eventsToProcess: RawAuditLogEventT[] = [ { action: 'repo.create', _allowlists: ['user'], description: 'repo was created', + docs_reference_links: '', + ghes: {}, }, { action: 'repo.delete', _allowlists: ['organization'], description: 'repo was deleted', + docs_reference_links: '', + ghes: {}, }, ] - const filteredEvents = filterByAllowlistValues(eventsToProcess, ['user', 'organization']) + const filteredEvents = filterByAllowlistValues(eventsToProcess, ['user', 'organization'], [], { + sha: '', + appendedDescriptions: {}, + }) expect(filteredEvents[0].action).toEqual('repo.create') expect(filteredEvents.length).toEqual(2) }) test('does not match non-matching allowlist value', () => { - const eventsToProcess = [ + const eventsToProcess: RawAuditLogEventT[] = [ { action: 'repo.create', _allowlists: ['user'], description: 'repo was created', + docs_reference_links: '', + ghes: {}, }, ] - const filteredEvents = filterByAllowlistValues(eventsToProcess, 'organization') + const filteredEvents = filterByAllowlistValues(eventsToProcess, 'organization', [], { + sha: '', + appendedDescriptions: {}, + }) expect(filteredEvents.length).toBe(0) }) test('ghes filters and updates multiple ghes versions', () => { - const eventsToProcess = [ + const eventsToProcess: RawAuditLogEventT[] = [ { action: 'repo.create', description: 'repo was created', + docs_reference_links: '', + _allowlists: [], ghes: { '3.10': { _allowlists: ['user'], }, - 3.11: { + '3.11': { _allowlists: ['user'], }, }, }, ] - const currentEvents = { + const currentEvents: VersionedAuditLogData = { 'ghes-3.11': { organization: [ { @@ -90,10 +110,13 @@ describe('audit log event fitering', () => { eventsToProcess, 'user', currentEvents, - {}, + { + sha: '', + appendedDescriptions: {}, + }, auditLogPage, ) - const getActions = (version) => + const getActions = (version: string) => currentEvents[version][auditLogPage].map((event) => event.action) expect(getActions('ghes-3.10').includes('repo.create')).toBe(true) expect(getActions('ghes-3.11').includes('repo.create')).toBe(true)