diff --git a/test/classes/mapping/post.ts b/test/classes/mapping/post.ts new file mode 100644 index 0000000..7b2e103 --- /dev/null +++ b/test/classes/mapping/post.ts @@ -0,0 +1,33 @@ +"use strict"; + +// Public module from npm +import chai from "chai"; +import chaiAsPromised from "chai-as-promised"; +import { INVALID_POST_ID, USER_NOT_LOGGED } from "../../../src/scripts/classes/errors"; + +// Module from files +import { Post } from "../../../src"; +import Shared from "../../../src/scripts/shared"; + +chai.use(chaiAsPromised); +const { expect } = chai; + +export function suite(): void { + it("Fetch post with null ID", async function fetchWithNullID() { + Shared.setIsLogged(true); + const post = new Post(null); + await expect(post.fetch()).to.be.rejectedWith(INVALID_POST_ID); + }); + + it("Fetch post with invalid ID", async function fetchWithInvalidID() { + Shared.setIsLogged(true); + const post = new Post(-1); + await expect(post.fetch()).to.be.rejectedWith(INVALID_POST_ID); + }); + + it("Fetch post without authentication", async function fetchWithoutAuth() { + Shared.setIsLogged(false); + const post = new Post(1234); + await expect(post.fetch()).to.be.rejectedWith(USER_NOT_LOGGED); + }); +} diff --git a/test/classes/mapping/thread.ts b/test/classes/mapping/thread.ts new file mode 100644 index 0000000..e9bac61 --- /dev/null +++ b/test/classes/mapping/thread.ts @@ -0,0 +1,41 @@ +"use strict"; + +// Public module from npm +import chai from "chai"; +import chaiAsPromised from "chai-as-promised"; +import { INVALID_THREAD_ID, USER_NOT_LOGGED } from "../../../src/scripts/classes/errors"; + +// Module from files +import { Thread } from "../../../src"; +import Shared from "../../../src/scripts/shared"; + +chai.use(chaiAsPromised); +const { expect } = chai; + +export function suite(): void { + it("Fetch thread with invalid ID", async function fetchWithInvalidID() { + Shared.setIsLogged(true); + const thread = new Thread(-1); + await expect(thread.fetch()).to.be.rejectedWith(INVALID_THREAD_ID); + }); + + it("Fetch thread with null ID", async function fetchWithNullID() { + Shared.setIsLogged(true); + const thread = new Thread(null); + await expect(thread.fetch()).to.be.rejectedWith(INVALID_THREAD_ID); + }); + + it("Fetch thread without authentication", async function fetchWithoutAuth() { + Shared.setIsLogged(false); + const thread = new Thread(1234); + await expect(thread.fetch()).to.be.rejectedWith(USER_NOT_LOGGED); + }); + + it("Fetch post with invalid ID", async function fetchWithInvalidID() { + Shared.setIsLogged(true); + const thread = new Thread(-1); + await expect(thread.getPost(0)).to.be.rejectedWith( + "Index must be greater or equal than 1" + ); + }); +} diff --git a/test/classes/mapping/user-profile.ts b/test/classes/mapping/user-profile.ts new file mode 100644 index 0000000..1644ba8 --- /dev/null +++ b/test/classes/mapping/user-profile.ts @@ -0,0 +1,21 @@ +"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 { UserProfile } from "../../../src"; +import Shared from "../../../src/scripts/shared"; + +chai.use(chaiAsPromised); +const { expect } = chai; + +export function suite(): void { + it("Fetch profile without authentication", async function fetchWithoutAuth() { + Shared.setIsLogged(false); + const up = new UserProfile(); + await expect(up.fetch()).to.be.rejectedWith(USER_NOT_LOGGED); + }); +}