11import { describe , expect , test } from 'vitest'
22
33import { filterByAllowlistValues , filterAndUpdateGhesDataByAllowlistValues } from '../../lib'
4+ import type { RawAuditLogEventT , VersionedAuditLogData } from '../../types'
45
56describe ( '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