fix: oprava zobrazení statistik pro aktuální týden
CI / Generate TypeScript types (push) Successful in 16s
CI / Server unit tests (push) Successful in 25s
CI / Build server (push) Successful in 28s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m46s
CI / Build and push Docker image (push) Successful in 48s
CI / Notify (push) Successful in 2s
CI / Generate TypeScript types (push) Successful in 16s
CI / Server unit tests (push) Successful in 25s
CI / Build server (push) Successful in 28s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m46s
CI / Build and push Docker image (push) Successful in 48s
CI / Notify (push) Successful in 2s
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
[
|
||||
"Statistiky se nově načtou i pro aktuální týden, který ještě neskončil"
|
||||
]
|
||||
+9
-3
@@ -5,6 +5,9 @@ import getStorage from "./storage";
|
||||
|
||||
const storage = getStorage();
|
||||
|
||||
/** O kolik dní do budoucnosti smí sahat koncové datum požadovaného rozsahu. */
|
||||
const MAX_FUTURE_DAYS = 7;
|
||||
|
||||
/**
|
||||
* Vypočte a vrátí statistiky jednotlivých možností pro předaný rozsah dat.
|
||||
*
|
||||
@@ -25,9 +28,12 @@ export async function getStats(startDate: string, endDate: string): Promise<Week
|
||||
throw new Error('Neplatný rozsah');
|
||||
}
|
||||
|
||||
const today = new Date();
|
||||
today.setHours(23, 59, 59, 999);
|
||||
if (end > today) {
|
||||
// Aktuální týden se načítá i s dny, které teprve budou — povolíme proto rozsah
|
||||
// sahající maximálně týden do budoucnosti
|
||||
const maxEnd = new Date();
|
||||
maxEnd.setHours(23, 59, 59, 999);
|
||||
maxEnd.setDate(maxEnd.getDate() + MAX_FUTURE_DAYS);
|
||||
if (end > maxEnd) {
|
||||
throw new Error('Nelze načíst statistiky pro budoucí datum');
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import bodyParser from 'body-parser';
|
||||
import { generateToken } from '../auth';
|
||||
import { resetMemoryStorage } from '../storage/memory';
|
||||
import statsRouter from '../routes/statsRoutes';
|
||||
import { formatDate } from '../utils';
|
||||
|
||||
function buildApp() {
|
||||
const app = express();
|
||||
@@ -52,6 +53,31 @@ test('GET /stats s budoucím datem vrátí 400', async () => {
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
test('GET /stats s koncovým datem do týdne v budoucnosti vrátí 200', async () => {
|
||||
// Aktuální týden se načítá i s dny, které teprve budou
|
||||
const start = new Date();
|
||||
const end = new Date();
|
||||
end.setDate(end.getDate() + 3);
|
||||
const res = await request(buildApp())
|
||||
.get('/api/stats')
|
||||
.query({ startDate: formatDate(start), endDate: formatDate(end) })
|
||||
.set('Authorization', TOKEN);
|
||||
expect(res.status).toBe(200);
|
||||
expect(Array.isArray(res.body)).toBe(true);
|
||||
});
|
||||
|
||||
test('GET /stats s koncovým datem více než týden v budoucnosti vrátí 400', async () => {
|
||||
const start = new Date();
|
||||
start.setDate(start.getDate() + 8);
|
||||
const end = new Date(start);
|
||||
end.setDate(end.getDate() + 4);
|
||||
const res = await request(buildApp())
|
||||
.get('/api/stats')
|
||||
.query({ startDate: formatDate(start), endDate: formatDate(end) })
|
||||
.set('Authorization', TOKEN);
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
test('GET /stats/export vrátí XLSX soubor', async () => {
|
||||
const res = await request(buildApp())
|
||||
.get('/api/stats/export')
|
||||
|
||||
Reference in New Issue
Block a user