Skip to content

Commit 4014ce3

Browse files
committed
[eas-cli] Add Convex project command
1 parent 30bc865 commit 4014ce3

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import chalk from 'chalk';
2+
3+
import EasCommand from '../../../commandUtils/EasCommand';
4+
import { formatConvexProject, logNoConvexProject } from '../../../commandUtils/convex';
5+
import { ConvexQuery } from '../../../graphql/queries/ConvexQuery';
6+
import Log from '../../../log';
7+
8+
export default class IntegrationsConvexProject extends EasCommand {
9+
static override description = 'display the Convex project linked to the current Expo app';
10+
11+
static override contextDefinition = {
12+
...this.ContextOptions.ProjectConfig,
13+
};
14+
15+
async runAsync(): Promise<void> {
16+
const {
17+
privateProjectConfig: { projectId, exp },
18+
loggedIn: { graphqlClient },
19+
} = await this.getContextAsync(IntegrationsConvexProject, {
20+
nonInteractive: false,
21+
withServerSideEnvironment: null,
22+
});
23+
24+
const convexProject = await ConvexQuery.getConvexProjectByAppIdAsync(graphqlClient, projectId);
25+
26+
if (!convexProject) {
27+
logNoConvexProject(exp.slug);
28+
return;
29+
}
30+
31+
Log.log(chalk.bold(`Convex project linked to ${exp.slug}`));
32+
Log.log(formatConvexProject(convexProject));
33+
}
34+
}

0 commit comments

Comments
 (0)