2023-06-08 11:01:07 -04:00
|
|
|
import { assetEntityStub, authStub, newAssetRepositoryMock } from '@test';
|
2023-06-15 14:05:30 -04:00
|
|
|
import { when } from 'jest-when';
|
|
|
|
import { AssetService, IAssetRepository, mapAsset } from '.';
|
2023-02-25 09:12:03 -05:00
|
|
|
|
|
|
|
describe(AssetService.name, () => {
|
|
|
|
let sut: AssetService;
|
2023-03-02 21:47:08 -05:00
|
|
|
let assetMock: jest.Mocked<IAssetRepository>;
|
2023-02-25 09:12:03 -05:00
|
|
|
|
|
|
|
it('should work', () => {
|
|
|
|
expect(sut).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2023-03-02 21:47:08 -05:00
|
|
|
assetMock = newAssetRepositoryMock();
|
2023-05-26 15:43:24 -04:00
|
|
|
sut = new AssetService(assetMock);
|
2023-03-02 21:47:08 -05:00
|
|
|
});
|
2023-05-21 08:26:06 +02:00
|
|
|
|
|
|
|
describe('get map markers', () => {
|
|
|
|
it('should get geo information of assets', async () => {
|
|
|
|
assetMock.getMapMarkers.mockResolvedValue(
|
|
|
|
[assetEntityStub.withLocation].map((asset) => ({
|
|
|
|
id: asset.id,
|
|
|
|
|
|
|
|
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
|
|
|
|
lat: asset.exifInfo!.latitude!,
|
|
|
|
|
|
|
|
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
|
|
|
|
lon: asset.exifInfo!.longitude!,
|
|
|
|
})),
|
|
|
|
);
|
|
|
|
|
|
|
|
const markers = await sut.getMapMarkers(authStub.user1, {});
|
|
|
|
|
|
|
|
expect(markers).toHaveLength(1);
|
|
|
|
expect(markers[0]).toEqual({
|
|
|
|
id: assetEntityStub.withLocation.id,
|
|
|
|
lat: 100,
|
|
|
|
lon: 100,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-06-15 14:05:30 -04:00
|
|
|
|
|
|
|
describe('getMemoryLane', () => {
|
|
|
|
it('should get pictures for each year', async () => {
|
|
|
|
assetMock.getByDate.mockResolvedValue([]);
|
|
|
|
|
|
|
|
await expect(sut.getMemoryLane(authStub.admin, { timestamp: new Date(2023, 5, 15), years: 10 })).resolves.toEqual(
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(assetMock.getByDate).toHaveBeenCalledTimes(10);
|
|
|
|
expect(assetMock.getByDate.mock.calls).toEqual([
|
|
|
|
[authStub.admin.id, new Date('2022-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2021-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2020-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2019-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2018-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2017-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2016-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2015-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2014-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2013-06-15T00:00:00.000Z')],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should keep hours from the date', async () => {
|
|
|
|
assetMock.getByDate.mockResolvedValue([]);
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
sut.getMemoryLane(authStub.admin, { timestamp: new Date(2023, 5, 15, 5), years: 2 }),
|
|
|
|
).resolves.toEqual([]);
|
|
|
|
|
|
|
|
expect(assetMock.getByDate).toHaveBeenCalledTimes(2);
|
|
|
|
expect(assetMock.getByDate.mock.calls).toEqual([
|
|
|
|
[authStub.admin.id, new Date('2022-06-15T05:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2021-06-15T05:00:00.000Z')],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set the title correctly', async () => {
|
|
|
|
when(assetMock.getByDate)
|
|
|
|
.calledWith(authStub.admin.id, new Date('2022-06-15T00:00:00.000Z'))
|
|
|
|
.mockResolvedValue([assetEntityStub.image]);
|
|
|
|
when(assetMock.getByDate)
|
|
|
|
.calledWith(authStub.admin.id, new Date('2021-06-15T00:00:00.000Z'))
|
|
|
|
.mockResolvedValue([assetEntityStub.video]);
|
|
|
|
|
|
|
|
await expect(sut.getMemoryLane(authStub.admin, { timestamp: new Date(2023, 5, 15), years: 2 })).resolves.toEqual([
|
|
|
|
{ title: '1 year since...', assets: [mapAsset(assetEntityStub.image)] },
|
|
|
|
{ title: '2 years since...', assets: [mapAsset(assetEntityStub.video)] },
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(assetMock.getByDate).toHaveBeenCalledTimes(2);
|
|
|
|
expect(assetMock.getByDate.mock.calls).toEqual([
|
|
|
|
[authStub.admin.id, new Date('2022-06-15T00:00:00.000Z')],
|
|
|
|
[authStub.admin.id, new Date('2021-06-15T00:00:00.000Z')],
|
|
|
|
]);
|
|
|
|
});
|
2023-02-25 09:12:03 -05:00
|
|
|
});
|