d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
94 lines
2.7 KiB
TypeScript
94 lines
2.7 KiB
TypeScript
/**
|
|
* Tests for OAuth credentials API route
|
|
*
|
|
* @vitest-environment node
|
|
*/
|
|
|
|
import { hybridAuthMockFns, permissionsMock, workflowsUtilsMock } from '@sim/testing'
|
|
import { NextRequest } from 'next/server'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
vi.mock('@/lib/credentials/oauth', () => ({
|
|
syncWorkspaceOAuthCredentialsForUser: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/lib/workflows/utils', () => workflowsUtilsMock)
|
|
|
|
vi.mock('@/lib/workspaces/permissions/utils', () => permissionsMock)
|
|
|
|
import { GET } from '@/app/api/auth/oauth/credentials/route'
|
|
|
|
describe('OAuth Credentials API Route', () => {
|
|
function createMockRequestWithQuery(method = 'GET', queryParams = ''): NextRequest {
|
|
const url = `http://localhost:3000/api/auth/oauth/credentials${queryParams}`
|
|
return new NextRequest(new URL(url), { method })
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('should handle unauthenticated user', async () => {
|
|
hybridAuthMockFns.mockCheckSessionOrInternalAuth.mockResolvedValueOnce({
|
|
success: false,
|
|
error: 'Authentication required',
|
|
})
|
|
|
|
const req = createMockRequestWithQuery('GET', '?provider=google')
|
|
|
|
const response = await GET(req)
|
|
const data = await response.json()
|
|
|
|
expect(response.status).toBe(401)
|
|
expect(data.error).toBe('User not authenticated')
|
|
})
|
|
|
|
it('should handle missing provider parameter', async () => {
|
|
hybridAuthMockFns.mockCheckSessionOrInternalAuth.mockResolvedValueOnce({
|
|
success: true,
|
|
userId: 'user-123',
|
|
authType: 'session',
|
|
})
|
|
|
|
const req = createMockRequestWithQuery('GET')
|
|
|
|
const response = await GET(req)
|
|
const data = await response.json()
|
|
|
|
expect(response.status).toBe(400)
|
|
expect(data.error).toBe('Provider or credentialId is required')
|
|
})
|
|
|
|
it('should handle no credentials found', async () => {
|
|
hybridAuthMockFns.mockCheckSessionOrInternalAuth.mockResolvedValueOnce({
|
|
success: true,
|
|
userId: 'user-123',
|
|
authType: 'session',
|
|
})
|
|
|
|
const req = createMockRequestWithQuery('GET', '?provider=github')
|
|
|
|
const response = await GET(req)
|
|
const data = await response.json()
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(data.credentials).toHaveLength(0)
|
|
})
|
|
|
|
it('should return empty credentials when no workspace context', async () => {
|
|
hybridAuthMockFns.mockCheckSessionOrInternalAuth.mockResolvedValueOnce({
|
|
success: true,
|
|
userId: 'user-123',
|
|
authType: 'session',
|
|
})
|
|
|
|
const req = createMockRequestWithQuery('GET', '?provider=google-email')
|
|
|
|
const response = await GET(req)
|
|
const data = await response.json()
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(data.credentials).toHaveLength(0)
|
|
})
|
|
})
|