From 229a7a7e783d6eeb5c5d74475812c5a98e35b20c Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Wed, 10 Mar 2021 12:32:13 +0100 Subject: [PATCH] Add test for PlatformUser class --- test/classes/mapping/platform-user.ts | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/classes/mapping/platform-user.ts diff --git a/test/classes/mapping/platform-user.ts b/test/classes/mapping/platform-user.ts new file mode 100644 index 0000000..3075045 --- /dev/null +++ b/test/classes/mapping/platform-user.ts @@ -0,0 +1,34 @@ +"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 +import { auth } from "../../helpers"; +import PlatformUser from "../../../src/scripts/classes/mapping/platform-user"; +import { logout } from "../../../src"; + +chai.use(chaiAsPromised); +const { expect } = chai; + +export function suite(): void { + it("Fetch platform user without ID", async function fetchWithoutID() { + await auth(); + const user = new PlatformUser(); + await expect(user.fetch()).to.be.rejectedWith(INVALID_USER_ID); + }); + + it("Fetch platform user with invalid ID", async function fetchWithInvalidID() { + await auth(); + const user = new PlatformUser(-1); + await expect(user.fetch()).to.be.rejectedWith(INVALID_USER_ID); + }); + + it("Fetch platform user without authentication", async function fetchWithoutAuth() { + await logout(); + const user = new PlatformUser(1234); + await expect(user.fetch()).to.be.rejectedWith(USER_NOT_LOGGED); + }); +}