Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
a2br committed Dec 26, 2020
1 parent dda72ac commit e6328f1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
10 changes: 6 additions & 4 deletions __tests__/isFailure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ const responses = getDirectories("__tests__/responses").map((dirName) => {
return map;
});

responses.forEach((resType) => {
test(resType.name, () => {
resType.success.forEach((res) => expect(isFailure(res)).toBe(false));
resType.failure.forEach((res) => expect(isFailure(res)).toBe(true));
describe("isFailure function", () => {
responses.forEach((resType) => {
test(resType.name, () => {
resType.success.forEach((res) => expect(isFailure(res)).toBe(false));
resType.failure.forEach((res) => expect(isFailure(res)).toBe(true));
});
});
});

Expand Down
52 changes: 33 additions & 19 deletions __tests__/session.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
import { Session } from "../lib";

const session = new Session("EDELEVE", "0");
const account = session.login();
describe("Session class", () => {
const session = new Session("EDELEVE", "0");
const account = session.login();

test("credentials", () => {
expect(JSON.stringify(session.credentials)).toBe(
JSON.stringify({
username: "EDELEVE",
password: "0",
})
);
});
test("it returns correct credentials", () => {
expect(JSON.stringify(session.credentials)).toBe(
JSON.stringify({
username: "EDELEVE",
password: "0",
})
);
});

test("account", async () => {
const acc = await account;
expect(acc.type).toBe("student");
});
test("it successfully connects", async () => {
const acc = await account;
expect(acc.type).toBe("student");
});

test("homework", async () => {
const acc = await account;
test("it properly handles errors", async () => {
const errSession = new Session("EDELEVE", "1");
let didThrowError = false;
await errSession
.login()
.catch((e) => {
didThrowError = true;
})
.then(() => {
expect(didThrowError).toBe(true);
});
});

if (acc.type !== "student") return;
const someHomework = await acc.getHomework("2021-01-14");
expect(Array.isArray(someHomework)).toBe(true);
test("it fetches homework", async () => {
const acc = await account;
if (acc.type !== "student") return;
const someHomework = await acc.getHomework("2021-01-14");
expect(Array.isArray(someHomework)).toBe(true);
});
});

0 comments on commit e6328f1

Please sign in to comment.