-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: created initial tests (with 100% coverage)
Also moved the webservice-module to the correct location in the repository
- Loading branch information
Luke Carr
committed
May 21, 2020
1 parent
217f66d
commit 989f82b
Showing
8 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Module from ".."; | ||
import WebServiceModule from "./webservice"; | ||
import { Client } from "../../client"; | ||
|
||
/** | ||
* Functions relating to core Moodle operations. | ||
*/ | ||
export default class CoreModule extends Module { | ||
public webservice: WebServiceModule; | ||
|
||
public constructor(client: Client) { | ||
super(client); | ||
this.webservice = new WebServiceModule(client); | ||
} | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import nock from "nock"; | ||
import { Joodle } from "../src"; | ||
|
||
describe("The Joodle client class", () => { | ||
const baseURL = "https://moodle.example.com/"; | ||
const token = "abc123"; | ||
let joodle: Joodle; | ||
|
||
beforeAll(() => { | ||
joodle = new Joodle({ | ||
baseURL, | ||
token, | ||
}); | ||
|
||
nock(baseURL) | ||
.get(`/webservice/rest/server.php?wsfunction=auth_email_get_signup_settings&wstoken=${token}&moodlewsrestformat=json`) | ||
.reply(200, { | ||
namefields: [ | ||
"firstname", | ||
"lastname", | ||
], | ||
passwordpolicy: "Password must exist!", | ||
warnings: [], | ||
}); | ||
|
||
nock(baseURL) | ||
.get(`/webservice/rest/server.php?wsfunction=core_webservice_get_site_info&wstoken=${token}&moodlewsrestformat=json`) | ||
.reply(200, { | ||
errorcode: "invalidtoken", | ||
exception: "moodle_exception", | ||
message: "Invalid token - token not found", | ||
}); | ||
}); | ||
|
||
it("should be initialized with a baseURL and token", () => { | ||
expect(joodle.got.defaults.options.prefixUrl).toBe(baseURL); | ||
expect(joodle.got.defaults.options.searchParams!.get("wstoken")).toBe(token); | ||
expect(joodle.got.defaults.options.searchParams!.get("moodlewsrestformat")).toBe("json"); | ||
}); | ||
|
||
it("should make API calls using the got library", () => { | ||
return expect(joodle.auth.email.getSignUpSettings()).resolves.toBeDefined(); | ||
}); | ||
|
||
it("should catch errors returned by Moodle", () => { | ||
return expect(joodle.core.webservice.getSiteInfo()).rejects.toBeDefined(); | ||
}); | ||
}); |