mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(server): remove inactive sessions (#9121)
* feat(server): remove inactive sessions * add rudimentary unit test --------- Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
This commit is contained in:
parent
953896a35a
commit
034c928d9e
12 changed files with 82 additions and 3 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { UserEntity } from 'src/entities/user.entity';
|
||||
import { JobStatus } from 'src/interfaces/job.interface';
|
||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { ISessionRepository } from 'src/interfaces/session.interface';
|
||||
import { SessionService } from 'src/services/session.service';
|
||||
|
|
@ -26,6 +28,32 @@ describe('SessionService', () => {
|
|||
expect(sut).toBeDefined();
|
||||
});
|
||||
|
||||
describe('handleCleanup', () => {
|
||||
it('should return skipped if nothing is to be deleted', async () => {
|
||||
sessionMock.search.mockResolvedValue([]);
|
||||
await expect(sut.handleCleanup()).resolves.toEqual(JobStatus.SKIPPED);
|
||||
expect(sessionMock.search).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should delete sessions', async () => {
|
||||
sessionMock.search.mockResolvedValue([
|
||||
{
|
||||
createdAt: new Date('1970-01-01T00:00:00.00Z'),
|
||||
updatedAt: new Date('1970-01-02T00:00:00.00Z'),
|
||||
deviceOS: '',
|
||||
deviceType: '',
|
||||
id: '123',
|
||||
token: '420',
|
||||
user: {} as UserEntity,
|
||||
userId: '42',
|
||||
},
|
||||
]);
|
||||
|
||||
await expect(sut.handleCleanup()).resolves.toEqual(JobStatus.SUCCESS);
|
||||
expect(sessionMock.delete).toHaveBeenCalledWith('123');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAll', () => {
|
||||
it('should get the devices', async () => {
|
||||
sessionMock.getByUserId.mockResolvedValue([sessionStub.valid, sessionStub.inactive]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue