mirror of
https://github.com/langgenius/dify.git
synced 2026-08-29 19:54:46 +08:00
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'
|
|
import { emailLoginWithCode, sendEMailLoginCode } from './common'
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
post: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('./base', () => ({
|
|
del: vi.fn(),
|
|
get: vi.fn(),
|
|
patch: vi.fn(),
|
|
post: mocks.post,
|
|
}))
|
|
|
|
describe('sendEMailLoginCode', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('includes the Turnstile token when provided', async () => {
|
|
await sendEMailLoginCode('user@example.com', 'en-US', 'turnstile-token')
|
|
|
|
expect(mocks.post).toHaveBeenCalledWith('/email-code-login', {
|
|
body: {
|
|
email: 'user@example.com',
|
|
language: 'en-US',
|
|
turnstile_token: 'turnstile-token',
|
|
},
|
|
})
|
|
})
|
|
|
|
it('omits the Turnstile token when it is not provided', async () => {
|
|
await sendEMailLoginCode('user@example.com', 'en-US')
|
|
|
|
expect(mocks.post).toHaveBeenCalledWith('/email-code-login', {
|
|
body: {
|
|
email: 'user@example.com',
|
|
language: 'en-US',
|
|
},
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('emailLoginWithCode', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('includes the verification-specific Turnstile token when provided', async () => {
|
|
await emailLoginWithCode({
|
|
code: 'encrypted-code',
|
|
email: 'user@example.com',
|
|
language: 'en-US',
|
|
timezone: 'Asia/Singapore',
|
|
token: 'email-login-token',
|
|
turnstile_token: 'verify-turnstile-token',
|
|
})
|
|
|
|
expect(mocks.post).toHaveBeenCalledWith('/email-code-login/validity', {
|
|
body: {
|
|
code: 'encrypted-code',
|
|
email: 'user@example.com',
|
|
language: 'en-US',
|
|
timezone: 'Asia/Singapore',
|
|
token: 'email-login-token',
|
|
turnstile_token: 'verify-turnstile-token',
|
|
},
|
|
})
|
|
})
|
|
})
|