mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-05-05 15:30:48 +00:00
feat: implement login and signup functionality with auto-create option in stackAuthApi
This commit is contained in:
parent
21299788c3
commit
ca26a7da87
6 changed files with 202 additions and 48 deletions
44
test/unit/service/stackAuthApi.test.ts
Normal file
44
test/unit/service/stackAuthApi.test.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
import { loginByStackWithAutoCreate, loginByStackToken } from '../../../src/service/stackAuthApi'
|
||||
|
||||
vi.mock('@/api/http', () => ({
|
||||
proxyFetchPost: vi.fn(),
|
||||
}))
|
||||
|
||||
describe('stackAuthApi', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('falls back to signup when login returns user not found', async () => {
|
||||
const { proxyFetchPost } = await import('@/api/http')
|
||||
|
||||
vi.mocked(proxyFetchPost)
|
||||
.mockResolvedValueOnce({ code: 1, text: 'User not found' })
|
||||
.mockResolvedValueOnce({ code: 0, token: 't', email: 'e@example.com' })
|
||||
|
||||
const res = await loginByStackWithAutoCreate('stack-token')
|
||||
|
||||
expect(res.code).toBe(0)
|
||||
expect(vi.mocked(proxyFetchPost)).toHaveBeenCalledTimes(2)
|
||||
|
||||
const firstUrl = vi.mocked(proxyFetchPost).mock.calls[0][0] as string
|
||||
const secondUrl = vi.mocked(proxyFetchPost).mock.calls[1][0] as string
|
||||
|
||||
expect(firstUrl).toContain('/api/login-by_stack?')
|
||||
expect(firstUrl).toContain('type=login')
|
||||
expect(secondUrl).toContain('type=signup')
|
||||
})
|
||||
|
||||
it('includes invite_code in query when provided', async () => {
|
||||
const { proxyFetchPost } = await import('@/api/http')
|
||||
|
||||
vi.mocked(proxyFetchPost).mockResolvedValueOnce({ code: 0 })
|
||||
|
||||
await loginByStackToken({ token: 'stack-token', type: 'signup', inviteCode: 'INV123' })
|
||||
|
||||
const url = vi.mocked(proxyFetchPost).mock.calls[0][0] as string
|
||||
expect(url).toContain('invite_code=INV123')
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue