|
| 1 | +import { CreateCheckDepositRequest, Unit, UploadCheckDepositRequest } from "../unit" |
| 2 | +import axios from "axios" |
| 3 | +import dotenv from "dotenv" |
| 4 | +import { createIndividualAccount } from "./testHelpers" |
| 5 | +dotenv.config() |
| 6 | +const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test") |
| 7 | + |
| 8 | +async function createCheckDepositReqeust(amount = 20000): Promise<CreateCheckDepositRequest> { |
| 9 | + const accountId = (await createIndividualAccount(unit)).data.id |
| 10 | + return { |
| 11 | + "type": "checkDeposit", |
| 12 | + "attributes": { |
| 13 | + "amount": amount, |
| 14 | + "description": "Check deposit" |
| 15 | + }, |
| 16 | + "relationships": { |
| 17 | + "account": { |
| 18 | + "data": { |
| 19 | + "type": "depositAccount", |
| 20 | + "id": accountId |
| 21 | + } |
| 22 | + } |
| 23 | + } |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +describe("CheckDeposit Create Test", () => { |
| 28 | + test("Create CheckDeposit", async () => { |
| 29 | + const req = await createCheckDepositReqeust() |
| 30 | + const res = await unit.checkDeposits.create(req) |
| 31 | + expect(res.data.type).toBe("checkDeposit") |
| 32 | + expect(res.data.attributes.amount).toBe(20000) |
| 33 | + }) |
| 34 | +}) |
| 35 | + |
| 36 | +describe("Upload Check", () => { |
| 37 | + test("Create CheckDeposit and upload image", async () => { |
| 38 | + const createReq = await createCheckDepositReqeust(15000) |
| 39 | + const checkDeposit = await unit.checkDeposits.create(createReq) |
| 40 | + expect(checkDeposit.data.type).toBe("checkDeposit") |
| 41 | + expect(checkDeposit.data.attributes.amount).toBe(15000) |
| 42 | + |
| 43 | + const checkDepositId = checkDeposit.data.id |
| 44 | + |
| 45 | + const response = await axios.get("https://image.shutterstock.com/image-illustration/blank-check-design-open-spacing-260nw-76703974.jpg", { responseType: "arraybuffer" }) |
| 46 | + const buffer = Buffer.from(response.data, "utf-8") |
| 47 | + const uploadReq: UploadCheckDepositRequest = { |
| 48 | + checkDepositId: checkDepositId, |
| 49 | + file: buffer |
| 50 | + } |
| 51 | + |
| 52 | + const uploadRes = await unit.checkDeposits.upload(uploadReq) |
| 53 | + expect(uploadRes.data.type).toBe("checkDeposit") |
| 54 | + |
| 55 | + const image = await unit.checkDeposits.getImage(checkDepositId) |
| 56 | + expect(image).not.toBeNull() |
| 57 | + }) |
| 58 | +}) |
0 commit comments