-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for headers or token to be passed into methods
- Loading branch information
1 parent
ace4874
commit 7e9e9f3
Showing
44 changed files
with
401 additions
and
220 deletions.
There are no files selected for viewing
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,64 @@ | ||
/* eslint-disable max-nested-callbacks */ | ||
import {expect} from "chai" | ||
|
||
import {Accounts, Moneyhub, MoneyhubInstance} from ".." | ||
import {expectTypeOf} from "expect-type" | ||
|
||
describe("Accounts with extra options", function() { | ||
let moneyhub: MoneyhubInstance, | ||
userId: string | ||
|
||
before(async function() { | ||
const { | ||
testUserId, | ||
} = this.config | ||
userId = testUserId | ||
moneyhub = await Moneyhub(this.config) | ||
}) | ||
|
||
it("errors with malformed token", async function() { | ||
let error: any | ||
try { | ||
await moneyhub.getAccounts({userId}, { | ||
token: "malformed.token", | ||
}) | ||
} catch (err) { | ||
error = err | ||
} | ||
expect(error.response.statusCode).to.equal(401) | ||
}) | ||
|
||
it("errors with malformed headers", async function() { | ||
let error: any | ||
try { | ||
await moneyhub.getAccounts({userId}, { | ||
headers: { | ||
Authorization: "malformed.header", | ||
}, | ||
}) | ||
} catch (err) { | ||
error = err | ||
} | ||
expect(error.response.statusCode).to.equal(401) | ||
}) | ||
|
||
it("succeeds with given token", async function() { | ||
const {access_token: token} = await moneyhub.getClientCredentialTokens({scope: "accounts:read", sub: userId}) | ||
|
||
const accounts = await moneyhub.getAccounts({userId}, { | ||
token, | ||
}) | ||
expectTypeOf<Accounts.Account[]>(accounts.data) | ||
}) | ||
|
||
it("succeeds with given headers", async function() { | ||
const {access_token: token} = await moneyhub.getClientCredentialTokens({scope: "accounts:read", sub: userId}) | ||
|
||
const accounts = await moneyhub.getAccounts({userId}, { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}) | ||
expectTypeOf<Accounts.Account[]>(accounts.data) | ||
}) | ||
}) |
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
Oops, something went wrong.