@@ -92,6 +92,7 @@ vi.mock('next/link', () => ({
9292// Mock next/navigation
9393vi . mock ( 'next/navigation' , ( ) => ( {
9494 useParams : ( ) => ( { orgId : 'org-1' } ) ,
95+ useRouter : ( ) => ( { push : vi . fn ( ) } ) ,
9596 useSearchParams : ( ) => new URLSearchParams ( ) ,
9697} ) ) ;
9798
@@ -143,9 +144,10 @@ vi.mock('lucide-react', () => ({
143144
144145// Mock sonner
145146vi . mock ( 'sonner' , ( ) => ( {
146- toast : { success : vi . fn ( ) , error : vi . fn ( ) } ,
147+ toast : { success : vi . fn ( ) , error : vi . fn ( ) , info : vi . fn ( ) } ,
147148} ) ) ;
148149
150+ import { toast } from 'sonner' ;
149151import { PlatformIntegrations } from './PlatformIntegrations' ;
150152
151153const defaultProps = {
@@ -202,4 +204,129 @@ describe('PlatformIntegrations', () => {
202204 expect ( screen . getByTestId ( 'search-input' ) ) . toBeInTheDocument ( ) ;
203205 } ) ;
204206 } ) ;
207+
208+ describe ( 'Employee sync import prompt' , ( ) => {
209+ it ( 'shows import prompt toast after Google Workspace OAuth callback' , async ( ) => {
210+ // Override mocks for this test to simulate OAuth callback
211+ const { useIntegrationProviders, useIntegrationConnections } = vi . mocked (
212+ await import ( '@/hooks/use-integration-platform' ) ,
213+ ) ;
214+
215+ vi . mocked ( useIntegrationProviders ) . mockReturnValue ( {
216+ providers : [
217+ {
218+ id : 'google-workspace' ,
219+ name : 'Google Workspace' ,
220+ description : 'Google Workspace admin' ,
221+ category : 'Identity & Access' ,
222+ logoUrl : '/google.png' ,
223+ authType : 'oauth2' ,
224+ oauthConfigured : true ,
225+ isActive : true ,
226+ requiredVariables : [ ] ,
227+ mappedTasks : [ ] ,
228+ supportsMultipleConnections : false ,
229+ } ,
230+ ] as any ,
231+ isLoading : false ,
232+ error : undefined ,
233+ refresh : vi . fn ( ) ,
234+ } ) ;
235+
236+ vi . mocked ( useIntegrationConnections ) . mockReturnValue ( {
237+ connections : [
238+ {
239+ id : 'conn-1' ,
240+ providerSlug : 'google-workspace' ,
241+ status : 'active' ,
242+ variables : null ,
243+ } ,
244+ ] as any ,
245+ isLoading : false ,
246+ error : undefined ,
247+ refresh : vi . fn ( ) ,
248+ } ) ;
249+
250+ // Mock useSearchParams to simulate OAuth callback
251+ const { useSearchParams : mockUseSearchParams } = vi . mocked (
252+ await import ( 'next/navigation' ) ,
253+ ) ;
254+ vi . mocked ( mockUseSearchParams ) . mockReturnValue (
255+ new URLSearchParams ( 'success=true&provider=google-workspace' ) as any ,
256+ ) ;
257+
258+ setMockPermissions ( ADMIN_PERMISSIONS ) ;
259+
260+ render ( < PlatformIntegrations { ...defaultProps } /> ) ;
261+
262+ expect ( toast . success ) . toHaveBeenCalledWith (
263+ 'Google Workspace connected successfully!' ,
264+ ) ;
265+ expect ( toast . info ) . toHaveBeenCalledWith (
266+ 'Import your Google Workspace users' ,
267+ expect . objectContaining ( {
268+ description : 'Go to People to import and sync your team members.' ,
269+ action : expect . objectContaining ( { label : 'Go to People' } ) ,
270+ } ) ,
271+ ) ;
272+ } ) ;
273+
274+ it ( 'does not show import prompt for non-sync providers' , async ( ) => {
275+ // Override mocks for this test to simulate OAuth callback for a non-sync provider
276+ const { useIntegrationProviders, useIntegrationConnections } = vi . mocked (
277+ await import ( '@/hooks/use-integration-platform' ) ,
278+ ) ;
279+
280+ vi . mocked ( useIntegrationProviders ) . mockReturnValue ( {
281+ providers : [
282+ {
283+ id : 'github' ,
284+ name : 'GitHub' ,
285+ description : 'Code hosting' ,
286+ category : 'Development' ,
287+ logoUrl : '/github.png' ,
288+ authType : 'oauth2' ,
289+ oauthConfigured : true ,
290+ isActive : true ,
291+ requiredVariables : [ ] ,
292+ mappedTasks : [ ] ,
293+ supportsMultipleConnections : false ,
294+ } ,
295+ ] as any ,
296+ isLoading : false ,
297+ error : undefined ,
298+ refresh : vi . fn ( ) ,
299+ } ) ;
300+
301+ vi . mocked ( useIntegrationConnections ) . mockReturnValue ( {
302+ connections : [
303+ {
304+ id : 'conn-2' ,
305+ providerSlug : 'github' ,
306+ status : 'active' ,
307+ variables : null ,
308+ } ,
309+ ] as any ,
310+ isLoading : false ,
311+ error : undefined ,
312+ refresh : vi . fn ( ) ,
313+ } ) ;
314+
315+ const { useSearchParams : mockUseSearchParams } = vi . mocked (
316+ await import ( 'next/navigation' ) ,
317+ ) ;
318+ vi . mocked ( mockUseSearchParams ) . mockReturnValue (
319+ new URLSearchParams ( 'success=true&provider=github' ) as any ,
320+ ) ;
321+
322+ setMockPermissions ( ADMIN_PERMISSIONS ) ;
323+
324+ render ( < PlatformIntegrations { ...defaultProps } /> ) ;
325+
326+ expect ( toast . success ) . toHaveBeenCalledWith (
327+ 'GitHub connected successfully!' ,
328+ ) ;
329+ expect ( toast . info ) . not . toHaveBeenCalled ( ) ;
330+ } ) ;
331+ } ) ;
205332} ) ;
0 commit comments