lobe-chat icon indicating copy to clipboard operation
lobe-chat copied to clipboard

✅ test: add unit test for src/server/routers/lambda/aiModel.ts

Open gru-agent[bot] opened this issue 1 week ago • 4 comments

Trigger Info

Trigger Type Triggered By Source Pull Request Assignment
Auto Rebase arvinxx 6080 Detail

Summary

This PR introduces unit tests for the aiModelRouter module, ensuring comprehensive coverage of its functionalities. The following key features are tested:

  • Batch Operations:

    • batchToggleAiModels: Verifies toggling the enabled state of multiple AI models.

    • batchUpdateAiModels: Ensures batch updates of AI models are handled correctly.

  • Model Management:

    • clearModelsByProvider: Tests clearing models associated with a specific provider.

    • clearRemoteModels: Validates clearing remote models for a given provider.

    • createAiModel: Confirms the creation of a new AI model and returns the created model's ID.

    • getAiModelById: Ensures retrieval of an AI model by its ID.

    • removeAiModel: Verifies the deletion of an AI model by ID and provider.

  • Model State and Order:

    • toggleModelEnabled: Tests toggling the enabled state of a specific model.

    • updateAiModel: Validates updating a model's attributes.

    • updateAiModelOrder: Ensures the correct reordering of models based on a provided sort map.

Mocks are used for dependencies such as AiModelModel, UserModel, AiInfraRepos, KeyVaultsGateKeeper, and getServerGlobalConfig to isolate the tests and focus on the router's logic. Each test case ensures the corresponding method is called with the expected arguments.

[!TIP] You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

[!TIP] You can @gru-agent rebase to rebase the PR.

[!TIP] You can @gru-agent redo to reset or rebase before redoing the PR.

[!TIP] To modify the test code yourself, click here Edit Test Code

gru-agent[bot] avatar Feb 13 '25 05:02 gru-agent[bot]