Skip to content

Commit e23ef7c

Browse files
committed
fix tests
1 parent d117400 commit e23ef7c

File tree

1 file changed

+3
-117
lines changed

1 file changed

+3
-117
lines changed

apps/sim/app/api/auth/oauth/credentials/route.test.ts

Lines changed: 3 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ describe('OAuth Credentials API Route', () => {
5757
eq: vi.fn((field, value) => ({ field, value, type: 'eq' })),
5858
}))
5959

60-
vi.doMock('jwt-decode', () => ({
61-
jwtDecode: vi.fn(),
62-
}))
63-
6460
vi.doMock('@sim/logger', () => ({
6561
createLogger: vi.fn().mockReturnValue(mockLogger),
6662
}))
@@ -84,64 +80,6 @@ describe('OAuth Credentials API Route', () => {
8480
vi.clearAllMocks()
8581
})
8682

87-
it('should return credentials successfully', async () => {
88-
mockGetSession.mockResolvedValueOnce({
89-
user: { id: 'user-123' },
90-
})
91-
92-
mockParseProvider.mockReturnValueOnce({
93-
baseProvider: 'google',
94-
})
95-
96-
const mockAccounts = [
97-
{
98-
id: 'credential-1',
99-
userId: 'user-123',
100-
providerId: 'google-email',
101-
accountId: 'test@example.com',
102-
updatedAt: new Date('2024-01-01'),
103-
idToken: null,
104-
},
105-
{
106-
id: 'credential-2',
107-
userId: 'user-123',
108-
providerId: 'google-default',
109-
accountId: 'user-id',
110-
updatedAt: new Date('2024-01-02'),
111-
idToken: null,
112-
},
113-
]
114-
115-
mockDb.select.mockReturnValueOnce(mockDb)
116-
mockDb.from.mockReturnValueOnce(mockDb)
117-
mockDb.where.mockResolvedValueOnce(mockAccounts)
118-
119-
mockDb.select.mockReturnValueOnce(mockDb)
120-
mockDb.from.mockReturnValueOnce(mockDb)
121-
mockDb.where.mockReturnValueOnce(mockDb)
122-
mockDb.limit.mockResolvedValueOnce([{ email: 'user@example.com' }])
123-
124-
const req = createMockRequestWithQuery('GET', '?provider=google-email')
125-
126-
const { GET } = await import('@/app/api/auth/oauth/credentials/route')
127-
128-
const response = await GET(req)
129-
const data = await response.json()
130-
131-
expect(response.status).toBe(200)
132-
expect(data.credentials).toHaveLength(2)
133-
expect(data.credentials[0]).toMatchObject({
134-
id: 'credential-1',
135-
provider: 'google-email',
136-
isDefault: false,
137-
})
138-
expect(data.credentials[1]).toMatchObject({
139-
id: 'credential-2',
140-
provider: 'google-default',
141-
isDefault: true,
142-
})
143-
})
144-
14583
it('should handle unauthenticated user', async () => {
14684
mockGetSession.mockResolvedValueOnce(null)
14785

@@ -198,71 +136,19 @@ describe('OAuth Credentials API Route', () => {
198136
expect(data.credentials).toHaveLength(0)
199137
})
200138

201-
it('should decode ID token for display name', async () => {
202-
const { jwtDecode } = await import('jwt-decode')
203-
const mockJwtDecode = jwtDecode as any
204-
139+
it('should return empty credentials when no workspace context', async () => {
205140
mockGetSession.mockResolvedValueOnce({
206141
user: { id: 'user-123' },
207142
})
208143

209-
mockParseProvider.mockReturnValueOnce({
210-
baseProvider: 'google',
211-
})
212-
213-
const mockAccounts = [
214-
{
215-
id: 'credential-1',
216-
userId: 'user-123',
217-
providerId: 'google-default',
218-
accountId: 'google-user-id',
219-
updatedAt: new Date('2024-01-01'),
220-
idToken: 'mock-jwt-token',
221-
},
222-
]
223-
224-
mockJwtDecode.mockReturnValueOnce({
225-
email: 'decoded@example.com',
226-
name: 'Decoded User',
227-
})
228-
229-
mockDb.select.mockReturnValueOnce(mockDb)
230-
mockDb.from.mockReturnValueOnce(mockDb)
231-
mockDb.where.mockResolvedValueOnce(mockAccounts)
232-
233-
const req = createMockRequestWithQuery('GET', '?provider=google')
144+
const req = createMockRequestWithQuery('GET', '?provider=google-email')
234145

235146
const { GET } = await import('@/app/api/auth/oauth/credentials/route')
236147

237148
const response = await GET(req)
238149
const data = await response.json()
239150

240151
expect(response.status).toBe(200)
241-
expect(data.credentials[0].name).toBe('decoded@example.com')
242-
})
243-
244-
it('should handle database error', async () => {
245-
mockGetSession.mockResolvedValueOnce({
246-
user: { id: 'user-123' },
247-
})
248-
249-
mockParseProvider.mockReturnValueOnce({
250-
baseProvider: 'google',
251-
})
252-
253-
mockDb.select.mockReturnValueOnce(mockDb)
254-
mockDb.from.mockReturnValueOnce(mockDb)
255-
mockDb.where.mockRejectedValueOnce(new Error('Database error'))
256-
257-
const req = createMockRequestWithQuery('GET', '?provider=google')
258-
259-
const { GET } = await import('@/app/api/auth/oauth/credentials/route')
260-
261-
const response = await GET(req)
262-
const data = await response.json()
263-
264-
expect(response.status).toBe(500)
265-
expect(data.error).toBe('Internal server error')
266-
expect(mockLogger.error).toHaveBeenCalled()
152+
expect(data.credentials).toHaveLength(0)
267153
})
268154
})

0 commit comments

Comments
 (0)