jsteuer
2019-12-21 cd876c0026bf59831c0322946f0d73a8328c1b3f
fix argument validation
6 files modified
31 ■■■■ changed files
CHANGELOG.md 5 ●●●●● patch | view | raw | blame | history
README.md 3 ●●●● patch | view | raw | blame | history
package-lock.json 2 ●●● patch | view | raw | blame | history
package.json 4 ●●●● patch | view | raw | blame | history
src/Helpers.ts 13 ●●●●● patch | view | raw | blame | history
test/Helpers.spec.ts 4 ●●●● patch | view | raw | blame | history
CHANGELOG.md
@@ -9,6 +9,11 @@
### Removed
## [2.0.1] - 2019-12-21
### Fixed
-   Fehlerhafte Validierung von Argumenten bei API Aufrufen gegenüber der
    Offline-Implementierung (z.B. `Helpers.enableOfflineUsageIfNecessary`)
    verbessert
## [2.0.0] - 2019-12-18
README.md
@@ -1,5 +1,5 @@
# MathCoach IDE API
# MathCoach IDE API <small>`Version 2.0.1`</small>
In diesem Paket ([Das Gitblit Repository findet sich hier](https://newton.htwsaar.de/gitblit/summary/mathcoach!mathcoach-ide-api.git)) 
ist die öffentliche Schnittstelle zur MathCoach Entwicklungsumgebung (IDE) definiert. Mithilfe 
@@ -320,6 +320,7 @@
#### Release einer neuen Version
- Version der API in der `package.json` eintragen
- Version in der Überschrift der `README.md` eintragen
- Beispiele und Changelog aktualisieren
- IDE-Projekt prüfen:  `package.json`, `ide-lib.js`, ...
- Final: Release Tag setzen `git tag -a VERSION -m '...'` und pushen
package-lock.json
@@ -1,6 +1,6 @@
{
  "name": "@mathcoach/ide-api",
  "version": "1.1.0",
  "version": "2.0.0",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
package.json
@@ -1,6 +1,6 @@
{
  "name": "@mathcoach/ide-api",
  "version": "2.0.0",
  "version": "2.0.1",
  "description": "API zur MathCoach IDE",
  "main": "./src/index.ts",
  "directories": {
@@ -54,4 +54,4 @@
    "instrument": true,
    "all": true
  }
}
}
src/Helpers.ts
@@ -65,13 +65,16 @@
        const traceMethod = (method: string, args?: any[]) => console.log(["[MC MOCK API]", " ", method, "(", (args ? args : [""]).join(","), ")"].join(""));
        const runtimeCheck = (errorMessage: string, isInvalid: (param: any) => boolean) => {
            return (paramName: string, value: any, optional: boolean = false) => {
                if (!optional && (value === null || value === undefined)) {
                    throw new Error(`parameter '${paramName}' is null or undefined`);
                } else {
                    if (isInvalid(value)) {
                        throw new Error(`parameter '${paramName}' is invalid: ${errorMessage}`);
                if (value === undefined) {
                    if (optional) {
                        return;
                    } else {
                        throw new Error(`missing parameter '${paramName}'`);
                    }
                }
                if (isInvalid(value)) {
                    throw new Error(`parameter '${paramName}' is invalid: ${errorMessage}`);
                }
            }
        }
        const runtimeCheckString = runtimeCheck("not a string", v => typeof v !== "string");
test/Helpers.spec.ts
@@ -108,8 +108,12 @@
    const contextFile = await MC.ide.getContextFile();
    const exerciseFile = Helpers.contextFileToExerciseFile(contextFile);
    MC.ide.navigator.navigateTo("www.google.de");
    MC.ide.navigator.navigateToExercise(exerciseFile);
    MC.ide.navigator.navigateTo("www.google.de", true);
    MC.ide.navigator.navigateToExercise(exerciseFile, true);
    MC.ide.navigator.navigateTo("www.google.de", false);
    MC.ide.navigator.navigateToExercise(exerciseFile, false);
    expectThrows(t, () => MC.ide.navigator.navigateTo(null as any));
    expectThrows(t, () => MC.ide.navigator.navigateTo(42 as any));