Skip to content

Commit 547d5fc

Browse files
authored
Merge branch 'main' into fix/notify-malformed-json-400
2 parents ed25cb3 + 84e878f commit 547d5fc

5 files changed

Lines changed: 43 additions & 10 deletions

File tree

app/api/track-user/route.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import { User } from '@/models/User';
44
import { trackUserRateLimiter } from '@/lib/rate-limit';
55

66
export async function POST(req: Request) {
7-
// Get IP for rate limiting
8-
const ip = req.headers.get('x-forwarded-for') || req.headers.get('x-real-ip') || 'unknown';
7+
// Get IP for rate limiting.
8+
// x-real-ip is provided by Vercel/Nginx as the true client IP.
9+
// We fall back to the LAST IP in the x-forwarded-for chain, which is appended by the Vercel proxy.
10+
const forwardedFor = req.headers.get('x-forwarded-for');
11+
const fallbackIp = forwardedFor ? forwardedFor.split(',').pop()?.trim() : 'unknown';
12+
const ip = req.headers.get('x-real-ip') || fallbackIp || 'unknown';
913

1014
if (ip !== 'unknown' && !(await trackUserRateLimiter.check(ip))) {
1115
return NextResponse.json(

lib/cache.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,15 @@ describe('TTLCache', () => {
409409
const matrix = [
410410
[1, 2],
411411
[3, 4],
412+
[5, 6],
412413
];
413414

414415
cache.set('matrix', matrix, 60_000);
415416

416-
expect(cache.get('matrix')).toEqual(matrix);
417+
const cached = cache.get('matrix');
418+
419+
expect(cached).toEqual(matrix);
420+
expect(cached?.[2]?.[1]).toBe(6);
417421

418422
cache.destroy();
419423
});

lib/svg/generator.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from './generator';
1515
import type { BadgeParams, ContributionCalendar, StreakStats, MonthlyStats } from '../../types';
1616
import { hexColor } from './sanitizer';
17+
import { themes } from './themes';
1718

1819
describe('generateSVG', () => {
1920
const mockStats: StreakStats = {
@@ -868,6 +869,29 @@ describe('generateSVG', () => {
868869
expect(svg).not.toContain('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
869870
});
870871
});
872+
873+
describe('verify all supported themes produce valid SVG output', () => {
874+
it('generates a valid SVG and contains the theme accent color for each supported theme', () => {
875+
for (const theme of Object.values(themes)) {
876+
const svg = generateSVG(
877+
mockStats,
878+
{
879+
user: 'octocat',
880+
bg: theme.bg,
881+
text: theme.text,
882+
accent: theme.accent,
883+
speed: '8s',
884+
scale: 'linear',
885+
} as unknown as BadgeParams,
886+
mockCalendar
887+
);
888+
889+
expect(svg).toContain('<svg');
890+
expect(svg).toContain('</svg>');
891+
expect(svg.toLowerCase()).toContain(theme.accent.toLowerCase());
892+
}
893+
});
894+
});
871895
});
872896

873897
describe('generateMonthlySVG', () => {

lib/svg/layout.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,22 @@ it('assigns correct row and col values based on week/day position', () => {
223223
weeks: [
224224
{
225225
contributionDays: [
226+
{ contributionCount: 1, date: '2024-06-09' },
226227
{ contributionCount: 1, date: '2024-06-10' },
227228
{ contributionCount: 1, date: '2024-06-11' },
228-
{ contributionCount: 1, date: '2024-06-12' },
229229
],
230230
},
231231
{
232232
contributionDays: [
233-
{ contributionCount: 1, date: '2024-06-13' },
234-
{ contributionCount: 1, date: '2024-06-14' },
235-
{ contributionCount: 1, date: '2024-06-15' },
233+
{ contributionCount: 1, date: '2024-06-16' },
234+
{ contributionCount: 1, date: '2024-06-17' },
235+
{ contributionCount: 1, date: '2024-06-18' },
236236
],
237237
},
238238
],
239239
} as unknown as ContributionCalendar;
240240

241-
const towers = computeTowers(calendar, 'linear', '2024-06-15');
241+
const towers = computeTowers(calendar, 'linear', '2024-06-18');
242242

243243
expect(towers[0].row).toBe(0);
244244
expect(towers[0].col).toBe(0);

lib/svg/layout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ export function computeTowers(
123123
? `TODAY: ${day.date}: ${count} ${unit}`
124124
: `${day.date}: ${count} ${unit}`;
125125

126-
const coords = projectIsometric(i, j);
126+
const dayOfWeekIndex = new Date(day.date).getUTCDay();
127+
const coords = projectIsometric(i, dayOfWeekIndex);
127128

128129
let intensityLevel = 0;
129130
if (hasCommits) {
@@ -153,7 +154,7 @@ export function computeTowers(
153154
strokeOpacity: isGhost ? 0.3 : 0,
154155
strokeWidth: isGhost ? 0.5 : 0,
155156
row: i,
156-
col: j,
157+
col: dayOfWeekIndex,
157158
intensityLevel,
158159
});
159160
});

0 commit comments

Comments
 (0)