@@ -296,6 +296,59 @@ describe("Integration", () => {
296296 } ) . pipe ( Effect . provide ( connectionLayer ( created ) ) )
297297 } )
298298
299+ it . effect ( "completes legacy success callback OAuth and translates it to Credential.Value" , ( ) => {
300+ const created : Array < {
301+ integrationID : Integration . ID
302+ label ?: string
303+ value : Credential . Info
304+ } > = [ ]
305+ return Effect . gen ( function * ( ) {
306+ const integrations = yield * Integration . Service
307+ const integrationID = Integration . ID . make ( "openai" )
308+ const methodID = Integration . MethodID . make ( "legacy" )
309+ yield * integrations . update ( ( editor ) =>
310+ editor . method . update ( {
311+ integrationID,
312+ method : new Integration . OAuthMethod ( { id : methodID , type : "oauth" , label : "Legacy" } ) ,
313+ authorize : ( ) =>
314+ Effect . succeed ( {
315+ mode : "auto" as const ,
316+ url : "https://example.com/authorize" ,
317+ instructions : "Sign in" ,
318+ callback : Effect . succeed ( {
319+ type : "success" ,
320+ access : "token-legacy" ,
321+ refresh : "refresh-legacy" ,
322+ expires : 100 ,
323+ accountId : "legacy-client-id" ,
324+ enterpriseUrl : "legacy-client-secret" ,
325+ metadata : { customField : "val" } ,
326+ } as any ) ,
327+ } ) ,
328+ } ) ,
329+ )
330+
331+ const attempt = yield * integrations . connect . oauth ( { integrationID, methodID, inputs : { } } )
332+ yield * Effect . yieldNow
333+ expect ( yield * integrations . attempt . status ( attempt . attemptID ) ) . toEqual ( {
334+ status : "complete" ,
335+ time : attempt . time ,
336+ } )
337+ expect ( created ) . toHaveLength ( 1 )
338+ expect ( created [ 0 ] . value . type ) . toBe ( "oauth" )
339+ if ( created [ 0 ] . value . type === "oauth" ) {
340+ expect ( created [ 0 ] . value . access ) . toBe ( "token-legacy" )
341+ expect ( created [ 0 ] . value . refresh ) . toBe ( "refresh-legacy" )
342+ expect ( created [ 0 ] . value . expires ) . toBe ( 100 )
343+ expect ( created [ 0 ] . value . metadata ) . toEqual ( {
344+ clientId : "legacy-client-id" ,
345+ clientSecret : "legacy-client-secret" ,
346+ customField : "val" ,
347+ } )
348+ }
349+ } ) . pipe ( Effect . provide ( connectionLayer ( created ) ) )
350+ } )
351+
299352 it . effect ( "expires abandoned OAuth attempts" , ( ) => {
300353 const created : Array < {
301354 integrationID : Integration . ID
0 commit comments