@@ -13,7 +13,7 @@ import githubEventsToS3 from '../../src/call/github-events-to-s3';
13
13
14
14
jest . mock ( '@aws-sdk/client-s3' ) ;
15
15
16
- describe ( 'githubWorkflowRunsMonitor ' , ( ) => {
16
+ describe ( 'githubEventsToS3 ' , ( ) => {
17
17
let app : Probot ;
18
18
let context : any ;
19
19
let resource : any ;
@@ -53,6 +53,10 @@ describe('githubWorkflowRunsMonitor', () => {
53
53
( S3Client as jest . Mock ) . mockImplementation ( ( ) => mockS3Client ) ;
54
54
} ) ;
55
55
56
+ afterEach ( ( ) => {
57
+ jest . clearAllMocks ( ) ;
58
+ } ) ;
59
+
56
60
it ( 'should upload to S3 on event listened' , async ( ) => {
57
61
mockS3Client . send . mockResolvedValue ( { } ) ;
58
62
@@ -69,4 +73,55 @@ describe('githubWorkflowRunsMonitor', () => {
69
73
70
74
expect ( app . log . error ) . toHaveBeenCalledWith ( 'Error uploading GitHub Event to S3 : Error: S3 error' ) ;
71
75
} ) ;
76
+
77
+ it ( 'S3 key name set with action' , async ( ) => {
78
+ context = {
79
+ name : 'name' ,
80
+ id : 'id' ,
81
+ payload : {
82
+ repository : {
83
+ name : 'repo' ,
84
+ owner : { login : 'org' } ,
85
+ } ,
86
+ action : 'action' ,
87
+ } ,
88
+ } ;
89
+
90
+ jest . spyOn ( Date . prototype , 'getDate' ) . mockReturnValue ( 4 ) ;
91
+ jest . spyOn ( Date . prototype , 'getMonth' ) . mockReturnValue ( 8 ) ;
92
+ jest . spyOn ( Date . prototype , 'getFullYear' ) . mockReturnValue ( 2024 ) ;
93
+
94
+ await githubEventsToS3 ( app , context , resource ) ;
95
+
96
+ expect ( PutObjectCommand ) . toHaveBeenCalledWith (
97
+ expect . objectContaining ( {
98
+ Key : expect . stringMatching ( `name.action/2024-09-04/repo-id` ) ,
99
+ } ) ,
100
+ ) ;
101
+ } ) ;
102
+
103
+ it ( 'S3 key name set without action' , async ( ) => {
104
+ context = {
105
+ name : 'name' ,
106
+ id : 'id' ,
107
+ payload : {
108
+ repository : {
109
+ name : 'repo' ,
110
+ owner : { login : 'org' } ,
111
+ } ,
112
+ } ,
113
+ } ;
114
+
115
+ jest . spyOn ( Date . prototype , 'getDate' ) . mockReturnValue ( 4 ) ;
116
+ jest . spyOn ( Date . prototype , 'getMonth' ) . mockReturnValue ( 8 ) ;
117
+ jest . spyOn ( Date . prototype , 'getFullYear' ) . mockReturnValue ( 2024 ) ;
118
+
119
+ await githubEventsToS3 ( app , context , resource ) ;
120
+
121
+ expect ( PutObjectCommand ) . toHaveBeenCalledWith (
122
+ expect . objectContaining ( {
123
+ Key : expect . stringMatching ( `name/2024-09-04/repo-id` ) ,
124
+ } ) ,
125
+ ) ;
126
+ } ) ;
72
127
} ) ;
0 commit comments