Files
supabase/apps/studio/data/projects/project-create-mutation.test.ts
Saxon Fletcher ae66a6a9c0 Connect GitHub during project creation (#44884)
<img width="1289" height="863" alt="image"
src="https://github.com/user-attachments/assets/d661f107-b358-4894-8531-80441d60ab91"
/>

GitHub integration is now available on the free plan and so we'd like to
start promoting code-first workflows as much as possible. One way to do
that is to set the tone straight away by asking a user to connecting
their GitHub repository to a project as part of project creation.

This PR: 
- decouples GitHub connection and repo selection into a separate
component we can make use of in integration settings and project
creation.
- Adds new GitHub fields to project creation form and sends them off to
project creation endpoint
- Pre-fills project name based on repo selection 


To test locally:
- Ensure you have GitHub integration set up locally (using ngrok etc)
- Ensure you are on the connected platform branch
- Open create a new project page
- Connect GitHub as part of the creation form and select a repo
- Create the project and wait for status to be healthy
- Check project settings integrations page and ensure repo is connected

Note: 
- this requires changes on the management api end to accept new GitHub
fields
- it might make sense to pull out GitHub connection/authorization from
GitHub repository selection but in the current state they are tied
together.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **New Features**
* GitHub repository selection now available during project creation with
integrated authorization flow
* GitHub connection status and compute availability indicators now
displayed on project dashboard
* Project name auto-populates from selected GitHub repository name when
available

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
2026-05-08 13:52:09 +10:00

73 lines
2.1 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
vi.mock('@/data/fetchers', () => ({
post: vi.fn(),
handleError: vi.fn((error) => {
throw error
}),
}))
describe('project-create-mutation', () => {
beforeEach(() => {
vi.clearAllMocks()
})
describe('createProject', () => {
it('sends GitHub connection fields when provided', async () => {
const { post } = await import('@/data/fetchers')
const { createProject } = await import('./project-create-mutation')
const mockPost = post as unknown as ReturnType<typeof vi.fn>
mockPost.mockResolvedValueOnce({
data: { ref: 'project-ref', organization_slug: 'test-org' },
error: null,
})
await createProject({
name: 'test-project',
organizationSlug: 'test-org',
dbPass: 'secret-password',
dbRegion: 'West US (North California)',
githubInstallationId: 1234,
githubRepositoryId: 5678,
})
expect(mockPost).toHaveBeenCalledWith('/platform/projects', {
body: expect.objectContaining({
name: 'test-project',
organization_slug: 'test-org',
db_pass: 'secret-password',
db_region: 'West US (North California)',
github_installation_id: 1234,
github_repository_id: 5678,
}),
})
})
it('does not populate GitHub connection fields when omitted', async () => {
const { post } = await import('@/data/fetchers')
const { createProject } = await import('./project-create-mutation')
const mockPost = post as unknown as ReturnType<typeof vi.fn>
mockPost.mockResolvedValueOnce({
data: { ref: 'project-ref', organization_slug: 'test-org' },
error: null,
})
await createProject({
name: 'test-project',
organizationSlug: 'test-org',
dbPass: 'secret-password',
dbRegion: 'West US (North California)',
})
expect(mockPost).toHaveBeenCalledWith('/platform/projects', {
body: expect.objectContaining({
github_installation_id: undefined,
github_repository_id: undefined,
}),
})
})
})
})