Skip to content

Commit

Permalink
fix: update exports
Browse files Browse the repository at this point in the history
  • Loading branch information
BelfordZ committed Jun 25, 2019
1 parent 287b60f commit 547e1aa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
generateMethodResultId,
ContentDescriptorNotFoundInMethodError,
} from "./generate-method-id";
import { MethodCallValidator, ParameterValidationError } from "./method-call-validator";
import { MethodCallValidator, ParameterValidationError, MethodNotFoundError } from "./method-call-validator";
import readSchemaFromFile from "./get-open-rpc-document-from-file";
import fetchUrlSchema from "./get-open-rpc-document-from-url";

Expand All @@ -18,6 +18,7 @@ export {
validateOpenRPCDocument,
MethodCallValidator,
ParameterValidationError,
MethodNotFoundError,
OpenRPCDocumentValidationError,
OpenRPCDocumentDereferencingError,
ContentDescriptorNotFoundInMethodError,
Expand Down
3 changes: 2 additions & 1 deletion src/method-call-validator/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MethodCallValidator from "./method-call-validator";
import ParameterValidationError from "./parameter-validation-error";
import MethodNotFoundError from "./method-not-found-error";

export { MethodCallValidator, ParameterValidationError };
export { MethodCallValidator, ParameterValidationError, MethodNotFoundError };
27 changes: 14 additions & 13 deletions src/method-call-validator/method-not-found-error.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MethodCallMethodNotFoundError from "./method-not-found-error";
import MethodNotFoundError from "./method-not-found-error";
import { OpenRPC } from "@open-rpc/meta-schema";

const exampleDoc = {
Expand All @@ -10,25 +10,26 @@ const exampleDoc = {
openrpc: "1.1.9",
} as OpenRPC;

describe("MethodCallMethodNotFoundError", () => {
describe("MethodNotFoundError", () => {
it("can be instantiated", () => {
const error = new MethodCallMethodNotFoundError("floobar", exampleDoc, ["abc", 123]);
expect(error).toBeInstanceOf(MethodCallMethodNotFoundError);
const error = new MethodNotFoundError("floobar", exampleDoc, ["abc", 123]);
expect(error).toBeInstanceOf(MethodNotFoundError);
});

it("works when no params passed", () => {
const error = new MethodCallMethodNotFoundError("floobar", exampleDoc);
expect(error).toBeInstanceOf(MethodCallMethodNotFoundError);
const error = new MethodNotFoundError("floobar", exampleDoc);
expect(error).toBeInstanceOf(MethodNotFoundError);
});

it("properly parses params in to a string", () => {
const error = new MethodCallMethodNotFoundError("floobar", exampleDoc, ["abc", { abc: 123 }, 123]);
expect(error).toBeInstanceOf(MethodCallMethodNotFoundError);
const error = new MethodNotFoundError("floobar", exampleDoc, ["abc", { abc: 123 }, 123]);
expect(error).toBeInstanceOf(MethodNotFoundError);
expect(error.message).toBe(`Method Not Found Error for OpenRPC API named "testerino"
The requested method: "floobar" not a valid method.
debug info:
params: "abc", {"abc":123}, 123`);
Params:
"abc"
{"abc":123}
123`);
});

it("it handles openrpc docs with a method", () => {
Expand All @@ -42,8 +43,8 @@ debug info:
},
},
];
const error = new MethodCallMethodNotFoundError("floobar", exampleDoc, ["abc", { abc: 123 }, 123]);
expect(error).toBeInstanceOf(MethodCallMethodNotFoundError);
const error = new MethodNotFoundError("floobar", exampleDoc, ["abc", { abc: 123 }, 123]);
expect(error).toBeInstanceOf(MethodNotFoundError);
expect(error.message).toContain("Valid method names are as follows: dooptiedoo");
});
});
11 changes: 5 additions & 6 deletions src/method-call-validator/method-not-found-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { OpenRPC } from "@open-rpc/meta-schema";
/**
* Provides an error interface for handling when a method is trying to be called but does not exist.
*/
export default class MethodCallMethodNotFoundError implements Error {
public name = "MethodCallMethodNotFoundError";
export default class MethodNotFoundError implements Error {
public name = "MethodNotFoundError";
public message: string;

/**
Expand Down Expand Up @@ -32,11 +32,10 @@ export default class MethodCallMethodNotFoundError implements Error {
if (receievedParams.length > 0) {
const stringedParams = receievedParams
.map((p) => { try { return JSON.stringify(p); } catch (e) { return p; } })
.join(", ");
.join("\n");

msg.push("");
msg.push("debug info:");
msg.push(` params: ${stringedParams}`);
msg.push("Params:");
msg.push(stringedParams);
}

this.message = msg.join("\n");
Expand Down
4 changes: 2 additions & 2 deletions src/method-call-validator/parameter-validation-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Schema } from "@open-rpc/meta-schema";
/**
* Provides an error interface for handling when a function call has invalid parameters.
*/
export default class MethodCallParameterValidationError implements Error {
public name = "MethodCallParameterValidationError";
export default class ParameterValidationError implements Error {
public name = "ParameterValidationError";
public message: string;

/**
Expand Down

0 comments on commit 547e1aa

Please sign in to comment.