Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
#21 - Add new test for the InvalidCredentialManager
Browse files Browse the repository at this point in the history
Signed-off-by: Wright, Christopher R <Christopher.Wright@ca.com>
  • Loading branch information
Wright, Christopher R authored and Wright, Christopher R committed Sep 19, 2018
1 parent 9e08e2c commit a2dd36a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/security/__tests__/InvalidCredentialManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This program and the accompanying materials are made available under the terms of the *
* Eclipse Public License v2.0 which accompanies this distribution, and is available at *
* https://www.eclipse.org/legal/epl-v20.html *
* *
* SPDX-License-Identifier: EPL-2.0 *
* *
* Copyright Contributors to the Zowe Project. *
* *
*/

import { InvalidCredentialManager } from "../src/InvalidCredentialManager";
import { BadCredentialManagerError } from "..";

describe("InvalidCredentialMangager", () => {
it("should throw an error for every available method on the class", async () => {
const error = new Error("This is a test");
const invalidManager = new InvalidCredentialManager("cli", error);
const ignoreMethods = [ "constructor" ];

// Loops through the InvalidCredentialManager class's direct methods and will
// check that each one throws the expected BadCredentialManagerError object.
// If more methods are ever added to the invalid manager, they will be checked
// to see that they do throw errors.
for (const method of Object.getOwnPropertyNames(Object.getPrototypeOf(invalidManager))) {
// We will ignore any methods specified in the ignoreMethods array and
// only look at functions of the class.
if (ignoreMethods.indexOf(method) === -1 && typeof (invalidManager as any)[method] === "function") {
let caughtError: Error;

try {
// Try to invoke the method. We don't care about the parameters because neither should
// the class throwing errors.
await (invalidManager as any)[method]();
} catch (e) {
caughtError = e;
}

// Check to see if this method fails the test.
if (caughtError == null || !(caughtError instanceof BadCredentialManagerError)) {
fail(`InvalidCredentialManager.${method} does not properly throw a valid BadCredentialError.`);
} else if (caughtError.causeErrors !== error) {
fail(`InvalidCredentialManager.${method} does not preserve the error set in the constructor.`);
}
}
}
});
});

0 comments on commit a2dd36a

Please sign in to comment.