Skip to content

Commit e9304a2

Browse files
Update tests using version option
1 parent 7c989bf commit e9304a2

5 files changed

Lines changed: 27 additions & 11 deletions

File tree

readme.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ When making calls to our methods that require authentication, you can provide an
119119
token: "full.access.token" // if specified will be added to authorisation header of request
120120
headers: {
121121
Authorization: "Bearer full.access.token" // can be used to specify authorisation header or additional headers
122-
}
122+
},
123+
version: "v3" // Forces an specific API version when calling the method
123124
}
124125
```
125126
Example usages
@@ -143,6 +144,12 @@ const accounts = await moneyhub.getAccounts({
143144
Authorization: "Bearer full.access.token"
144145
}
145146
});
147+
148+
const accounts = await moneyhub.getAccountsList({
149+
params: {},
150+
}, {
151+
version: "v2"
152+
});
146153
```
147154

148155
At least one of the following parameters needs to be passed in to any api call that requires user authentication:

src/__tests__/accounts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe("Accounts", function() {
4242
})
4343

4444
it("get accounts list", async function() {
45-
const accounts = await moneyhub.getAccountsList({userId})
45+
const accounts = await moneyhub.getAccountsList({userId}, {version: "v2"})
4646
expect(accounts.data.length).to.be.at.least(2)
4747
const cashAccount = accounts.data.find(a => a.type === "cash:current")
4848
const pension = accounts.data.find(a => a.type === "pension")
@@ -56,7 +56,7 @@ describe("Accounts", function() {
5656
})
5757

5858
it("get accounts list with transactionData", async function() {
59-
const accounts = await moneyhub.getAccountsList({userId, params: {showTransactionData: true}})
59+
const accounts = await moneyhub.getAccountsList({userId, params: {showTransactionData: true}}, {version: "v2"})
6060
expect(accounts.data.length).to.be.at.least(2)
6161
const cashAccount = accounts.data.find(a => a.type === "cash:current")
6262
const pension = accounts.data.find(a => a.type === "pension")
@@ -70,7 +70,7 @@ describe("Accounts", function() {
7070
})
7171

7272
it("get accounts list with details", async function() {
73-
const accounts = await moneyhub.getAccountsListWithDetails({userId})
73+
const accounts = await moneyhub.getAccountsListWithDetails({userId}, {version: "v2"})
7474
expect(accounts.data.length).to.be.at.least(2)
7575
const cashAccount = accounts.data.find(a => a.type === "cash:current")
7676
const pension = accounts.data.find(a => a.type === "pension")
@@ -93,7 +93,7 @@ describe("Accounts", function() {
9393
params: {
9494
counterpartiesVersion: "v2",
9595
},
96-
})
96+
}, {version: "v2"})
9797
expect(counterparties.length).to.be.greaterThan(6)
9898
expectTypeOf<Counterparties.Counterparty[]>(counterparties)
9999
})

src/__tests__/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,16 @@ describe("API client", function() {
191191
expect((openIdConfig as any).issuer).to.be.a("string")
192192
})
193193

194-
it("gets global counterparties", async function() {
195-
const counterparties = await moneyhub.getGlobalCounterparties()
194+
it("gets global counterparties v2", async function() {
195+
const counterparties = await moneyhub.getGlobalCounterparties({}, {version: "v2"})
196196
expect(counterparties.data.length).to.be.greaterThan(100)
197+
expect(counterparties.data[0].id).to.match(/^global:/)
198+
})
199+
200+
it("gets global counterparties v3", async function() {
201+
const counterparties = await moneyhub.getGlobalCounterparties({limit: 100}, {version: "v3"})
202+
expect(counterparties.data.length).to.be.equal(100)
203+
expect(counterparties.data[0].id).to.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
197204
})
198205
})
199206
})

src/requests/types/unauthenticated.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import {ApiResponse} from "../../request"
1+
import {ApiResponse, ExtraOptions} from "../../request"
22
import {WellKnownConnection} from "../../schema/connection"
33
import {GlobalCounterpartiesSearchParams, GlobalCounterparty} from "../../schema/counterparty"
44

55
export interface UnauthenticatedRequests {
66
getGlobalCounterparties: (
7-
params?: GlobalCounterpartiesSearchParams
7+
params?: GlobalCounterpartiesSearchParams,
8+
options?: ExtraOptions
89
) => Promise<ApiResponse<GlobalCounterparty[]>>
910

1011
listConnections: (query?: {clientId?: string}) => Promise<WellKnownConnection[]>

src/requests/unauthenticated.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import qs from "query-string"
2-
import {RequestsParams} from "../request"
2+
import {RequestsParams, ExtraOptions} from "../request"
33
import {UnauthenticatedRequests} from "./types/unauthenticated"
44

55
export default ({config, request}: RequestsParams): UnauthenticatedRequests => {
66
const {resourceServerUrl, identityServiceUrl} = config
77
return {
8-
getGlobalCounterparties: (params = {}) =>
8+
getGlobalCounterparties: (params = {}, options?: ExtraOptions) =>
99
request(`${resourceServerUrl}/global-counterparties`, {
1010
searchParams: params,
11+
options,
1112
}),
1213
listConnections: (query?: {clientId?: string}) =>
1314
request(`${identityServiceUrl}/oidc/.well-known/all-connections?${query && qs.stringify(query)}`),

0 commit comments

Comments
 (0)