mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-14 02:29:38 +00:00
fix: restore process sets currentDay
This commit is contained in:
committed by
Carlos Valente
parent
1b55254834
commit
f8cde5d627
@@ -13,6 +13,7 @@ describe('isRestorePoint()', () => {
|
||||
pausedAt: 3,
|
||||
firstStart: 1,
|
||||
startEpoch: 1,
|
||||
currentDay: 0,
|
||||
};
|
||||
expect(isRestorePoint(restorePoint)).toBe(true);
|
||||
|
||||
@@ -24,6 +25,21 @@ describe('isRestorePoint()', () => {
|
||||
pausedAt: null,
|
||||
firstStart: 1,
|
||||
startEpoch: 1,
|
||||
currentDay: 2,
|
||||
};
|
||||
expect(isRestorePoint(restorePoint)).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts null start fields', () => {
|
||||
const restorePoint: RestorePoint = {
|
||||
playback: Playback.Stop,
|
||||
selectedEventId: null,
|
||||
startedAt: null,
|
||||
addedTime: 0,
|
||||
pausedAt: null,
|
||||
firstStart: null,
|
||||
startEpoch: null,
|
||||
currentDay: null,
|
||||
};
|
||||
expect(isRestorePoint(restorePoint)).toBe(true);
|
||||
});
|
||||
@@ -63,5 +79,39 @@ describe('isRestorePoint()', () => {
|
||||
};
|
||||
expect(isRestorePoint(restorePoint)).toBe(false);
|
||||
});
|
||||
it('with missing firstStart', () => {
|
||||
const restorePoint = {
|
||||
playback: Playback.Roll,
|
||||
selectedEventId: '123',
|
||||
startedAt: null,
|
||||
addedTime: 0,
|
||||
pausedAt: null,
|
||||
startEpoch: 1,
|
||||
};
|
||||
expect(isRestorePoint(restorePoint)).toBe(false);
|
||||
});
|
||||
it('with missing startEpoch', () => {
|
||||
const restorePoint = {
|
||||
playback: Playback.Roll,
|
||||
selectedEventId: '123',
|
||||
startedAt: null,
|
||||
addedTime: 0,
|
||||
pausedAt: null,
|
||||
firstStart: 1,
|
||||
};
|
||||
expect(isRestorePoint(restorePoint)).toBe(false);
|
||||
});
|
||||
it('with missing currentDay', () => {
|
||||
const restorePoint = {
|
||||
playback: Playback.Roll,
|
||||
selectedEventId: '123',
|
||||
startedAt: null,
|
||||
addedTime: 0,
|
||||
pausedAt: null,
|
||||
firstStart: 1,
|
||||
startEpoch: 1,
|
||||
};
|
||||
expect(isRestorePoint(restorePoint)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,6 +17,7 @@ describe('restoreService', () => {
|
||||
pausedAt: 9087,
|
||||
firstStart: 1234,
|
||||
startEpoch: 1234,
|
||||
currentDay: 0,
|
||||
};
|
||||
|
||||
const mockRead = vi.fn().mockResolvedValue(expected);
|
||||
@@ -35,6 +36,7 @@ describe('restoreService', () => {
|
||||
pausedAt: null,
|
||||
firstStart: 1234,
|
||||
startEpoch: 1234,
|
||||
currentDay: null,
|
||||
};
|
||||
|
||||
const mockRead = vi.fn().mockResolvedValue(expected);
|
||||
@@ -82,6 +84,7 @@ describe('restoreService', () => {
|
||||
pausedAt: 1234,
|
||||
firstStart: 1234,
|
||||
startEpoch: 1234,
|
||||
currentDay: 0,
|
||||
};
|
||||
|
||||
const mockWrite = vi.fn().mockResolvedValue(undefined);
|
||||
@@ -90,6 +93,39 @@ describe('restoreService', () => {
|
||||
expect(mockWrite).toHaveBeenCalledWith(testData);
|
||||
});
|
||||
|
||||
it('writes updated data when values change', async () => {
|
||||
const firstData: RestorePoint = {
|
||||
playback: Playback.Play,
|
||||
selectedEventId: '2345',
|
||||
startedAt: 2345,
|
||||
addedTime: 2345,
|
||||
pausedAt: 2345,
|
||||
firstStart: 2345,
|
||||
startEpoch: 2345,
|
||||
currentDay: 0,
|
||||
};
|
||||
|
||||
const updatedData: RestorePoint = {
|
||||
playback: Playback.Pause,
|
||||
selectedEventId: '3456',
|
||||
startedAt: 3456,
|
||||
addedTime: 3456,
|
||||
pausedAt: 3456,
|
||||
firstStart: 3456,
|
||||
startEpoch: 3456,
|
||||
currentDay: 1,
|
||||
};
|
||||
|
||||
const mockWrite = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
await restoreService.save(firstData, mockWrite);
|
||||
await restoreService.save(updatedData, mockWrite);
|
||||
|
||||
expect(mockWrite).toHaveBeenCalledTimes(2);
|
||||
expect(mockWrite).toHaveBeenNthCalledWith(1, firstData);
|
||||
expect(mockWrite).toHaveBeenNthCalledWith(2, updatedData);
|
||||
});
|
||||
|
||||
it('handles write failures gracefully', async () => {
|
||||
const testData: RestorePoint = {
|
||||
playback: Playback.Pause,
|
||||
@@ -99,6 +135,7 @@ describe('restoreService', () => {
|
||||
pausedAt: 5678,
|
||||
firstStart: 5678,
|
||||
startEpoch: 5678,
|
||||
currentDay: 0,
|
||||
};
|
||||
|
||||
const mockWrite = vi.fn().mockRejectedValue(new Error('Write failed'));
|
||||
|
||||
Reference in New Issue
Block a user