-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from ucsb-cs148-w25/lab06-testing
Lab06 testing
- Loading branch information
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
import { jest } from '@jest/globals'; | ||
|
||
// Mock axios using unstable_mockModule for ES modules | ||
jest.unstable_mockModule('axios', () => ({ | ||
default: { | ||
get: jest.fn().mockResolvedValue({ | ||
data: [ | ||
{ | ||
id: "test-bet-1", | ||
sport_key: "basketball_nba", | ||
commence_time: "2025-01-24T01:30:38Z", | ||
home_team: "Team A", | ||
away_team: "Team B", | ||
bookmakers: [{ | ||
markets: [{ | ||
outcomes: [ | ||
{ name: "Team A", price: 1.5 }, | ||
{ name: "Team B", price: 2.5 } | ||
] | ||
}] | ||
}] | ||
} | ||
] | ||
}) | ||
} | ||
})); | ||
|
||
// Mock node-cron using unstable_mockModule | ||
jest.unstable_mockModule('node-cron', () => ({ | ||
default: { | ||
schedule: jest.fn() | ||
} | ||
})); | ||
|
||
|
||
describe('Betting System Basic Test', () => { | ||
test('script can be imported', async () => { | ||
const { script } = await import('./script.js'); | ||
expect(script).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,48 @@ | ||
Using Jest testing library. Created a unit test on our bet parser function. Tests to make sure | ||
the function can parse a bet string and return the correct bet object. Run the test with the | ||
command `npm test`. | ||
command `npm test`. | ||
|
||
## Unit Testing Implementation | ||
For our initial unit testing requirements, we used Jest to test our betting script functionality. Specifically, we implemented a unit test that checks if our API response parser correctly formats betting data into our backend's required structure. The test verifies that given a raw API response (with stuff like odds, teams, and timestamps), it properly extracts and organizes the data into a format our system can use. | ||
|
||
The main test file (`script.test.js`) includes test cases that: | ||
- Verify successful parsing of valid betting data | ||
- Handle empty bookmaker arrays gracefully | ||
- Deal with malformed data without crashing | ||
|
||
```javascript | ||
describe('Betting API Parser', () => { | ||
test('parse_api_response correctly formats betting data', async () => { | ||
const result = await parse_api_response(test_api_response); | ||
expect(result).toEqual(expected_parse_api_response_output); | ||
}); | ||
// ... other test cases | ||
}); | ||
``` | ||
|
||
## Future Unit Testing Plans | ||
Let's be real - while 100% test coverage would be nice in theory, we're focusing our unit testing efforts where they matter most: | ||
- Core data processing functions (like the betting parser) | ||
- Critical user-facing calculations (odds processing, payout logic) | ||
- Edge cases that could break the app | ||
|
||
We're not going to unit test every single component because: | ||
1. Our dev timeline is tight | ||
2. Some parts change too frequently to maintain tests | ||
3. Integration tests sometimes give us better value for time spent | ||
|
||
## Integration Testing Implementation | ||
We've added a basic integration test using Jest that verifies our betting script components work together correctly. The test (`script.integration.test.js`) checks that: | ||
- The script can be imported correctly | ||
- Components can communicate with each other | ||
- The basic betting cycle flows properly | ||
|
||
While simple, this test ensures our core modules play nice together and catches any major integration issues. | ||
|
||
## Future Integration Testing Plans | ||
Going forward, we're planning to: | ||
- Add more comprehensive integration tests for user workflows | ||
- Focus on critical paths (bet placement -> processing -> payout) | ||
- Maybe add some end-to-end tests if time permits | ||
|
||
However, we're keeping it pragmatic. Full end-to-end testing would be overkill for our project scope and timeline. We'll stick to integration tests that give us the most bang for our buck in terms of catching real issues users might face. |