Public Access
feat(points): show early finish and expected points on questions
Core pays 10 early points for an unproven Steam finish. The rest comes with proof. Show this in the toast and the game line. Questions cards show the full value from GET /api/rewards/expected.
This commit is contained in:
1 parent
814decc781
commit
c126592887
13 files changed
+166
-28
No files matched your search
@@ -14,7 +14,11 @@ const card = (appid, question, name = `Game ${appid}`) => ({appid, name, imageUr
|
||||
playtimeMinutes: 1500, normallyMinutes: null, lastActivity: null});
|
||||
|
||||
const booked = (appid) => ({balance: 30, missing: {}, paid: [{kind: 'FINISHED', appid, points: 30, paidAt: '2026-10-09T10:00:00Z', bookedNow: true}]});
|
||||
const WALLET = {'GET /api/rewards/wallet': json(200, {balance: 30, catalog: [], owned: [], equipped: {}, history: []})};
|
||||
const WALLET = {
|
||||
'GET /api/rewards/wallet': json(200, {balance: 30, catalog: [], owned: [], equipped: {}, history: []}),
|
||||
'GET /api/rewards/expected': json(200, {}),
|
||||
};
|
||||
const expectedCalls = () => globalThis.fetch.mock.calls.filter(([url]) => url.includes('/api/rewards/expected'));
|
||||
const pointsCalls = () => globalThis.fetch.mock.calls.filter(([url]) => url.includes('/api/rewards/games/'));
|
||||
|
||||
const renderPage = (routes) => {
|
||||
@@ -161,6 +165,45 @@ describe('QuestionsPage', () => {
|
||||
expect(screen.getByText('Game 1')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('showsTheExpectedPointsOnAFinishedCardOnly', async () => {
|
||||
renderPage({
|
||||
'GET /api/library/questions': json(200, {results: [card(1, 'FINISHED'), card(2, 'FINISHED'), card(3, 'START')]}),
|
||||
'GET /api/rewards/expected': json(200, {1: 50, 2: 0}),
|
||||
});
|
||||
|
||||
expect(await screen.findByText('QUESTIONS.FINISHED.POINTS:50')).toBeTruthy();
|
||||
expect(screen.getAllByText(/^QUESTIONS.FINISHED.POINTS/)).toHaveLength(1);
|
||||
expect(expectedCalls()[0][0]).toContain('appids=1,2');
|
||||
});
|
||||
|
||||
it('asksForTheExpectedPointsOfEveryFinishedCardInChunks', async () => {
|
||||
const cards = Array.from({length: 201}, (_, i) => card(i + 1, 'FINISHED'));
|
||||
renderPage({'GET /api/library/questions': json(200, {results: cards})});
|
||||
|
||||
await waitFor(() => expect(expectedCalls().length).toBeGreaterThan(0));
|
||||
const asked = expectedCalls().flatMap(([url]) => new URL(url, 'http://x').searchParams.get('appids').split(','));
|
||||
expect(asked).toContain('201');
|
||||
});
|
||||
|
||||
it('asksForNoExpectedPointsWithoutAFinishedCard', async () => {
|
||||
renderPage({'GET /api/library/questions': json(200, {results: [card(1, 'START')]})});
|
||||
await screen.findByText('Game 1');
|
||||
|
||||
expect(expectedCalls()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('showsNoPointsLineAndNoErrorWhenTheExpectedCallFails', async () => {
|
||||
renderPage({
|
||||
'GET /api/library/questions': json(200, {results: [card(1, 'FINISHED')]}),
|
||||
'GET /api/rewards/expected': json(500, {}),
|
||||
});
|
||||
|
||||
expect(await screen.findByText('Game 1')).toBeTruthy();
|
||||
await waitFor(() => expect(expectedCalls()).toHaveLength(1));
|
||||
expect(screen.queryByText(/^QUESTIONS.FINISHED.POINTS/)).toBeNull();
|
||||
expect(screen.queryByText('INFO.ERROR.NETWORK_FAILURE')).toBeNull();
|
||||
});
|
||||
|
||||
it('showsTheEmptyState', async () => {
|
||||
renderPage({'GET /api/library/questions': json(200, {results: []})});
|
||||
|
||||
|
||||
Reference in new issue
Block a user