2021-03-10 11:32:13 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Public module from npm
|
|
|
|
import chai from "chai";
|
|
|
|
import chaiAsPromised from "chai-as-promised";
|
|
|
|
import { INVALID_USER_ID, USER_NOT_LOGGED } from "../../../src/scripts/classes/errors";
|
|
|
|
|
|
|
|
// Module from files
|
2021-03-10 14:13:11 +00:00
|
|
|
import { PlatformUser } from "../../../src";
|
|
|
|
import Shared from "../../../src/scripts/shared";
|
2021-03-10 11:32:13 +00:00
|
|
|
|
|
|
|
chai.use(chaiAsPromised);
|
|
|
|
const { expect } = chai;
|
|
|
|
|
|
|
|
export function suite(): void {
|
2021-03-10 14:13:11 +00:00
|
|
|
it("Set invalid ID", function setInvalidID() {
|
|
|
|
const user = new PlatformUser();
|
|
|
|
expect(user.setID(-1)).to.be.rejectedWith(INVALID_USER_ID);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Set null ID", function setNullID() {
|
|
|
|
const user = new PlatformUser();
|
|
|
|
expect(user.setID(null)).to.be.rejectedWith(INVALID_USER_ID);
|
|
|
|
});
|
|
|
|
|
2021-03-10 11:32:13 +00:00
|
|
|
it("Fetch platform user without ID", async function fetchWithoutID() {
|
2021-03-10 14:13:11 +00:00
|
|
|
Shared.setIsLogged(true);
|
2021-03-10 11:32:13 +00:00
|
|
|
const user = new PlatformUser();
|
|
|
|
await expect(user.fetch()).to.be.rejectedWith(INVALID_USER_ID);
|
|
|
|
});
|
|
|
|
|
2021-03-10 14:13:11 +00:00
|
|
|
it("Fetch platform user with null ID", async function fetchWithNullID() {
|
|
|
|
Shared.setIsLogged(true);
|
|
|
|
const user = new PlatformUser(null);
|
|
|
|
await expect(user.fetch()).to.be.rejectedWith(INVALID_USER_ID);
|
|
|
|
});
|
|
|
|
|
2021-03-10 11:32:13 +00:00
|
|
|
it("Fetch platform user with invalid ID", async function fetchWithInvalidID() {
|
2021-03-10 14:13:11 +00:00
|
|
|
Shared.setIsLogged(true);
|
2021-03-10 11:32:13 +00:00
|
|
|
const user = new PlatformUser(-1);
|
|
|
|
await expect(user.fetch()).to.be.rejectedWith(INVALID_USER_ID);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Fetch platform user without authentication", async function fetchWithoutAuth() {
|
2021-03-10 14:13:11 +00:00
|
|
|
Shared.setIsLogged(false);
|
2021-03-10 11:32:13 +00:00
|
|
|
const user = new PlatformUser(1234);
|
|
|
|
await expect(user.fetch()).to.be.rejectedWith(USER_NOT_LOGGED);
|
|
|
|
});
|
|
|
|
}
|