Tests: Add unit tests

This commit is contained in:
graciousgrey 2023-12-07 14:49:15 +01:00
parent 8990d48381
commit 1b56fe2ab7
3 changed files with 226 additions and 7 deletions

View file

@ -53,6 +53,104 @@ describe("model/album", () => {
assert.equal(result, "Christmas 2019");
});
it("should get album country", () => {
const values = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Country: "at" };
const album = new Album(values);
const result = album.getCountry();
assert.equal(result, "Austria");
const values2 = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Country: "zz" };
const album2 = new Album(values2);
const result2 = album2.getCountry();
assert.equal(result2, "");
const values3 = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Country: "xx" };
const album3 = new Album(values3);
const result3 = album3.getCountry();
assert.equal(result3, "");
});
it("should check if album has location", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
Country: "zz",
State: "",
Location: "",
};
const album = new Album(values);
const result = album.hasLocation();
assert.equal(result, false);
const values2 = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Country: "at" };
const album2 = new Album(values2);
const result2 = album2.hasLocation();
assert.equal(result2, true);
});
it("should get album location", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
Country: "at",
State: "Salzburg",
Location: "",
};
const album = new Album(values);
const result = album.getLocation();
assert.equal(result, "Salzburg, Austria");
const values2 = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
Country: "zz",
State: "",
Location: "",
};
const album2 = new Album(values2);
const result2 = album2.getLocation();
assert.equal(result2, "");
const values3 = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
Country: "zz",
State: "",
Location: "Austria",
};
const album3 = new Album(values3);
const result3 = album3.getLocation();
assert.equal(result3, "Austria");
const values5 = {
ID: 5,
Title: "Salzburg",
Slug: "salzburg",
Country: "at",
State: "Salzburg",
Location: "",
};
const album5 = new Album(values5);
const result5 = album5.getLocation();
assert.equal(result5, "Austria");
const values6 = {
ID: 5,
Title: "Austria",
Slug: "austria",
Country: "at",
State: "Salzburg",
Location: "",
};
const album6 = new Album(values6);
const result6 = album6.getLocation();
assert.equal(result6, "Salzburg");
});
it("should get thumbnail url", () => {
const values = {
ID: 5,
@ -214,6 +312,9 @@ describe("model/album", () => {
it("should return batch size", () => {
assert.equal(Album.batchSize(), 24);
Album.setBatchSize(30);
assert.equal(Album.batchSize(), 30);
Album.setBatchSize(24);
});
it("should like album", () => {

View file

@ -81,6 +81,16 @@ describe("model/face", () => {
const result2 = face2.thumbnailUrl();
assert.equal(result2, "/api/v1/t/7ca759a2b788cc5bcc08dbbce9854ff94a2f94d1/public/tile_160");
const values3 = {
ID: "f123ghytrfggd",
Samples: 5,
Thumb: "",
};
const face3 = new Face(values3);
const result3 = face3.thumbnailUrl("tile_240");
assert.equal(result3, "/api/v1/svg/portrait");
});
it("should get date string", () => {
@ -124,8 +134,35 @@ describe("model/face", () => {
assert.equal(face.Hidden, true);
});
it("should set name", (done) => {
const values = { ID: "f123ghytrfggd", Samples: 5, MarkerUID: "mDC123ghytr", Name: "Jane" };
const face = new Face(values);
face
.setName("testname")
.then((response) => {
assert.equal(response.Name, "testname");
done();
})
.catch((error) => {
done(error);
});
face
.setName("")
.then((response) => {
assert.equal(response.Name, "Jane");
done();
})
.catch((error) => {
done(error);
});
});
it("should return batch size", () => {
assert.equal(Face.batchSize(), 24);
Face.setBatchSize(30);
assert.equal(Face.batchSize(), 30);
Face.setBatchSize(24);
});
it("should get collection resource", () => {

View file

@ -193,13 +193,82 @@ describe("model/file", () => {
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Duration: 8009,
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.getInfo(), "JPG, 8µs");
assert.equal(file.getInfo(), "JPG");
const values2 = {
InstanceID: 6,
UID: "ABC124",
Hash: "54ghtfd",
FileType: "mp4",
Duration: 8009,
FPS: 60,
Name: "1/2/IMG123.mp4",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file2 = new File(values2);
assert.equal(file2.getInfo(), "MP4, 8µs, 60.0 FPS");
});
it("should return storage location", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
Root: "sidecar",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.storageInfo(), "Sidecar");
const values2 = {
InstanceID: 6,
UID: "ABC124",
Hash: "54ghtfd",
FileType: "mp4",
Duration: 8009,
FPS: 60,
Root: "/",
Name: "1/2/IMG123.mp4",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file2 = new File(values2);
assert.equal(file2.storageInfo(), "Originals");
const values3 = {
InstanceID: 6,
UID: "ABC124",
Hash: "54ghtfd",
FileType: "mp4",
Duration: 8009,
FPS: 60,
Root: "",
Name: "1/2/IMG123.mp4",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file3 = new File(values3);
assert.equal(file3.storageInfo(), "");
});
it("should return whether file is animated", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
MediaType: "image",
Duration: 500,
};
const file = new File(values);
assert.equal(file.isAnimated(), true);
});
it("should get type info", () => {
@ -208,20 +277,21 @@ describe("model/file", () => {
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Duration: 8009,
Primary: true,
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.typeInfo(), "JPEG");
assert.equal(file.typeInfo(), "Image");
const values2 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
FileType: "mp4",
Duration: 8009,
Name: "1/2/IMG123.jpg",
FPS: 60,
Name: "1/2/IMG123.mp4",
Video: true,
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
@ -233,7 +303,6 @@ describe("model/file", () => {
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Duration: 8009,
Name: "1/2/IMG123.jpg",
Sidecar: true,
CreatedAt: "2012-07-08T14:45:39Z",
@ -255,6 +324,18 @@ describe("model/file", () => {
};
const file4 = new File(values4);
assert.equal(file4.typeInfo(), "Sidecar GIF Image");
const values5 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "svg",
MediaType: "vector",
Name: "1/2/IMG123.svg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file5 = new File(values5);
assert.equal(file5.typeInfo(), "Scalable Vector Graphics");
});
it("should get size info", () => {