|
| 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 { ConvexTeamConnectionData } from '../../../../graphql/types/ConvexTeamConnection'; |
| 6 | +import Log from '../../../../log'; |
| 7 | +import { getOwnerAccountForProjectIdAsync } from '../../../../project/projectUtils'; |
| 8 | +import IntegrationsConvexTeam from '../team'; |
| 9 | + |
| 10 | +jest.mock('../../../../graphql/queries/ConvexQuery'); |
| 11 | +jest.mock('../../../../project/projectUtils'); |
| 12 | +jest.mock('../../../../log'); |
| 13 | + |
| 14 | +describe(IntegrationsConvexTeam, () => { |
| 15 | + const graphqlClient = {} as ExpoGraphqlClient; |
| 16 | + const mockConfig = getMockOclifConfig(); |
| 17 | + const testAccountId = 'test-account-id'; |
| 18 | + const testAccountName = 'testuser'; |
| 19 | + |
| 20 | + const mockAccount = { |
| 21 | + id: testAccountId, |
| 22 | + name: testAccountName, |
| 23 | + ownerUserActor: { id: 'test-user-id', username: testAccountName }, |
| 24 | + users: [{ role: 'OWNER' as any, actor: { id: 'test-user-id' } }], |
| 25 | + }; |
| 26 | + |
| 27 | + const mockConnection: ConvexTeamConnectionData = { |
| 28 | + id: 'connection-1', |
| 29 | + convexTeamIdentifier: 'team-123', |
| 30 | + convexTeamName: 'Test Team', |
| 31 | + convexTeamSlug: 'test-team', |
| 32 | + createdAt: '2024-01-01T00:00:00.000Z', |
| 33 | + updatedAt: '2024-01-01T00:00:00.000Z', |
| 34 | + invitedAt: null, |
| 35 | + invitedEmail: null, |
| 36 | + }; |
| 37 | + |
| 38 | + function createCommand(): IntegrationsConvexTeam { |
| 39 | + const command = new IntegrationsConvexTeam([], mockConfig); |
| 40 | + jest.spyOn(command as any, 'getContextAsync').mockReturnValue({ |
| 41 | + privateProjectConfig: { |
| 42 | + projectId: testProjectId, |
| 43 | + }, |
| 44 | + loggedIn: { graphqlClient }, |
| 45 | + } as never); |
| 46 | + return command; |
| 47 | + } |
| 48 | + |
| 49 | + beforeEach(() => { |
| 50 | + jest.resetAllMocks(); |
| 51 | + jest.spyOn(Log, 'log').mockImplementation(() => {}); |
| 52 | + jest.spyOn(Log, 'warn').mockImplementation(() => {}); |
| 53 | + jest.spyOn(Log, 'newLine').mockImplementation(() => {}); |
| 54 | + jest.mocked(getOwnerAccountForProjectIdAsync).mockResolvedValue(mockAccount as any); |
| 55 | + }); |
| 56 | + |
| 57 | + it('prints linked Convex team metadata', async () => { |
| 58 | + jest |
| 59 | + .mocked(ConvexQuery.getConvexTeamConnectionsByAccountIdAsync) |
| 60 | + .mockResolvedValue([mockConnection]); |
| 61 | + |
| 62 | + await createCommand().runAsync(); |
| 63 | + |
| 64 | + expect(Log.log).toHaveBeenCalledWith( |
| 65 | + expect.stringContaining('Convex teams linked to @testuser') |
| 66 | + ); |
| 67 | + expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('team-123')); |
| 68 | + }); |
| 69 | + |
| 70 | + it('prints an empty state when no Convex teams are linked', async () => { |
| 71 | + jest.mocked(ConvexQuery.getConvexTeamConnectionsByAccountIdAsync).mockResolvedValue([]); |
| 72 | + |
| 73 | + await createCommand().runAsync(); |
| 74 | + |
| 75 | + expect(Log.warn).toHaveBeenCalledWith(expect.stringContaining('No Convex team is linked')); |
| 76 | + }); |
| 77 | +}); |
0 commit comments