mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
fix(db): keep a carried-over half day as a half on both engines
A vacation day can be taken as a half day, so what a year carries into the next can end in a half. vacay_user_years.carried_over was an INTEGER column: SQLite stored 29.5 as a REAL, Postgres (bigint) rounded it to 30, and the move refused such a SQLite value. The column becomes REAL on SQLite (a table rebuild that keeps every id and the AUTOINCREMENT counter) and double precision on Postgres, through the first migration after the Postgres baseline's cut. VACAY-046 books a half day and reads the carry-over on both engines.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
import { buildApp } from '../../src/bootstrap';
|
||||
import { VacayHolidayCalendars } from '../../src/db/entities/VacayHolidayCalendars.entity';
|
||||
import { VacayUserYears } from '../../src/db/entities/VacayUserYears.entity';
|
||||
import { VacayService } from '../../src/nest/vacay/vacay.service';
|
||||
import { authCookie } from '../helpers/auth';
|
||||
import type { FactoryOrm } from '../helpers/factories/context';
|
||||
@@ -200,6 +201,33 @@ describe('Vacay entries', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Vacay carry-over', () => {
|
||||
it('VACAY-046 — a half day left over carries as a half day into the next year, on every engine', async () => {
|
||||
const { user } = await makeUser(orm);
|
||||
const cookie = authCookie(user.id);
|
||||
await request(app).get('/api/addons/vacay/plan').set('Cookie', cookie);
|
||||
await request(app).put('/api/addons/vacay/plan').set('Cookie', cookie).send({ carry_over_enabled: true });
|
||||
await request(app).post('/api/addons/vacay/years').set('Cookie', cookie).send({ year: 2025 });
|
||||
await request(app).post('/api/addons/vacay/years').set('Cookie', cookie).send({ year: 2026 });
|
||||
const half = await request(app)
|
||||
.post('/api/addons/vacay/entries/toggle')
|
||||
.set('Cookie', cookie)
|
||||
.send({ date: '2025-06-16', year: 2025, type: 'vacation', fraction: 0.5 });
|
||||
expect(half.status).toBe(200);
|
||||
|
||||
// Reading 2025 writes what is left of it into 2026: 30 days less a half day.
|
||||
expect((await request(app).get('/api/addons/vacay/stats/2025').set('Cookie', cookie)).status).toBe(200);
|
||||
const next = await request(app).get('/api/addons/vacay/stats/2026').set('Cookie', cookie);
|
||||
expect(next.status).toBe(200);
|
||||
const mine = (next.body.stats as Array<{ user_id: number; carried_over: number }>).find(
|
||||
(s) => s.user_id === user.id,
|
||||
);
|
||||
expect(mine?.carried_over).toBe(29.5);
|
||||
const [row] = await findRows(orm, VacayUserYears, { user: user.id, year: 2026 });
|
||||
expect(row.carried_over).toBe(29.5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Vacay color', () => {
|
||||
it('VACAY-024 — PUT /api/addons/vacay/color sets user color in plan', async () => {
|
||||
const { user } = await makeUser(orm);
|
||||
|
||||
Reference in New Issue
Block a user