Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions PR_TESTING_AND_BUG_FIXES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This PR addresses multiple issues related to test coverage and bug fixes in the
- connect, disconnect, setJwt, applyRefreshedTokens
- isTokenExpired, hydration, persistence
- Session cookie handling

- **Created** `src/store/__tests__/course-store.test.ts` - Comprehensive tests for course-store including:
- setCurrentCourse, setEnrollments, enroll (with deduplication)
- updateProgress (percent calculation, module tracking)
Expand Down Expand Up @@ -40,7 +40,8 @@ This PR addresses multiple issues related to test coverage and bug fixes in the

**Problem**: The `connectWallet` callback included `walletError` in its dependency array, but reads it inside the catch block. Since `walletError` is state, the closure captures a stale value.

**Solution**:
**Solution**:

- Added `walletErrorRef` to track the latest `walletError` value
- Changed catch block to check `walletErrorRef.current` instead of `walletError`
- Removed `walletError` from the `connectWallet` dependency array
Expand All @@ -52,26 +53,30 @@ This PR addresses multiple issues related to test coverage and bug fixes in the
**Problem**: The `setSessionCookie` function sets the `chainlearn-session` cookie without the `Secure` flag, allowing JWT transmission over unencrypted HTTP.

**Solution**:

- Added logic to detect HTTPS protocol using `window.location.protocol`
- Conditionally adds `; Secure` flag when served over HTTPS
- Maintains HTTP compatibility for local development

## Testing

All new tests follow existing patterns from the codebase (e.g., `use-debounce.test.tsx`) and cover:

- Successful operations
- Error handling
- Loading states
- Abort/cleanup where applicable

Run tests with:

```bash
npm test
```

## Type Checking

Run type checking to verify no type errors:

```bash
npm run typecheck
```
Expand Down Expand Up @@ -103,6 +108,7 @@ git push -u origin feature/testing-and-bug-fixes
```

Then create a pull request using the GitHub UI or CLI with the title:

```
Add unit tests for Zustand stores and hooks, fix walletError stale closure, add Secure flag to session cookie
```
Expand Down
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const securityHeaders = [
const nextConfig = {
reactStrictMode: true,
images: {
formats: ['image/avif', 'image/webp'],
formats: ["image/avif", "image/webp"],
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
// Only trusted domains are allowed here to prevent SSRF via the image
Expand Down
115 changes: 43 additions & 72 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading