|
| 1 | +import { getMockOclifConfig } from '../../../../__tests__/commands/utils'; |
| 2 | +import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils/createGraphqlClient'; |
| 3 | +import { testProjectId } from '../../../../credentials/__tests__/fixtures-constants'; |
| 4 | +import { ConvexQuery } from '../../../../graphql/queries/ConvexQuery'; |
| 5 | +import { |
| 6 | + ConvexProjectData, |
| 7 | + ConvexTeamConnectionData, |
| 8 | +} from '../../../../graphql/types/ConvexTeamConnection'; |
| 9 | +import Log from '../../../../log'; |
| 10 | +import IntegrationsConvexProject from '../project'; |
| 11 | + |
| 12 | +jest.mock('../../../../graphql/queries/ConvexQuery'); |
| 13 | +jest.mock('../../../../log'); |
| 14 | + |
| 15 | +describe(IntegrationsConvexProject, () => { |
| 16 | + const graphqlClient = {} as ExpoGraphqlClient; |
| 17 | + const mockConfig = getMockOclifConfig(); |
| 18 | + |
| 19 | + const mockConnection: ConvexTeamConnectionData = { |
| 20 | + id: 'connection-1', |
| 21 | + convexTeamIdentifier: 'team-123', |
| 22 | + convexTeamName: 'Test Team', |
| 23 | + convexTeamSlug: 'test-team', |
| 24 | + createdAt: '2024-01-01T00:00:00.000Z', |
| 25 | + updatedAt: '2024-01-01T00:00:00.000Z', |
| 26 | + invitedAt: null, |
| 27 | + invitedEmail: null, |
| 28 | + }; |
| 29 | + |
| 30 | + const mockProject: ConvexProjectData = { |
| 31 | + id: 'convex-project-1', |
| 32 | + convexProjectIdentifier: 'project-123', |
| 33 | + convexProjectName: 'Test Project', |
| 34 | + convexProjectSlug: 'test-project', |
| 35 | + createdAt: '2024-01-01T00:00:00.000Z', |
| 36 | + updatedAt: '2024-01-01T00:00:00.000Z', |
| 37 | + convexTeamConnection: mockConnection, |
| 38 | + }; |
| 39 | + |
| 40 | + function createCommand(): IntegrationsConvexProject { |
| 41 | + const command = new IntegrationsConvexProject([], mockConfig); |
| 42 | + jest.spyOn(command as any, 'getContextAsync').mockReturnValue({ |
| 43 | + privateProjectConfig: { |
| 44 | + projectId: testProjectId, |
| 45 | + exp: { slug: 'testapp' }, |
| 46 | + }, |
| 47 | + loggedIn: { graphqlClient }, |
| 48 | + } as never); |
| 49 | + return command; |
| 50 | + } |
| 51 | + |
| 52 | + beforeEach(() => { |
| 53 | + jest.resetAllMocks(); |
| 54 | + jest.spyOn(Log, 'log').mockImplementation(() => {}); |
| 55 | + jest.spyOn(Log, 'warn').mockImplementation(() => {}); |
| 56 | + }); |
| 57 | + |
| 58 | + it('prints linked Convex project metadata', async () => { |
| 59 | + jest.mocked(ConvexQuery.getConvexProjectByAppIdAsync).mockResolvedValue(mockProject); |
| 60 | + |
| 61 | + await createCommand().runAsync(); |
| 62 | + |
| 63 | + expect(Log.log).toHaveBeenCalledWith( |
| 64 | + expect.stringContaining('Convex project linked to testapp') |
| 65 | + ); |
| 66 | + expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('project-123')); |
| 67 | + }); |
| 68 | + |
| 69 | + it('prints an empty state when no Convex project is linked', async () => { |
| 70 | + jest.mocked(ConvexQuery.getConvexProjectByAppIdAsync).mockResolvedValue(null); |
| 71 | + |
| 72 | + await createCommand().runAsync(); |
| 73 | + |
| 74 | + expect(Log.warn).toHaveBeenCalledWith( |
| 75 | + expect.stringContaining('No Convex project is linked to Expo app') |
| 76 | + ); |
| 77 | + }); |
| 78 | +}); |
0 commit comments