@@ -26,7 +26,10 @@ const refreshBasicViewEvent: RefreshBasicViewEvent = {
26
26
} ,
27
27
timezoneWithAppId : {
28
28
appId : 'app1' ,
29
- timezone : 'America/Noronha' ,
29
+ timezone : 'UTC' ,
30
+ } ,
31
+ originalInput : {
32
+ refreshStartTime : '' ,
30
33
} ,
31
34
} ;
32
35
@@ -62,8 +65,86 @@ describe('Lambda - do refresh job in Redshift Serverless', () => {
62
65
} ) ;
63
66
} ) ;
64
67
68
+ test ( 'Executed Redshift refresh custom-mv command' , async ( ) => {
69
+ const exeuteId = 'Id-1' ;
70
+ refreshBasicViewEvent . view . type = 'custom-mv' ;
71
+ refreshBasicViewEvent . originalInput = {
72
+ refreshStartTime : '1715470905000' ,
73
+ } ;
74
+ jest
75
+ . useFakeTimers ( )
76
+ . setSystemTime ( 1715490905000 ) ;
77
+ const dataFreshnessInHour = 6 ;
78
+ redshiftDataMock . on ( ExecuteStatementCommand ) . resolvesOnce ( { Id : exeuteId } ) ;
79
+ const resp = await handler ( refreshBasicViewEvent ) ;
80
+ expect ( resp ) . toEqual ( {
81
+ detail : {
82
+ viewName : refreshBasicViewEvent . view . name ,
83
+ queryId : exeuteId ,
84
+ } ,
85
+ timezoneWithAppId : refreshBasicViewEvent . timezoneWithAppId ,
86
+ } ) ;
87
+ expect ( redshiftDataMock ) . toHaveReceivedCommandWith ( ExecuteStatementCommand , {
88
+ WorkgroupName : workGroupName ,
89
+ Sql : `CALL ${ refreshBasicViewEvent . timezoneWithAppId . appId } .${ refreshBasicViewEvent . view . name } (NULL, NULL, ${ dataFreshnessInHour } );` ,
90
+ Database : expect . any ( String ) ,
91
+ } ) ;
92
+ jest . useRealTimers ( ) ;
93
+ } ) ;
94
+
95
+ test ( 'Executed Redshift refresh custom-mv command with RefreshStartTime bigger than current' , async ( ) => {
96
+ const exeuteId = 'Id-1' ;
97
+ refreshBasicViewEvent . view . type = 'custom-mv' ;
98
+ refreshBasicViewEvent . originalInput = {
99
+ refreshStartTime : '1715470905000' ,
100
+ } ;
101
+ jest
102
+ . useFakeTimers ( )
103
+ . setSystemTime ( 1715450905000 ) ;
104
+ const dataFreshnessInHour = 72 ;
105
+ redshiftDataMock . on ( ExecuteStatementCommand ) . resolvesOnce ( { Id : exeuteId } ) ;
106
+ const resp = await handler ( refreshBasicViewEvent ) ;
107
+ expect ( resp ) . toEqual ( {
108
+ detail : {
109
+ viewName : refreshBasicViewEvent . view . name ,
110
+ queryId : exeuteId ,
111
+ } ,
112
+ timezoneWithAppId : refreshBasicViewEvent . timezoneWithAppId ,
113
+ } ) ;
114
+ expect ( redshiftDataMock ) . toHaveReceivedCommandWith ( ExecuteStatementCommand , {
115
+ WorkgroupName : workGroupName ,
116
+ Sql : `CALL ${ refreshBasicViewEvent . timezoneWithAppId . appId } .${ refreshBasicViewEvent . view . name } (NULL, NULL, ${ dataFreshnessInHour } );` ,
117
+ Database : expect . any ( String ) ,
118
+ } ) ;
119
+ jest . useRealTimers ( ) ;
120
+ } ) ;
121
+
122
+ test ( 'Executed Redshift refresh custom-mv command without input refreshStartTime' , async ( ) => {
123
+ const exeuteId = 'Id-1' ;
124
+ refreshBasicViewEvent . view . type = 'custom-mv' ;
125
+ refreshBasicViewEvent . originalInput = {
126
+ refreshStartTime : '' ,
127
+ } ;
128
+ const dataFreshnessInHour = 72 ;
129
+ redshiftDataMock . on ( ExecuteStatementCommand ) . resolvesOnce ( { Id : exeuteId } ) ;
130
+ const resp = await handler ( refreshBasicViewEvent ) ;
131
+ expect ( resp ) . toEqual ( {
132
+ detail : {
133
+ viewName : refreshBasicViewEvent . view . name ,
134
+ queryId : exeuteId ,
135
+ } ,
136
+ timezoneWithAppId : refreshBasicViewEvent . timezoneWithAppId ,
137
+ } ) ;
138
+ expect ( redshiftDataMock ) . toHaveReceivedCommandWith ( ExecuteStatementCommand , {
139
+ WorkgroupName : workGroupName ,
140
+ Sql : `CALL ${ refreshBasicViewEvent . timezoneWithAppId . appId } .${ refreshBasicViewEvent . view . name } (NULL, NULL, ${ dataFreshnessInHour } );` ,
141
+ Database : expect . any ( String ) ,
142
+ } ) ;
143
+ } ) ;
144
+
65
145
test ( 'Execute command error in Redshift when doing refresh' , async ( ) => {
66
146
redshiftDataMock . on ( ExecuteStatementCommand ) . rejects ( ) ;
147
+ refreshBasicViewEvent . view . type = 'basic' ;
67
148
try {
68
149
await handler ( refreshBasicViewEvent ) ;
69
150
fail ( 'The error in executing statement of Redshift data was caught' ) ;
@@ -79,7 +160,6 @@ describe('Lambda - do refresh job in Redshift Serverless', () => {
79
160
redshiftDataMock . on ( ExecuteStatementCommand )
80
161
. rejectsOnce ( )
81
162
. resolves ( { Id : exeuteId } ) ;
82
-
83
163
const resp = await handler ( refreshBasicViewEvent ) ;
84
164
expect ( resp ) . toEqual ( {
85
165
detail : {
0 commit comments