Skip to content

Commit

Permalink
Merge pull request #181 from ucsb-cs148-w25/lab06-testing
Browse files Browse the repository at this point in the history
Lab06 testing
  • Loading branch information
jonathanzhang2027 authored Feb 21, 2025
2 parents e855c38 + dd980ce commit 964350c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 3 deletions.
42 changes: 42 additions & 0 deletions backend/scripts/integration.test.js
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();
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "### Project Description **BetBuddies** is a competitive sports betting app where users compete against friends using *fake money* to see who’s the best sports bettor. This app simulates real-world sports betting scenarios while keeping it fun and risk-free. The goal is to create an engaging platform where friends can enjoy sports events and friendly competition without financial stakes.",
"main": "index.js",
"scripts": {
"test": "jest",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"dev": "nodemon backend/server.js"
},
"repository": {
Expand Down
19 changes: 18 additions & 1 deletion team/AI_CODING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,21 @@ Verify:
### Daniel - Used GPT-4o creating foundational UI
- I used OpenAI's GPT-4o model to help create the UI of the sportsbook.css page
- Honestly, with the correct descriptions, GPT can defintely provide a foundational format of what you want your page to look like. From there, I added in my personal taste to help tailor the website to the vision I have.
- I verified the code it gave me by testing each snippet of code, and asking GPT to provide comments to understand what it did.
- I verified the code it gave me by testing each snippet of code, and asking GPT to provide comments to understand what it did.

### Colin - I used GPT-4o to create the group tab
- GPT was able to build off of the already basic group code and created the code structure for a few more features that I wanted to add.
- GPT helped extend existing functionality by suggesting best practices for API validation and error handling and sped up implementation of new features.
- Ensuring Correctness & Fair Use
- I looked through and manually reviewed the AI-generated code looking and evaluated how acurate it was. I then tested with different edge cases like missing group name, and made changes as necessary.

### Bryce - Used Claude for designing UI
- I used Claude to help me design the leaderboard page to make it look better.
- The UI it created helped to make the page look much nicer by giving me several options for designs that I could choose and select from.
- This tool was very helpful since I find it hard to make the UI look good.
- All I had to do to make sure that the code was correct was run each design and see if it matched the description it gave me. If there was anything that didn't look how it was supposed to, I could just describe the visual differences and it would fix it.

### Ryan - Used DeepSeek to help generate an HTML data scraper
- used DeepSeek in order to develop a script that will scrape data from ESPN's injury page daily
- The script worked locally but it became an issue when trying to query the data onto our database consistently using a CRON job.
- I believe that this AI tool is extremely useful to ask for guidance on a specific topic, but will struggle on understanding the large scope of a full stack project
47 changes: 46 additions & 1 deletion team/TESTING.md
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.

0 comments on commit 964350c

Please sign in to comment.