Skip to content

Commit 68f2478

Browse files
authored
Authorization include non-authorized (#173)
* Authorization include non-authorized * Authorization include non-authorized
1 parent 57e64c9 commit 68f2478

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

resources/authorization.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ export class Authorizations extends BaseResource {
88
super(token, basePath + "/authorizations", config)
99
}
1010

11-
public async get(id: string): Promise<UnitResponse<Authorization>> {
12-
return this.httpGet<UnitResponse<Authorization>>(`/${id}`)
11+
public async get(id: string, includeNonAuthorized = false): Promise<UnitResponse<Authorization>> {
12+
const parameters: any = {
13+
...(includeNonAuthorized && { "filter[includeNonAuthorized]": includeNonAuthorized }),
14+
}
15+
16+
return this.httpGet<UnitResponse<Authorization>>(`/${id}`, { params: parameters })
1317
}
1418

1519
public async find(params?: AuthorizationQueryParams): Promise<UnitResponse<Authorization[]> & Meta> {
@@ -85,7 +89,7 @@ export interface AuthorizationQueryParams {
8589
/**
8690
* Optional. Filter authorizations by (Authorization Status)[https://docs.unit.co/cards-authorizations/#authorization-statuses].
8791
*/
88-
status: string[]
92+
status?: string[]
8993

9094
/**
9195
* Optional. Leave empty or provide sort=createdAt for ascending order. Provide sort=-createdAt (leading minus sign) for descending order.

tests/authorizations.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Unit } from "../unit"
2+
3+
import dotenv from "dotenv"
4+
dotenv.config()
5+
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")
6+
const authorizationIds: string[] = []
7+
8+
describe("Authorization Find", () => {
9+
test("Get Authorization List", async () => {
10+
const res = await unit.authorizations.find({limit: 10})
11+
res.data.forEach(element => {0
12+
expect(element.type === "authorization").toBeTruthy()
13+
authorizationIds.push(element.id)
14+
})
15+
})
16+
})
17+
18+
describe("Get Authorization", () => {
19+
test("get authorization", async () => {
20+
authorizationIds.forEach(async id => {
21+
const res = await unit.authorizations.get(id)
22+
expect(res.data.type === "authorization").toBeTruthy()
23+
})
24+
})
25+
})

0 commit comments

Comments
 (0)