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
11 changes: 10 additions & 1 deletion backend/src/services/__tests__/scoresService-additions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@
const [sql] = mockQuery.mock.calls[0] as [string, unknown[]];
expect(sql).toContain('LEAST(850, GREATEST(300,');
});
});

it('applies positive deltas as score increases in bulk upserts', async () => {
await updateUserScoresBulk(new Map([['user_reward', 25]]));

const [sql, params] = mockQuery.mock.calls[0] as [string, unknown[]];
expect(params).toEqual(['user_reward', 25]);
expect(sql).toContain('500 + $2');
expect(sql).toContain('scores.current_score + EXCLUDED.current_score - 500');
expect(sql).not.toContain('500 - $2');
});});

Check failure on line 94 in backend/src/services/__tests__/scoresService-additions.test.ts

View workflow job for this annotation

GitHub Actions / backend

Insert `⏎`

describe('setAbsoluteUserScoresBulk', () => {
it('is a noop for empty map', async () => {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/scoresService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function updateUserScoresBulk(
// Clamped the initial raw value payload insertion step to prevent violating constraints on initial inserts
const valuePlaceholders = Array.from(
{ length: params.length / 2 },
(_, i) => `($${i * 2 + 1}, LEAST(850, GREATEST(300, 500 - $${i * 2 + 2})))`,
(_, i) => `($${i * 2 + 1}, LEAST(850, GREATEST(300, 500 + $${i * 2 + 2})))`,
).join(', ');

const sql = `
Expand Down
Loading