76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
jest.mock('../src/services/account/openaiAccountService', () => ({
|
|
setAccountRateLimited: jest.fn()
|
|
}))
|
|
|
|
jest.mock('../src/services/account/openaiResponsesAccountService', () => ({
|
|
getAccount: jest.fn(),
|
|
markAccountRateLimited: jest.fn(),
|
|
updateAccount: jest.fn()
|
|
}))
|
|
|
|
jest.mock('../src/services/accountGroupService', () => ({}))
|
|
jest.mock('../src/models/redis', () => ({}))
|
|
jest.mock('../src/utils/logger', () => ({
|
|
debug: jest.fn(),
|
|
error: jest.fn(),
|
|
info: jest.fn(),
|
|
warn: jest.fn()
|
|
}))
|
|
jest.mock('../src/utils/commonHelper', () => ({
|
|
isSchedulable: jest.fn((value) => value !== false && value !== 'false'),
|
|
sortAccountsByPriority: jest.fn((accounts) => accounts)
|
|
}))
|
|
jest.mock('../src/utils/upstreamErrorHelper', () => ({}))
|
|
|
|
const openaiResponsesAccountService = require('../src/services/account/openaiResponsesAccountService')
|
|
const unifiedOpenAIScheduler = require('../src/services/scheduler/unifiedOpenAIScheduler')
|
|
|
|
describe('UnifiedOpenAIScheduler', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks()
|
|
})
|
|
|
|
describe('markAccountRateLimited', () => {
|
|
it('does not disable scheduling again when OpenAI-Responses auto protection is disabled', async () => {
|
|
openaiResponsesAccountService.getAccount.mockResolvedValue({
|
|
id: 'account-1',
|
|
disableAutoProtection: 'true'
|
|
})
|
|
|
|
await unifiedOpenAIScheduler.markAccountRateLimited(
|
|
'account-1',
|
|
'openai-responses',
|
|
null,
|
|
120
|
|
)
|
|
|
|
expect(openaiResponsesAccountService.markAccountRateLimited).toHaveBeenCalledWith(
|
|
'account-1',
|
|
2
|
|
)
|
|
expect(openaiResponsesAccountService.updateAccount).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('keeps disabling scheduling for protected OpenAI-Responses accounts', async () => {
|
|
openaiResponsesAccountService.getAccount.mockResolvedValue({
|
|
id: 'account-1',
|
|
disableAutoProtection: 'false'
|
|
})
|
|
|
|
await unifiedOpenAIScheduler.markAccountRateLimited(
|
|
'account-1',
|
|
'openai-responses',
|
|
null,
|
|
120
|
|
)
|
|
|
|
expect(openaiResponsesAccountService.updateAccount).toHaveBeenCalledWith(
|
|
'account-1',
|
|
expect.objectContaining({
|
|
schedulable: 'false'
|
|
})
|
|
)
|
|
})
|
|
})
|
|
})
|