Skip to content

Commit

Permalink
Renaming fromJsonConfig method
Browse files Browse the repository at this point in the history
  • Loading branch information
erdimaden committed May 14, 2024
1 parent 6d43e54 commit 243cd63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/coinbase/coinbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Coinbase {
* @throws {InvalidConfiguration} If the configuration is invalid.
* @throws {InvalidAPIKeyFormat} If not able to create JWT token.
*/
static fromJsonConfig(
static configureFromJson(
filePath: string = "coinbase_cloud_api_key.json",
debugging: boolean = false,
basePath: string = BASE_PATH,
Expand Down
15 changes: 9 additions & 6 deletions src/coinbase/tests/coinbase_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ describe("Coinbase tests", () => {
});

it("should throw an error if the file does not exist", () => {
expect(() => Coinbase.fromJsonConfig(`${PATH_PREFIX}/does-not-exist.json`)).toThrow(
expect(() => Coinbase.configureFromJson(`${PATH_PREFIX}/does-not-exist.json`)).toThrow(
"Invalid configuration: file not found at ./src/coinbase/tests/config/does-not-exist.json",
);
});

it("should initialize the Coinbase SDK from a JSON file", () => {
const cbInstance = Coinbase.fromJsonConfig(`${PATH_PREFIX}/coinbase_cloud_api_key.json`);
const cbInstance = Coinbase.configureFromJson(`${PATH_PREFIX}/coinbase_cloud_api_key.json`);
expect(cbInstance).toBeInstanceOf(Coinbase);
});

it("should throw an error if there is an issue reading the file or parsing the JSON data", () => {
expect(() => Coinbase.fromJsonConfig(`${PATH_PREFIX}/invalid.json`)).toThrow(
expect(() => Coinbase.configureFromJson(`${PATH_PREFIX}/invalid.json`)).toThrow(
"Invalid configuration: missing configuration values",
);
});

it("should throw an error if the JSON file is not parseable", () => {
expect(() => Coinbase.fromJsonConfig(`${PATH_PREFIX}/not_parseable.json`)).toThrow(
expect(() => Coinbase.configureFromJson(`${PATH_PREFIX}/not_parseable.json`)).toThrow(
"Not able to parse the configuration file",
);
});
Expand All @@ -43,15 +43,18 @@ describe("Coinbase tests", () => {
axiosMock.onGet().reply(200, {
id: 123,
});
const cbInstance = Coinbase.fromJsonConfig(`${PATH_PREFIX}/coinbase_cloud_api_key.json`, true);
const cbInstance = Coinbase.configureFromJson(
`${PATH_PREFIX}/coinbase_cloud_api_key.json`,
true,
);
const user = await cbInstance.defaultUser();
expect(user.getUserId()).toBe(123);
expect(user.toString()).toBe("Coinbase:User{userId: 123}");
});

it("should raise an error if the user is not found", async () => {
axiosMock.onGet().reply(404);
const cbInstance = Coinbase.fromJsonConfig(`${PATH_PREFIX}/coinbase_cloud_api_key.json`);
const cbInstance = Coinbase.configureFromJson(`${PATH_PREFIX}/coinbase_cloud_api_key.json`);
await expect(cbInstance.defaultUser()).rejects.toThrow("Request failed with status code 404");
});
});

0 comments on commit 243cd63

Please sign in to comment.