railyard/apps/ritgram/web/tests/githubService.test.ts
caelum0x f80b04ae0f feat(ritgram): move GitGram app into railyard as Ritgram, next to Rithub
Moved later/gitgram-ai/gitgram/ to apps/ritgram/ (fresh history; full history stays in caelum0x/gitgram).
AITimeMachine stays separate in later/gitgram-ai per the Rithub master plan.
Logs, pid files and env files are ignored; GPL-3.0 mobile/proximity noted in THIRD_PARTY_NOTICES.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-13 04:18:46 +03:00

41 lines
1.6 KiB
TypeScript

/// <reference types="vitest/globals" />
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { githubService } from '@/services/githubService'
/**
* connectGitHub is the "Sign in with GitHub" entry point surfaced on the login
* screens. It must redirect to GitHub's OAuth authorize endpoint with the
* client id, the callback redirect URI, and the scopes the backend needs to
* write back stars/follows and read the user's email.
*/
describe('githubService.connectGitHub', () => {
const originalLocation = window.location
const originalClientId = process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID
beforeEach(() => {
Object.defineProperty(window, 'location', {
configurable: true,
value: { origin: 'https://app.gitgram.com', href: '' },
})
process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID = 'test-client-123'
})
afterEach(() => {
Object.defineProperty(window, 'location', { configurable: true, value: originalLocation })
process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID = originalClientId
})
it('redirects to the GitHub authorize endpoint', () => {
githubService.connectGitHub()
expect(window.location.href).toContain('https://github.com/login/oauth/authorize')
})
it('includes the configured client id, callback redirect, and scopes', () => {
githubService.connectGitHub()
const url = new URL(window.location.href)
expect(url.searchParams.get('client_id')).toBe('test-client-123')
expect(url.searchParams.get('redirect_uri')).toBe('https://app.gitgram.com/auth/github/callback')
expect(url.searchParams.get('scope')).toBe('user:email,repo,read:user')
})
})