@@ -1102,4 +1102,136 @@ describe("buildFromV1Alpha", () => {
11021102 expect ( parsed ) . to . deep . equal ( expected ) ;
11031103 } ) ;
11041104 } ) ;
1105+
1106+ describe ( "lifecycleHooks" , ( ) => {
1107+ it ( "copies valid task lifecycle hooks" , ( ) => {
1108+ const yaml : v1alpha1 . WireManifest = {
1109+ specVersion : "v1alpha1" ,
1110+ endpoints : { } ,
1111+ lifecycleHooks : {
1112+ afterInstall : {
1113+ task : {
1114+ function : "myTaskFunc" ,
1115+ body : { key : "value" } ,
1116+ } ,
1117+ } ,
1118+ } ,
1119+ } ;
1120+
1121+ const parsed = v1alpha1 . buildFromV1Alpha1 ( yaml , PROJECT , REGION , RUNTIME ) ;
1122+ const expected : build . Build = build . empty ( ) ;
1123+ expected . lifecycleHooks = {
1124+ afterInstall : {
1125+ task : {
1126+ function : "myTaskFunc" ,
1127+ body : { key : "value" } ,
1128+ } ,
1129+ } ,
1130+ } ;
1131+ expect ( parsed ) . to . deep . equal ( expected ) ;
1132+ } ) ;
1133+
1134+ it ( "copies valid callable lifecycle hooks" , ( ) => {
1135+ const yaml : v1alpha1 . WireManifest = {
1136+ specVersion : "v1alpha1" ,
1137+ endpoints : { } ,
1138+ lifecycleHooks : {
1139+ afterUpdate : {
1140+ callable : {
1141+ function : "myCallableFunc" ,
1142+ } ,
1143+ } ,
1144+ } ,
1145+ } ;
1146+
1147+ const parsed = v1alpha1 . buildFromV1Alpha1 ( yaml , PROJECT , REGION , RUNTIME ) ;
1148+ const expected : build . Build = build . empty ( ) ;
1149+ expected . lifecycleHooks = {
1150+ afterUpdate : {
1151+ callable : {
1152+ function : "myCallableFunc" ,
1153+ } ,
1154+ } ,
1155+ } ;
1156+ expect ( parsed ) . to . deep . equal ( expected ) ;
1157+ } ) ;
1158+
1159+ it ( "copies valid http lifecycle hooks" , ( ) => {
1160+ const yaml : v1alpha1 . WireManifest = {
1161+ specVersion : "v1alpha1" ,
1162+ endpoints : { } ,
1163+ lifecycleHooks : {
1164+ afterInstall : {
1165+ http : {
1166+ url : "https://example.com/hook" ,
1167+ body : "some-body" ,
1168+ } ,
1169+ } ,
1170+ } ,
1171+ } ;
1172+
1173+ const parsed = v1alpha1 . buildFromV1Alpha1 ( yaml , PROJECT , REGION , RUNTIME ) ;
1174+ const expected : build . Build = build . empty ( ) ;
1175+ expected . lifecycleHooks = {
1176+ afterInstall : {
1177+ http : {
1178+ url : "https://example.com/hook" ,
1179+ body : "some-body" ,
1180+ } ,
1181+ } ,
1182+ } ;
1183+ expect ( parsed ) . to . deep . equal ( expected ) ;
1184+ } ) ;
1185+
1186+ it ( "throws on invalid event type" , ( ) => {
1187+ const yaml = {
1188+ specVersion : "v1alpha1" ,
1189+ endpoints : { } ,
1190+ lifecycleHooks : {
1191+ invalidHookName : {
1192+ task : {
1193+ function : "myTaskFunc" ,
1194+ } ,
1195+ } ,
1196+ } ,
1197+ } ;
1198+
1199+ expect ( ( ) => v1alpha1 . buildFromV1Alpha1 ( yaml , PROJECT , REGION , RUNTIME ) ) . to . throw (
1200+ FirebaseError ,
1201+ / I n v a l i d e v e n t T y p e " i n v a l i d H o o k N a m e " f o r l i f e c y c l e h o o k / ,
1202+ ) ;
1203+ } ) ;
1204+
1205+ it ( "throws when target function is missing in task hook" , ( ) => {
1206+ const yaml = {
1207+ specVersion : "v1alpha1" ,
1208+ endpoints : { } ,
1209+ lifecycleHooks : {
1210+ afterInstall : {
1211+ task : { } ,
1212+ } ,
1213+ } ,
1214+ } ;
1215+
1216+ expect ( ( ) => v1alpha1 . buildFromV1Alpha1 ( yaml , PROJECT , REGION , RUNTIME ) ) . to . throw (
1217+ FirebaseError ,
1218+ / I n v a l i d t a r g e t " " f o r l i f e c y c l e h o o k " a f t e r I n s t a l l " / ,
1219+ ) ;
1220+ } ) ;
1221+
1222+ it ( "throws when action is missing" , ( ) => {
1223+ const yaml = {
1224+ specVersion : "v1alpha1" ,
1225+ endpoints : { } ,
1226+ lifecycleHooks : {
1227+ afterInstall : { } ,
1228+ } ,
1229+ } ;
1230+
1231+ expect ( ( ) => v1alpha1 . buildFromV1Alpha1 ( yaml , PROJECT , REGION , RUNTIME ) ) . to . throw (
1232+ FirebaseError ,
1233+ / N o a c t i o n \( t a s k , c a l l a b l e , o r h t t p \) s p e c i f i e d f o r l i f e c y c l e h o o k " a f t e r I n s t a l l " / ,
1234+ ) ;
1235+ } ) ;
1236+ } ) ;
11051237} ) ;
0 commit comments