Skip to content

test: Add unit test for projects/app/src/web/common/api/request.ts #5254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

gru-agent[bot]
Copy link
Contributor

@gru-agent gru-agent bot commented Jul 18, 2025

Trigger Info

Trigger Type Triggered By Source Pull Request Assignment
PR Created chuanhu9 5253 Detail

Summary

This PR introduces unit tests for the request utility functions in the projects/app/src/web/common/api/request.ts file. The following changes are included:

Changes:

  1. Export Enhancements:

    • Added explicit exports for utility functions: maxQuantityMap, checkMaxQuantity, requestFinish, startInterceptors, responseSuccess, checkRes, responseError, instance, and request.
  2. Unit Tests:

    • Created a new test file request.test.ts under test/cases/web/common/api/.

    • Added comprehensive test coverage for the following utility functions:

      • checkMaxQuantity: Tests for handling max quantity limits, including scenarios for first requests and exceeding limits.

      • requestFinish: Tests for removing finished requests and handling non-existent requests.

      • checkRes: Tests for handling successful responses, error responses, and undefined responses.

      • responseError: Tests for various error scenarios, including token errors, team errors, string errors, and undefined errors.

  3. Mocks:

    • Mocked getWebReqUrl from @fastgpt/web/common/system/utils.

    • Stubbed window.location to simulate different pathname scenarios for testing.

Purpose:

These tests ensure the reliability and correctness of the request utility functions, improving code quality and maintainability.

Coverage

The change in coverage value, such as: 0% -> 50%, indicates that the coverage was 0% before writing the tests and 50% after writing them.

https://web.dev/articles/ta-code-coverage

Type Change
lines 0% -> 66.44% 🔺
functions 0% -> 36.36% 🔺
statements 0% -> 66.44% 🔺
branches 0% -> 96.87% 🔺
source program

Test Statuses

Status Change
passed 0 -> 14 🔺
failed 0 -> 0
skipped 0 -> 0
source program

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 gru-agent bot mentioned this pull request Jul 18, 2025
Copy link

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 22.32% 12263 / 54940
🔵 Statements 22.32% 12263 / 54940
🔵 Functions 30.05% 339 / 1128
🔵 Branches 68.71% 905 / 1317
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
projects/app/src/web/common/api/request.ts 66.44% 96.87% 36.36% 66.44% 81-93, 133-141, 174-203, 213-214, 217-218, 221-222, 225-226
Generated in workflow #1473 for commit b3c4213 by the Vitest Coverage Report Action

Copy link

Preview mcp_server Image:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fatsgpt_mcp_server_b3c4213889cfe0affa87c0d2196318507dab8050

Copy link

Preview sandbox Image:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fatsgpt_sandbox_b3c4213889cfe0affa87c0d2196318507dab8050

Copy link

Preview fastgpt Image:

registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt-pr:fatsgpt_b3c4213889cfe0affa87c0d2196318507dab8050

@c121914yu c121914yu merged commit cfefe69 into main Jul 21, 2025
8 checks passed
@c121914yu c121914yu deleted the gru/projects-app-src-web-common-api-request-ts-1752810388252 branch July 22, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant