lobe-chat
lobe-chat copied to clipboard
test: add unit test for src/services/_auth.ts
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:
-
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
asbaseURL
for Azure whenbaseURL
is not provided.
-
-
createAuthTokenWithPayload
Tests:-
Verifies JWT token creation with both custom and empty payloads.
-
Mocks dependencies like
keyVaultsConfigSelectors
anduserProfileSelectors
.
-
-
createHeaderWithAuth
Tests:-
Confirms headers are correctly generated with the auth token.
-
Tests behavior for deprecated and non-deprecated editions, including provider-specific payload inclusion.
-
-
Refactor and Export:
- Exports
createAuthTokenWithPayload
for external usage.
- Exports
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