-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |