@@ -1188,7 +1188,62 @@ example-com:
11881188 expect ( mockAck ) . to . have . been . calledOnce ;
11891189 } ) ;
11901190
1191- it ( 'should print error message if onboarding throws an error' , async ( ) => {
1191+ it ( 'should return immediately after ack without waiting for onboarding to complete' , async ( ) => {
1192+ const mockBody = {
1193+ view : {
1194+ state : {
1195+ values : {
1196+ brand_name_input : {
1197+ brand_name : { value : 'Test Brand' } ,
1198+ } ,
1199+ ims_org_input : {
1200+ ims_org_id : { value : 'ABC123@AdobeOrg' } ,
1201+ } ,
1202+ delivery_type_input : {
1203+ delivery_type : {
1204+ selected_option : { value : 'aem_edge' } ,
1205+ } ,
1206+ } ,
1207+ } ,
1208+ } ,
1209+ private_metadata : JSON . stringify ( {
1210+ originalChannel : 'C1234567890' ,
1211+ originalThreadTs : '1234567890.123456' ,
1212+ brandURL : 'https://example.com' ,
1213+ } ) ,
1214+ } ,
1215+ user : { id : 'U1234567890' } ,
1216+ } ;
1217+
1218+ const mockAck = sandbox . stub ( ) ;
1219+ const mockClient = {
1220+ chat : {
1221+ postMessage : sandbox . stub ( ) . resolves ( ) ,
1222+ } ,
1223+ } ;
1224+
1225+ // Create a slow onboarding process to verify fire-and-forget behavior
1226+ const lambdaCtx = createDefaultMockLambdaCtx ( sandbox ) ;
1227+ const slowOnboardingPromise = new Promise ( ( resolve ) => {
1228+ setTimeout ( resolve , 1000 ) ; // Simulate slow operation
1229+ } ) ;
1230+ lambdaCtx . dataAccess . Site . findByBaseURL = sandbox . stub ( ) . returns ( slowOnboardingPromise ) ;
1231+
1232+ const { onboardLLMOModal } = mockedModule ;
1233+ const handler = onboardLLMOModal ( lambdaCtx ) ;
1234+
1235+ const startTime = Date . now ( ) ;
1236+ await handler ( { ack : mockAck , body : mockBody , client : mockClient } ) ;
1237+ const endTime = Date . now ( ) ;
1238+
1239+ // Handler should return quickly (well under 1 second), not wait for the slow operation
1240+ expect ( endTime - startTime ) . to . be . lessThan ( 500 ) ;
1241+ expect ( mockAck ) . to . have . been . calledOnce ;
1242+ expect ( mockAck ) . to . have . been . calledWith ( ) ; // Called without errors
1243+ expect ( lambdaCtx . log . debug ) . to . have . been . calledWith ( 'Onboard LLMO modal processed for user U1234567890, site https://example.com' ) ;
1244+ } ) ;
1245+
1246+ it ( 'should log error if onboarding throws an error in background' , async ( ) => {
11921247 const mockBody = {
11931248 view : {
11941249 state : {
@@ -1224,13 +1279,20 @@ example-com:
12241279
12251280 await handler ( { ack : mockAck , body : mockBody , client : mockClient } ) ;
12261281
1227- expect ( lambdaCtx . log . error ) . to . have . been . calledWith ( 'Error handling onboard site modal:' , sinon . match . instanceOf ( Error ) ) ;
1228- expect ( mockAck ) . to . have . been . calledWith ( {
1229- response_action : 'errors' ,
1230- errors : {
1231- brand_name_input : 'There was an error processing the onboarding request.' ,
1232- } ,
1282+ // The handler should acknowledge successfully even if onboarding will fail
1283+ expect ( mockAck ) . to . have . been . calledOnce ;
1284+ expect ( mockAck ) . to . have . been . calledWith ( ) ;
1285+
1286+ // Wait a bit for the background promise to settle
1287+ await new Promise ( ( resolve ) => {
1288+ setTimeout ( resolve , 100 ) ;
12331289 } ) ;
1290+
1291+ // The error should be logged by the background error handler
1292+ expect ( lambdaCtx . log . error ) . to . have . been . calledWith (
1293+ sinon . match ( / E r r o r i n b a c k g r o u n d o n b o a r d i n g f o r s i t e / ) ,
1294+ sinon . match . instanceOf ( Error ) ,
1295+ ) ;
12341296 } ) ;
12351297
12361298 it ( 'should return validation error when IMS org ID is not provided' , async ( ) => {
0 commit comments