Tests: Add unit tests

This commit is contained in:
graciousgrey 2023-12-08 14:00:49 +01:00
parent ff37fc2d53
commit 92759e8862
5 changed files with 246 additions and 0 deletions

View file

@ -15,6 +15,9 @@ describe("model/label", () => {
it("should return batch size", () => { it("should return batch size", () => {
assert.equal(Label.batchSize(), 24); assert.equal(Label.batchSize(), 24);
Label.setBatchSize(30);
assert.equal(Label.batchSize(), 30);
Label.setBatchSize(24);
}); });
it("should return classes", () => { it("should return classes", () => {

View file

@ -38,6 +38,10 @@ describe("model/link", () => {
const link = new Link(values); const link = new Link(values);
const result = link.getId(); const result = link.getId();
assert.equal(result, 5); assert.equal(result, 5);
const values2 = {};
const link2 = new Link(values2);
const result2 = link2.getId();
assert.equal(result2, false);
}); });
it("should test has id", () => { it("should test has id", () => {

View file

@ -204,6 +204,9 @@ describe("model/marker", () => {
it("should return batch size", () => { it("should return batch size", () => {
assert.equal(Marker.batchSize(), 48); assert.equal(Marker.batchSize(), 48);
Marker.setBatchSize(30);
assert.equal(Marker.batchSize(), 30);
Marker.setBatchSize(48);
}); });
it("should get collection resource", () => { it("should get collection resource", () => {

View file

@ -42,6 +42,7 @@ describe("model/subject", () => {
Favorite: false, Favorite: false,
Excluded: true, Excluded: true,
Private: true, Private: true,
Hidden: true,
}; };
const subject = new Subject(values); const subject = new Subject(values);
const result = subject.classes(true); const result = subject.classes(true);
@ -51,6 +52,7 @@ describe("model/subject", () => {
assert.notInclude(result, "is-favorite"); assert.notInclude(result, "is-favorite");
assert.include(result, "is-private"); assert.include(result, "is-private");
assert.include(result, "is-excluded"); assert.include(result, "is-excluded");
assert.include(result, "is-hidden");
const values2 = { const values2 = {
UID: "s123ghytrfggd", UID: "s123ghytrfggd",
Type: "person", Type: "person",
@ -236,6 +238,9 @@ describe("model/subject", () => {
it("should return batch size", () => { it("should return batch size", () => {
assert.equal(Subject.batchSize(), 60); assert.equal(Subject.batchSize(), 60);
Subject.setBatchSize(30);
assert.equal(Subject.batchSize(), 30);
Subject.setBatchSize(60);
}); });
it("should get collection resource", () => { it("should get collection resource", () => {

View file

@ -1,10 +1,186 @@
import "../fixtures"; import "../fixtures";
import User from "model/user"; import User from "model/user";
import File from "model/file";
let chai = require("chai/chai"); let chai = require("chai/chai");
let assert = chai.assert; let assert = chai.assert;
describe("model/user", () => { describe("model/user", () => {
it("should get handle", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.getHandle();
assert.equal(result, "max");
const values2 = {
ID: 6,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
};
const user2 = new User(values2);
const result2 = user2.getHandle();
assert.equal(result2, "");
});
it("should get default base path", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.defaultBasePath();
assert.equal(result, "users/max");
const values2 = {
ID: 6,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
};
const user2 = new User(values2);
const result2 = user2.defaultBasePath();
assert.equal(result2, "");
});
it("should get display name", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.getDisplayName();
assert.equal(result, "Max Last");
const values2 = {
ID: 6,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
};
const user2 = new User(values2);
const result2 = user2.getDisplayName();
assert.equal(result2, "Unknown");
const values3 = {
ID: 7,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
Details: {
NickName: "maxi",
GivenName: "Maximilian",
},
};
const user3 = new User(values3);
const result3 = user3.getDisplayName();
assert.equal(result3, "maxi");
const values4 = {
ID: 8,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
Details: {
NickName: "",
GivenName: "Maximilian",
},
};
const user4 = new User(values4);
const result4 = user4.getDisplayName();
assert.equal(result4, "Maximilian");
});
it("should get account info", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.getAccountInfo();
assert.equal(result, "max");
const values2 = {
ID: 6,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
};
const user2 = new User(values2);
const result2 = user2.getAccountInfo();
assert.equal(result2, "test@test.com");
const values3 = {
ID: 7,
Name: "",
DisplayName: "",
Email: "",
Role: "admin",
};
const user3 = new User(values3);
const result3 = user3.getAccountInfo();
assert.equal(result3, "Admin");
const values4 = {
ID: 8,
Name: "",
DisplayName: "",
Email: "",
Role: "",
};
const user4 = new User(values4);
const result4 = user4.getAccountInfo();
assert.equal(result4, "Account");
const values5 = {
ID: 9,
Name: "",
DisplayName: "",
Email: "",
Role: "admin",
Details: {
JobTitle: "Developer",
},
};
const user5 = new User(values5);
const result5 = user5.getAccountInfo();
assert.equal(result5, "Developer");
});
it("should get entity name", () => { it("should get entity name", () => {
const values = { const values = {
ID: 5, ID: 5,
@ -50,6 +226,54 @@ describe("model/user", () => {
assert.equal(result.definition.foo, "register"); assert.equal(result.definition.foo, "register");
}); });
it("should get avatar url", async () => {
const values = { ID: 52, Name: "max", DisplayName: "Max Last" };
const user = new User(values);
const result = await user.getAvatarURL();
assert.equal(result, "/static/img/avatar/tile_500.jpg");
const values2 = {
ID: 53,
Name: "max",
DisplayName: "Max Last",
Thumb: "91e6c374afb78b28a52d7b4fd4fd2ea861b87123",
};
const user2 = new User(values2);
const result2 = await user2.getAvatarURL();
assert.equal(result2, "/api/v1/t/91e6c374afb78b28a52d7b4fd4fd2ea861b87123/public/tile_500");
});
it("should upload avatar", async () => {
const values = { ID: 52, Name: "max", DisplayName: "Max Last" };
const user = new User(values);
const values2 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
MediaType: "image",
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values2);
const Files = [file];
return user
.uploadAvatar(Files)
.then((response) => {
assert.equal("abc", response.Thumb);
assert.equal("manual", response.ThumbSrc);
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
});
it("should get profile form", async () => { it("should get profile form", async () => {
const values = { ID: 53, Name: "max", DisplayName: "Max Last" }; const values = { ID: 53, Name: "max", DisplayName: "Max Last" };
const user = new User(values); const user = new User(values);
@ -57,6 +281,13 @@ describe("model/user", () => {
assert.equal(result.definition.foo, "profile"); assert.equal(result.definition.foo, "profile");
}); });
it("should return whether user is remote", async () => {
const values = { ID: 52, Name: "max", DisplayName: "Max Last", AuthProvider: "local" };
const user = new User(values);
const result = await user.isRemote();
assert.equal(result, false);
});
it("should get change password", async () => { it("should get change password", async () => {
const values = { const values = {
ID: 54, ID: 54,