freeCodeCamp / freeCodeCamp/back-end-development-and-apis
[Bug]: Regex issue in the test for lesson 13 (Bank API)
- Dominant language
- JavaScript
- Stars
- 32
- Forks
- 217
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
### Describe the bug
The test for the `POST /transfer` route checking if the sender account is not found fails if a developer capitalizes the error message (e.g., `new Error('Sender account not found')`) or uses standard formatting/linting spaces that push the character count between the variable `sender` and `404` past 30 characters.
### To Reproduce
Write a standard Express error handler block using standard capitalization:
```js
const sender = accounts.find((a) => a.id === fromId);
if (!sender) {
const err = new Error('Sender account not found');
err.status = 404;
throw err;
}
```
The test fails with `expected -1 to be above -1`.
### Expected behavior
The test should pass regardless of whether the developer capitalizes "Sender" or adds typical code formatting spacing.
### Screenshots
The current regex implementation is:
`/sender[\s\S]{0,30}404|404[\s\S]{0,60}sender/`
It lacks the case-insensitive flag `i` and has a tight character constraint (`{0,30}`). Adding the `i` flag and increasing the character limit to `{0,100}` fixes the issue.
### Desktop OS
_No response_
### Desktop Browser
_No response_
### Desktop Browser Version
_No response_
### Mobile Device
_No response_
### Mobile OS
_No response_
### Mobile Browser
_No response_
### Mobile Browser Version
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Find the lesson 13 Bank API test that checks the POST /transfer sender-not-found error and inspect its current regex. Update the matching behavior to allow capitalization and typical spacing, then run the relevant lesson 13 test to confirm the standard Express error handler passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100