@@ -47,3 +47,60 @@ postgresTest("ignores a soft-deleted Slack integration", async ({ prisma }) => {
4747 ) . toBeNull ( ) ;
4848 expect ( await findSlackIntegration ( prisma , { organizationId : organization . id } ) ) . toBeNull ( ) ;
4949} ) ;
50+
51+ postgresTest (
52+ "resolves a soft-deleted integration by id when includeDeleted is set" ,
53+ async ( { prisma } ) => {
54+ const { organization, integration } = await seed ( prisma , true ) ;
55+
56+ const byId = await findSlackIntegration (
57+ prisma ,
58+ { integrationId : integration . id , organizationId : organization . id } ,
59+ { includeDeleted : true }
60+ ) ;
61+
62+ expect ( byId ?. id ) . toBe ( integration . id ) ;
63+ }
64+ ) ;
65+
66+ postgresTest (
67+ "resolves a soft-deleted integration by organization when includeDeleted is set" ,
68+ async ( { prisma } ) => {
69+ const { organization, integration } = await seed ( prisma , true ) ;
70+
71+ const byOrg = await findSlackIntegration (
72+ prisma ,
73+ { organizationId : organization . id } ,
74+ { includeDeleted : true }
75+ ) ;
76+
77+ expect ( byOrg ?. id ) . toBe ( integration . id ) ;
78+ }
79+ ) ;
80+
81+ postgresTest (
82+ "prefers an older live integration over a newer soft-deleted one when includeDeleted is set" ,
83+ async ( { prisma } ) => {
84+ const { organization, integration : live } = await seed ( prisma , false ) ;
85+ const secret = await prisma . secretReference . create ( { data : { key : "slack-lookup-token-2" } } ) ;
86+ await prisma . organizationIntegration . create ( {
87+ data : {
88+ friendlyId : generateFriendlyId ( "org_integration" ) ,
89+ service : "SLACK" ,
90+ integrationData : { } ,
91+ tokenReferenceId : secret . id ,
92+ organizationId : organization . id ,
93+ createdAt : new Date ( Date . now ( ) + 60_000 ) ,
94+ deletedAt : new Date ( ) ,
95+ } ,
96+ } ) ;
97+
98+ const byOrg = await findSlackIntegration (
99+ prisma ,
100+ { organizationId : organization . id } ,
101+ { includeDeleted : true }
102+ ) ;
103+
104+ expect ( byOrg ?. id ) . toBe ( live . id ) ;
105+ }
106+ ) ;
0 commit comments