photoprism/frontend/tests/unit/model/photo_test.js

1509 lines
40 KiB
JavaScript
Raw Normal View History

import "../fixtures";
2021-07-05 16:41:43 +02:00
import { Photo, FormatJpeg } from "model/photo";
2020-07-02 10:03:00 +02:00
let chai = require("chai/chai");
2019-08-13 08:09:55 +02:00
let assert = chai.assert;
2019-08-07 12:18:04 +02:00
describe("model/photo", () => {
it("should get photo entity name", () => {
const values = { UID: 5, Title: "Crazy Cat" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.getEntityName();
assert.equal(result, "Crazy Cat");
});
2019-08-06 16:11:30 +02:00
it("should get photo uuid", () => {
const values = { ID: 5, Title: "Crazy Cat", UID: 789 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.getId();
assert.equal(result, 789);
});
2019-08-06 16:11:30 +02:00
it("should get photo title", () => {
const values = { ID: 5, Title: "Crazy Cat", UID: 789 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.getTitle();
assert.equal(result, "Crazy Cat");
});
2019-08-06 16:11:30 +02:00
it("should get photo maps link", () => {
const values = { ID: 5, Title: "Crazy Cat", Lat: 36.442881666666665, Lng: 28.229493333333334 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.getGoogleMapsLink();
assert.equal(result, "https://www.google.com/maps/place/36.442881666666665,28.229493333333334");
});
2019-08-06 16:11:30 +02:00
it("should get photo thumbnail url", () => {
const values = { ID: 5, Title: "Crazy Cat", Hash: 345982 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.thumbnailUrl("tile500");
assert.equal(result, "/api/v1/t/345982/public/tile500");
const values2 = {
ID: 10,
UID: "ABC127",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
],
};
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
const result2 = photo2.thumbnailUrl("tile500");
assert.equal(result2, "/api/v1/t/1xxbgdt55/public/tile500");
const values3 = {
ID: 10,
UID: "ABC127",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Width: 500,
Height: 600,
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
const result3 = photo3.thumbnailUrl("tile500");
assert.equal(result3, "/api/v1/svg/photo");
});
2019-08-07 12:18:04 +02:00
it("should get classes", () => {
const values2 = {
ID: 10,
UID: "ABC127",
Type: "video",
Portrait: true,
Favorite: true,
Private: true,
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Video: true,
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
{
UID: "123fde",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Width: 500,
Height: 600,
Hash: "1xxbgdkkk",
},
],
};
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
const result2 = photo2.classes();
assert.include(result2, "is-photo");
assert.include(result2, "uid-ABC127");
assert.include(result2, "type-video");
assert.include(result2, "is-portrait");
assert.include(result2, "is-favorite");
assert.include(result2, "is-private");
assert.include(result2, "is-stack");
assert.include(result2, "is-playable");
});
2019-08-07 12:18:04 +02:00
it("should get photo download url", () => {
const values = { ID: 5, Title: "Crazy Cat", Hash: 345982 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.getDownloadUrl();
assert.equal(result, "/api/v1/dl/345982?t=2lbh9x09");
});
2019-08-07 12:18:04 +02:00
it("should calculate photo size", () => {
const values = { ID: 5, Title: "Crazy Cat", Width: 500, Height: 200 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.calculateSize(500, 200);
assert.equal(result.width, 500);
assert.equal(result.height, 200);
});
2019-08-07 12:18:04 +02:00
it("should calculate photo size with srcAspectRatio < maxAspectRatio", () => {
const values = { ID: 5, Title: "Crazy Cat", Width: 500, Height: 200 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.calculateSize(300, 50);
assert.equal(result.width, 125);
assert.equal(result.height, 50);
});
2019-08-07 12:18:04 +02:00
it("should calculate photo size with srcAspectRatio > maxAspectRatio", () => {
const values = { ID: 5, Title: "Crazy Cat", Width: 500, Height: 200 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.calculateSize(400, 300);
assert.equal(result.width, 400);
assert.equal(result.height, 160);
});
2020-10-19 11:36:07 +02:00
it("should get local day string", () => {
const values = { ID: 5, Title: "Crazy Cat", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.localDayString();
// Current day of the month (changes):
assert.equal(result.length, 2);
const values2 = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
TimeZone: "UTC",
Day: 8,
};
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
const result2 = photo2.localDayString();
assert.equal(result2, "08");
});
2020-10-19 11:36:07 +02:00
it("should get local month string", () => {
const values = { ID: 5, Title: "Crazy Cat", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.localMonthString();
assert.equal(result, (new Date().getMonth() + 1).toString().padStart(2, "0"));
const values2 = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
TimeZone: "UTC",
Month: 8,
};
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
const result2 = photo2.localMonthString();
assert.equal(result2, "08");
});
2020-10-19 11:36:07 +02:00
it("should get local year string", () => {
const values = { ID: 5, Title: "Crazy Cat", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.localYearString();
assert.equal(result, new Date().getFullYear().toString().padStart(4, "0"));
const values2 = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
TimeZone: "UTC",
Year: 2010,
};
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
const result2 = photo2.localYearString();
assert.equal(result2, "2010");
});
2020-10-19 11:36:07 +02:00
it("should get local date string", () => {
const values = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
TimeZone: "UTC",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.localDateString();
assert.equal(result, "2012-07-08T14:45:39Z");
2021-03-11 11:55:38 +01:00
});
2020-10-19 11:36:07 +02:00
it("should get local date", () => {
const values = {
ID: 5,
Title: "Crazy Cat",
TakenAt: "2012-07-08T14:45:39Z",
TimeZone: "Indian/Reunion",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.localDate();
assert.equal(String(result), "2012-07-08T14:45:39.000Z");
});
2020-07-01 12:04:09 +02:00
it("UTC", () => {
const values = {
ID: 9999,
Title: "Video",
TakenAt: "2012-07-08T14:45:39Z",
TakenAtLocal: "2012-07-08T14:45:39Z",
TimeZone: "UTC",
};
const photo = new Photo(values);
assert.equal(String(photo.localDateString("10:00:00")), "2012-07-08T10:00:00Z");
const result = photo.localDate();
assert.equal(String(result), "2012-07-08T14:45:39.000Z");
});
it("should get date string", () => {
const values = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
TimeZone: "UTC",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.getDateString();
assert.equal(result, "Sunday, July 8, 2012, 2:45 PM");
const values2 = { ID: 5, Title: "Crazy Cat", TakenAtLocal: "", TakenAt: "", TimeZone: "UTC" };
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
const result2 = photo2.getDateString();
assert.equal(result2, "Unknown");
const values3 = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
const result3 = photo3.getDateString();
assert.equal(result3, "Sunday, July 8, 2012");
const values4 = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
Month: -1,
};
2021-03-11 11:55:38 +01:00
const photo4 = new Photo(values4);
const result4 = photo4.getDateString();
assert.equal(result4, "2012");
const values5 = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
Day: -1,
};
2021-03-11 11:55:38 +01:00
const photo5 = new Photo(values5);
const result5 = photo5.getDateString();
assert.equal(result5, "July 2012");
});
2019-08-07 12:18:04 +02:00
it("should get short date string", () => {
const values = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
TimeZone: "UTC",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.shortDateString();
assert.equal(result, "Jul 8, 2012");
const values2 = { ID: 5, Title: "Crazy Cat", TakenAtLocal: "", TakenAt: "", TimeZone: "UTC" };
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
const result2 = photo2.shortDateString();
assert.equal(result2, "Unknown");
const values3 = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
const result3 = photo3.shortDateString();
assert.equal(result3, "Jul 8, 2012");
const values4 = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
Month: -1,
};
2021-03-11 11:55:38 +01:00
const photo4 = new Photo(values4);
const result4 = photo4.shortDateString();
assert.equal(result4, "2012");
const values5 = {
ID: 5,
Title: "Crazy Cat",
TakenAtLocal: "2012-07-08T14:45:39Z",
TakenAt: "2012-07-08T14:45:39Z",
Day: -1,
};
2021-03-11 11:55:38 +01:00
const photo5 = new Photo(values5);
const result5 = photo5.shortDateString();
assert.equal(result5, "July 2012");
});
2019-08-07 12:18:04 +02:00
it("should test whether photo has location", () => {
const values = { ID: 5, Title: "Crazy Cat", Lat: 36.442881666666665, Lng: 28.229493333333334 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.hasLocation();
assert.equal(result, true);
});
2019-08-07 12:18:04 +02:00
it("should test whether photo has location", () => {
const values = { ID: 5, Title: "Crazy Cat", Lat: 0, Lng: 0 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.hasLocation();
assert.equal(result, false);
});
2019-08-07 12:18:04 +02:00
it("should get location", () => {
const values = {
ID: 5,
Title: "Crazy Cat",
CellID: 6,
CellCategory: "viewpoint",
PlaceLabel: "Cape Point, South Africa",
PlaceCountry: "South Africa",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.locationInfo();
assert.equal(result, "Cape Point, South Africa");
});
2019-08-07 12:18:04 +02:00
it("should get location", () => {
const values = {
ID: 5,
Title: "Crazy Cat",
CellID: 6,
CellCategory: "viewpoint",
PlaceLabel: "Cape Point, State, South Africa",
PlaceCountry: "South Africa",
PlaceCity: "Cape Town",
PlaceCounty: "County",
PlaceState: "State",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.locationInfo();
assert.equal(result, "Cape Point, State, South Africa");
});
2019-08-07 12:18:04 +02:00
it("should get location", () => {
const values = {
ID: 5,
Title: "Crazy Cat",
CellCategory: "viewpoint",
CellName: "Cape Point",
PlaceCountry: "Africa",
PlaceCity: "Cape Town",
PlaceCounty: "County",
PlaceState: "State",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.locationInfo();
assert.equal(result, "Unknown");
});
2019-08-07 12:18:04 +02:00
it("should get location", () => {
const values = { ID: 5, Title: "Crazy Cat", CountryName: "Africa", PlaceCity: "Cape Town" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.locationInfo();
assert.equal(result, "Unknown");
});
2020-07-01 14:49:12 +02:00
it("should get camera", () => {
const values = { ID: 5, Title: "Crazy Cat", CameraModel: "EOSD10", CameraMake: "Canon" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.getCamera();
assert.equal(result, "Canon EOSD10");
const values2 = {
ID: 10,
UID: "ABC127",
Files: [
{
UID: "123fgb",
2021-03-11 11:55:38 +01:00
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "jpg",
Hash: "1xxbgdt55",
},
],
2021-03-11 11:55:38 +01:00
Camera: {
Make: "Canon",
Model: "abc",
},
};
const photo2 = new Photo(values2);
assert.equal(photo2.getCamera(), "Canon abc");
});
2019-08-06 16:11:30 +02:00
it("should get camera", () => {
const values = { ID: 5, Title: "Crazy Cat" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.getCamera();
assert.equal(result, "Unknown");
});
2019-08-07 14:16:37 +02:00
it("should get collection resource", () => {
2021-03-11 11:55:38 +01:00
const result = Photo.getCollectionResource();
assert.equal(result, "photos");
});
2019-08-07 12:27:57 +02:00
it("should return batch size", () => {
2021-03-11 15:18:05 +01:00
assert.equal(Photo.batchSize(), 60);
});
it("should get model name", () => {
2021-03-11 11:55:38 +01:00
const result = Photo.getModelName();
assert.equal(result, "Photo");
});
2019-08-07 12:27:57 +02:00
it("should like photo", () => {
const values = { ID: 5, Title: "Crazy Cat", CountryName: "Africa", Favorite: false };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.Favorite, false);
photo.like();
assert.equal(photo.Favorite, true);
});
2019-08-09 13:50:07 +02:00
it("should unlike photo", () => {
const values = {
ID: 5,
UID: "abc123",
Title: "Crazy Cat",
CountryName: "Africa",
Favorite: true,
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.Favorite, true);
photo.unlike();
assert.equal(photo.Favorite, false);
});
2019-08-09 13:50:07 +02:00
2021-03-11 11:55:38 +01:00
/* TODO
2019-08-09 13:50:07 +02:00
it("should toggle like", () => {
const values = {ID: 5, Title: "Crazy Cat", CountryName: "Africa", Favorite: true};
2019-08-09 13:50:07 +02:00
const photo = new Photo(values);
assert.equal(photo.Favorite, true);
2019-08-09 13:50:07 +02:00
photo.toggleLike();
assert.equal(photo.Favorite, false);
2019-08-09 13:50:07 +02:00
photo.toggleLike();
assert.equal(photo.Favorite, true);
2019-08-09 13:50:07 +02:00
});
*/
2019-08-09 13:50:07 +02:00
it("should get photo defaults", () => {
const values = { ID: 5, UID: "ABC123" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.getDefaults();
assert.equal(result.UID, "");
});
2020-06-30 16:53:12 +02:00
it("should get photos base name", () => {
const values = {
ID: 8,
UID: "ABC123",
Filename: "1980/01/superCuteKitten.jpg",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "TypeJpeg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.baseName();
assert.equal(result, "superCuteKitten.jpg");
const result2 = photo.baseName(5);
assert.equal(result2, "supe…");
});
2020-06-30 16:53:12 +02:00
it("should refresh file attributes", () => {
const values2 = { ID: 5, UID: "ABC123" };
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
photo2.refreshFileAttr();
assert.equal(photo2.Width, undefined);
assert.equal(photo2.Height, undefined);
assert.equal(photo2.Hash, undefined);
const values = {
ID: 8,
UID: "ABC123",
Filename: "1980/01/superCuteKitten.jpg",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "TypeJpeg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.Width, undefined);
assert.equal(photo.Height, undefined);
assert.equal(photo.Hash, undefined);
photo.refreshFileAttr();
assert.equal(photo.Width, 500);
assert.equal(photo.Height, 600);
assert.equal(photo.Hash, "1xxbgdt53");
});
2020-06-30 16:53:12 +02:00
it("should return is playable", () => {
const values = {
ID: 8,
UID: "ABC123",
Filename: "1980/01/superCuteKitten.jpg",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "TypeJpeg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.isPlayable(), false);
const values2 = { ID: 9, UID: "ABC163" };
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
assert.equal(photo2.isPlayable(), false);
const values3 = {
ID: 10,
UID: "ABC127",
Filename: "1980/01/superCuteKitten.mp4",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
Video: true,
FileType: "mp4",
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
assert.equal(photo3.isPlayable(), true);
const values4 = {
ID: 1,
UID: "ABC128",
Filename: "1980/01/superCuteKitten.jpg",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: false,
Video: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
Codec: "avc1",
},
],
};
2021-03-11 11:55:38 +01:00
const photo4 = new Photo(values4);
assert.equal(photo4.isPlayable(), true);
});
2020-07-01 12:04:09 +02:00
it("should return video params", () => {
const values3 = {
ID: 10,
UID: "ABC127",
Filename: "1980/01/superCuteKitten.mp4",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
Video: true,
FileType: "mp4",
Width: 900,
Height: 600,
Hash: "1xxbgdt55",
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
const result = photo3.videoParams();
assert.equal(result.height, "463");
assert.equal(result.width, "695");
assert.equal(result.loop, false);
assert.equal(result.uri, "/api/v1/videos/1xxbgdt55/public/avc");
const values = {
ID: 11,
UID: "ABC127",
Filename: "1980/01/superCuteKitten.mp4",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
Video: true,
FileType: "mp4",
Width: 0,
Height: 0,
Hash: "1xxbgdt55",
},
{
UID: "123fpp",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
Width: 5000,
Height: 5000,
Hash: "1xxbgdt544",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result2 = photo.videoParams();
assert.equal(result2.height, "440");
assert.equal(result2.width, "440");
assert.equal(result2.loop, false);
assert.equal(result2.uri, "/api/v1/videos/1xxbgdt55/public/avc");
});
2020-07-01 12:04:09 +02:00
it("should return videofile", () => {
const values = {
ID: 8,
UID: "ABC123",
Filename: "1980/01/superCuteKitten.jpg",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.videoFile(), undefined);
const values2 = { ID: 9, UID: "ABC163" };
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
assert.equal(photo2.videoFile(), false);
const values3 = {
ID: 10,
UID: "ABC127",
Filename: "1980/01/superCuteKitten.mp4",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
const file = photo3.videoFile();
assert.equal(photo3.videoFile().Name, "1980/01/superCuteKitten.mp4");
const values4 = {
ID: 1,
UID: "ABC128",
Filename: "1980/01/superCuteKitten.jpg",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: false,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
Codec: "avc1",
},
],
};
2021-03-11 11:55:38 +01:00
const photo4 = new Photo(values4);
assert.equal(photo4.videoFile().Name, "1980/01/superCuteKitten.jpg");
const file2 = photo4.videoFile();
});
2020-07-01 12:04:09 +02:00
it("should return video url", () => {
const values = {
ID: 8,
UID: "ABC123",
Filename: "1980/01/superCuteKitten.jpg",
Hash: "703cf8f274fbb265d49c6262825780e1",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.videoUrl(), "/api/v1/videos/703cf8f274fbb265d49c6262825780e1/public/avc");
const values2 = { ID: 9, UID: "ABC163", Hash: "2305e512e3b183ec982d60a8b608a8ca501973ba" };
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
assert.equal(
photo2.videoUrl(),
"/api/v1/videos/2305e512e3b183ec982d60a8b608a8ca501973ba/public/avc"
);
const values3 = {
ID: 10,
UID: "ABC127",
Filename: "1980/01/superCuteKitten.mp4",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
2021-03-11 11:55:38 +01:00
assert.equal(photo3.videoUrl(), "/api/v1/videos/1xxbgdt55/public/avc");
const values4 = {
ID: 1,
UID: "ABC128",
Filename: "1980/01/superCuteKitten.jpg",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: false,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
Codec: "avc1",
},
],
};
2021-03-11 11:55:38 +01:00
const photo4 = new Photo(values4);
assert.equal(photo4.videoUrl(), "/api/v1/videos/1xxbgdt53/public/avc");
});
2020-06-30 16:53:12 +02:00
it("should return main file", () => {
const values = { ID: 9, UID: "ABC163", Width: 111, Height: 222 };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.mainFile(), photo);
const values2 = {
ID: 10,
2021-03-11 11:55:38 +01:00
UID: "ABC127",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: false,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt56",
},
],
};
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
const file = photo2.mainFile();
assert.equal(file.Name, "1980/01/superCuteKitten.jpg");
const values3 = {
ID: 1,
2021-03-11 11:55:38 +01:00
UID: "ABC128",
Files: [
{
UID: "123fgb",
Name: "1980/01/NotMainKitten.jpg",
Primary: false,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
{
UID: "123fgb",
Name: "1980/01/MainKitten.jpg",
Primary: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt54",
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
const file2 = photo3.mainFile();
assert.equal(file2.Name, "1980/01/MainKitten.jpg");
});
2020-07-01 12:04:09 +02:00
it("should return jpeg files", () => {
const values = { ID: 8, UID: "ABC123", Filename: "1980/01/superCuteKitten.jpg" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
const result = photo.jpegFiles();
assert.equal(result[0].Filename, "1980/01/superCuteKitten.jpg");
const values3 = {
ID: 10,
UID: "ABC127",
Filename: "1980/01/superCuteKitten.mp4",
FileUID: "123fgb",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: false,
FileType: FormatJpeg,
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
{
UID: "123fgz",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Width: 500,
Height: 600,
Hash: "1xxbgdt66",
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
const file = photo3.jpegFiles();
assert.equal(file[0].Name, "1980/01/superCuteKitten.jpg");
});
2020-07-01 14:49:12 +02:00
it("should return main hash", () => {
const values = { ID: 9, UID: "ABC163" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.mainFileHash(), "");
const values2 = {
ID: 10,
2021-03-11 11:55:38 +01:00
UID: "ABC127",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: false,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt56",
},
],
};
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
assert.equal(photo2.mainFileHash(), "1xxbgdt56");
});
2020-07-01 14:49:12 +02:00
it("should test filemodels", () => {
const values = { ID: 9, UID: "ABC163" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.empty(photo.fileModels());
const values2 = {
ID: 10,
2021-03-11 11:55:38 +01:00
UID: "ABC127",
Files: [
{
UID: "123fgb",
Name: "1980/01/cat.jpg",
Primary: false,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
{
UID: "123fgb",
Name: "1999/01/dog.jpg",
Primary: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt56",
},
],
};
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
assert.equal(photo2.fileModels()[0].Name, "1999/01/dog.jpg");
const values3 = {
ID: 10,
2021-03-11 11:55:38 +01:00
UID: "ABC127",
Files: [
{
UID: "123fgb",
Name: "1980/01/cat.jpg",
Primary: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
{
UID: "123fgb",
Name: "1999/01/dog.jpg",
Primary: false,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt56",
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
assert.equal(photo3.fileModels()[0].Name, "1980/01/cat.jpg");
const values4 = {
ID: 10,
2021-03-11 11:55:38 +01:00
UID: "ABC127",
Files: [
{
UID: "123fgb",
Name: "1980/01/cat.jpg",
Primary: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
},
],
};
2021-03-11 11:55:38 +01:00
const photo4 = new Photo(values4);
assert.equal(photo4.fileModels()[0].Name, "1980/01/cat.jpg");
});
2020-07-01 14:49:12 +02:00
it("should get country name", () => {
const values = { ID: 5, UID: "ABC123", Country: "zz" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.countryName(), "Unknown");
const values2 = { ID: 5, UID: "ABC123", Country: "es" };
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
assert.equal(photo2.countryName(), "Spain");
});
2020-07-01 14:49:12 +02:00
it("should get location info", () => {
const values = { ID: 5, UID: "ABC123", Country: "zz", PlaceID: "zz", PlaceLabel: "Nice beach" };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.locationInfo(), "Nice beach");
const values2 = { ID: 5, UID: "ABC123", Country: "es", PlaceID: "zz" };
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
assert.equal(photo2.locationInfo(), "Spain");
});
2020-07-01 16:16:47 +02:00
it("should return video info", () => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 9,
UID: "ABC163",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.getVideoInfo(), "Video");
const values2 = {
ID: 10,
UID: "ABC127",
Files: [
{
2021-03-11 11:55:38 +01:00
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Hash: "1xxbgdt55",
},
],
};
2021-03-11 11:55:38 +01:00
const photo2 = new Photo(values2);
assert.equal(photo2.getVideoInfo(), "Video");
const values3 = {
ID: 10,
UID: "ABC127",
Files: [
{
2021-03-11 11:55:38 +01:00
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
2021-03-11 11:55:38 +01:00
Width: 500,
Height: 600,
2021-03-11 11:55:38 +01:00
Hash: "1xxbgdt55",
Duration: 6000,
2021-03-11 11:55:38 +01:00
Size: 222897,
Codec: "avc1",
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
assert.equal(photo3.getVideoInfo(), "6µs, AVC1, 500 × 600, 0.2 MB");
const values4 = {
ID: 10,
UID: "ABC127",
Files: [
{
2021-03-11 11:55:38 +01:00
UID: "123fgb",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
2021-03-11 11:55:38 +01:00
Hash: "1xxbgdt55",
Duration: 6000,
2021-03-11 11:55:38 +01:00
Size: 10240,
Codec: "avc1",
},
{
2021-03-11 11:55:38 +01:00
UID: "345fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "jpg",
2021-03-11 11:55:38 +01:00
Hash: "1xxbgjhu5",
Width: 300,
Height: 500,
},
],
};
2021-03-11 11:55:38 +01:00
const photo4 = new Photo(values4);
assert.equal(photo4.getVideoInfo(), "6µs, AVC1, 300 × 500, 10.0 KB");
});
2020-07-01 16:16:47 +02:00
it("should return photo info", () => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 9,
UID: "ABC163",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.getPhotoInfo(), "Unknown");
const values2 = {
ID: 10,
UID: "ABC127",
Files: [
{
2021-03-11 11:55:38 +01:00
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "jpg",
Hash: "1xxbgdt55",
},
],
2021-03-11 11:55:38 +01:00
Size: "300",
Camera: {
Make: "Canon",
Model: "abc",
},
};
const photo2 = new Photo(values2);
assert.equal(photo2.getPhotoInfo(), "Canon abc");
const values3 = {
ID: 10,
UID: "ABC127",
CameraMake: "Canon",
CameraModel: "abcde",
Files: [
{
UID: "123fgb",
2021-03-11 11:55:38 +01:00
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Width: 500,
2021-03-11 11:55:38 +01:00
Height: 600,
Hash: "1xxbgdt55",
Duration: 6000,
Codec: "avc1",
},
],
};
2021-03-11 11:55:38 +01:00
const photo3 = new Photo(values3);
assert.equal(photo3.getPhotoInfo(), "Canon abcde, AVC1, 500 × 600");
const values4 = {
ID: 10,
UID: "ABC127",
Files: [
{
UID: "123fgb",
2021-03-11 11:55:38 +01:00
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
2021-03-11 11:55:38 +01:00
Width: 500,
Height: 600,
Hash: "1xxbgdt55",
Duration: 6000,
Size: 300,
Codec: "avc1",
},
{
2021-03-11 11:55:38 +01:00
UID: "123fgx",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "jpg",
Width: 800,
2021-03-11 11:55:38 +01:00
Height: 600,
Hash: "1xxbgdt55",
Duration: 6000,
2021-03-11 11:55:38 +01:00
Size: 200,
Codec: "avc1",
},
],
};
2021-03-11 11:55:38 +01:00
const photo4 = new Photo(values4);
assert.equal(photo3.getPhotoInfo(), "Canon abcde, AVC1, 500 × 600");
});
2020-07-01 16:16:47 +02:00
it("should archive photo", () => {
const values = { ID: 5, Title: "Crazy Cat", CountryName: "Africa", Favorite: false };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
return photo
.archive()
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(200, response.status);
assert.deepEqual({ photos: [1, 3] }, response.data);
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
2021-03-11 11:55:38 +01:00
});
2020-07-01 16:16:47 +02:00
it("should approve photo", () => {
const values = {
ID: 5,
UID: "pqbemz8276mhtobh",
Title: "Crazy Cat",
CountryName: "Africa",
Favorite: false,
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
return photo
.approve()
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(200, response.status);
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
2021-03-11 11:55:38 +01:00
});
2020-07-01 16:50:28 +02:00
it("should toggle private", () => {
const values = { ID: 5, Title: "Crazy Cat", CountryName: "Africa", Private: true };
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
assert.equal(photo.Private, true);
photo.togglePrivate();
assert.equal(photo.Private, false);
photo.togglePrivate();
assert.equal(photo.Private, true);
});
2020-07-03 17:24:48 +02:00
it("should mark photo as primary", (done) => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
Files: [
{
UID: "fqbfk181n4ca5sud",
2021-03-11 11:55:38 +01:00
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Hash: "1xxbgdt55",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
photo
.primaryFile("fqbfk181n4ca5sud")
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(response.Files[0].Primary, true);
done();
})
.catch((error) => {
2021-03-11 11:55:38 +01:00
done(error);
});
2021-03-11 11:55:38 +01:00
});
2020-10-19 11:36:07 +02:00
it("should unstack", (done) => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
Files: [
{
2021-03-11 11:55:38 +01:00
UID: "fqbfk181n4ca5sud",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Hash: "1xxbgdt55",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
photo
.unstackFile("fqbfk181n4ca5sud")
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(response.success, "ok");
done();
})
.catch((error) => {
2021-03-11 11:55:38 +01:00
done(error);
});
2021-03-11 11:55:38 +01:00
});
2020-07-03 17:24:48 +02:00
it("should delete file", (done) => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
Files: [
{
UID: "fqbfk181n4ca5sud",
2021-03-11 11:55:38 +01:00
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Hash: "1xxbgdt55",
},
{
2021-03-11 11:55:38 +01:00
UID: "fqbfk181n4ca5abc",
Name: "1980/01/superCuteKitten.mp4",
Primary: true,
FileType: "mp4",
Hash: "1xxbgdt89",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
photo
.deleteFile("fqbfk181n4ca5sud")
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(response.success, "successfully deleted");
done();
})
.catch((error) => {
2021-03-11 11:55:38 +01:00
done(error);
});
2021-03-11 11:55:38 +01:00
});
2020-07-03 17:24:48 +02:00
it("should add label", (done) => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
photo
.addLabel("Cat")
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(response.success, "ok");
done();
})
.catch((error) => {
2021-03-11 11:55:38 +01:00
done(error);
});
2021-03-11 11:55:38 +01:00
});
2020-07-03 17:24:48 +02:00
it("should activate label", (done) => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
photo
.activateLabel(12345)
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(response.success, "ok");
done();
})
.catch((error) => {
2021-03-11 11:55:38 +01:00
done(error);
});
2021-03-11 11:55:38 +01:00
});
2020-07-03 17:24:48 +02:00
it("should rename label", (done) => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
photo
.renameLabel(12345, "Sommer")
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(response.success, "ok");
done();
})
.catch((error) => {
2021-03-11 11:55:38 +01:00
done(error);
});
2021-03-11 11:55:38 +01:00
});
it("should remove label", (done) => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
photo
.removeLabel(12345)
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(response.success, "ok");
done();
})
.catch((error) => {
2021-03-11 11:55:38 +01:00
done(error);
});
2021-03-11 11:55:38 +01:00
});
it("should test update", (done) => {
2021-03-11 11:55:38 +01:00
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
Lat: 1.1,
Lng: 3.3,
CameraID: 123,
Title: "Test Titel",
Description: "Super nice video",
2021-10-08 18:16:34 +02:00
Day: 10,
Country: "es",
Files: [
{
UID: "fqbfk181n4ca5sud",
2021-03-11 11:55:38 +01:00
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Hash: "1xxbgdt55",
},
],
2021-10-08 18:16:34 +02:00
Details: [
{
Keywords: "old",
Notes: "old notes",
Subject: "old subject",
Artist: "Old Artist",
Copyright: "ABC",
License: "test",
},
],
};
2021-03-11 11:55:38 +01:00
const photo = new Photo(values);
2021-10-06 16:42:53 +02:00
photo.Title = "New Title";
2021-10-08 17:48:31 +02:00
photo.Type = "newtype";
photo.Description = "New description";
photo.Day = 21;
photo.Country = "de";
photo.CameraID = "newcameraid";
photo.Details.Keywords = "newkeyword";
photo.Details.Notes = "New Notes";
photo.Details.Subject = "New Photo Subject";
photo.Details.Artist = "New Artist";
photo.Details.Copyright = "New Copyright";
photo.Details.License = "New License";
photo
.update()
.then((response) => {
2021-03-11 11:55:38 +01:00
assert.equal(response.TitleSrc, "manual");
done();
})
.catch((error) => {
2021-03-11 11:55:38 +01:00
done(error);
});
2021-10-06 16:42:53 +02:00
assert.equal(photo.Title, "New Title");
2021-10-08 17:48:31 +02:00
assert.equal(photo.Type, "newtype");
assert.equal(photo.Description, "New description");
assert.equal(photo.Day, 21);
assert.equal(photo.Country, "de");
assert.equal(photo.CameraID, "newcameraid");
assert.equal(photo.Details.Keywords, "newkeyword");
assert.equal(photo.Details.Notes, "New Notes");
assert.equal(photo.Details.Subject, "New Photo Subject");
assert.equal(photo.Details.Artist, "New Artist");
assert.equal(photo.Details.Copyright, "New Copyright");
assert.equal(photo.Details.License, "New License");
2021-10-06 16:42:53 +02:00
});
it("should test get Markers", () => {
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
Lat: 1.1,
Lng: 3.3,
CameraID: 123,
Title: "Test Titel",
Description: "Super nice video",
Files: [
{
UID: "fqbfk181n4ca5sud",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
2021-10-06 16:42:53 +02:00
Hash: "1xxbgdt55",
},
],
};
const photo = new Photo(values);
const result = photo.getMarkers(true);
assert.empty(result);
const values2 = {
ID: 10,
UID: "pqbemz8276mhtobh",
Lat: 1.1,
Lng: 3.3,
CameraID: 123,
Title: "Test Titel",
Description: "Super nice video",
Files: [
{
UID: "fqbfk181n4ca5sud",
Name: "1980/01/superCuteKitten.mp4",
Primary: true,
FileType: "mp4",
2021-10-06 16:42:53 +02:00
Hash: "1xxbgdt55",
Markers: [
{
UID: "aaa123",
Invalid: false,
},
{
UID: "bbb123",
Invalid: true,
},
],
},
],
};
const photo2 = new Photo(values2);
const result2 = photo2.getMarkers(true);
assert.equal(result2.length, 1);
const result3 = photo2.getMarkers(false);
assert.equal(result3.length, 2);
2021-03-11 11:55:38 +01:00
});
});