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

test: add unit test for src/services/_auth.ts

Open gru-agent[bot] opened this issue 2 weeks ago • 7 comments

Trigger Info

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

Summary

This PR introduces unit tests for the _auth module, ensuring the correctness of its core functionalities. The following key areas are covered:

  1. getProviderAuthPayload Tests:

    • Validates the payload generation for various providers (Bedrock, Azure, Ollama, Cloudflare).

    • Ensures fallback behavior for unknown providers.

    • Tests specific cases like using endpoint as baseURL for Azure when baseURL is not provided.

  2. createAuthTokenWithPayload Tests:

    • Verifies JWT token creation with both custom and empty payloads.

    • Mocks dependencies like keyVaultsConfigSelectors and userProfileSelectors.

  3. createHeaderWithAuth Tests:

    • Confirms headers are correctly generated with the auth token.

    • Tests behavior for deprecated and non-deprecated editions, including provider-specific payload inclusion.

  4. Refactor and Export:

    • Exports createAuthTokenWithPayload for external usage.

These tests ensure robust validation of authentication-related logic and improve maintainability by mocking external dependencies.

[!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 05 '25 02:02 gru-agent[bot]