|
| 1 | +import { |
| 2 | + CONFIG_FOR_INTEGRATION, |
| 3 | + FILE_LOCATION, |
| 4 | + FILE_LOCATION_4X6, |
| 5 | + FILE_LOCATION_6X18, |
| 6 | +} from "./testFixtures"; |
| 7 | +import { BuckslipsApi } from "../api/buckslips-api"; |
| 8 | +import { BuckslipEditable, BuckslipEditableSizeEnum } from "../models"; |
| 9 | +import FormData from "form-data"; |
| 10 | +import fs from "fs"; |
| 11 | + |
| 12 | +describe("BuckSlipsApi", () => { |
| 13 | + it("Buckslips API can be instantiated", () => { |
| 14 | + const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION); |
| 15 | + expect(buckslipsApi).toBeDefined(); |
| 16 | + expect(typeof buckslipsApi).toEqual("object"); |
| 17 | + expect(buckslipsApi).toBeInstanceOf(BuckslipsApi); |
| 18 | + }); |
| 19 | + |
| 20 | + it("all individual Buckslips functions exists", () => { |
| 21 | + const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION); |
| 22 | + expect(buckslipsApi.create).toBeDefined(); |
| 23 | + expect(typeof buckslipsApi.create).toEqual("function"); |
| 24 | + |
| 25 | + expect(buckslipsApi.get).toBeDefined(); |
| 26 | + expect(typeof buckslipsApi.get).toEqual("function"); |
| 27 | + |
| 28 | + expect(buckslipsApi.update).toBeDefined(); |
| 29 | + expect(typeof buckslipsApi.update).toEqual("function"); |
| 30 | + |
| 31 | + expect(buckslipsApi.delete).toBeDefined(); |
| 32 | + expect(typeof buckslipsApi.delete).toEqual("function"); |
| 33 | + }); |
| 34 | + |
| 35 | + describe("performs single-buckslips operations", () => { |
| 36 | + const createBe = new BuckslipEditable({ |
| 37 | + description: "Test Buckslip", |
| 38 | + front: 'lobster.pdf"', |
| 39 | + back: FILE_LOCATION_6X18, |
| 40 | + size: BuckslipEditableSizeEnum._875x375, |
| 41 | + }); |
| 42 | + |
| 43 | + it("creates, updates, and gets a buckslip", async () => { |
| 44 | + const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION); |
| 45 | + // Create |
| 46 | + let data = new FormData(); |
| 47 | + data.append("front", fs.createReadStream("lobster.pdf")); |
| 48 | + data.append("description", "Test Buckslip"); |
| 49 | + |
| 50 | + const createdBe = await buckslipsApi.create(createBe, { data }); |
| 51 | + expect(createdBe.id).toBeDefined(); |
| 52 | + expect(createdBe.description).toEqual(createBe.description); |
| 53 | + |
| 54 | + // // Get |
| 55 | + // const retrievedBe = await buckslipsApi.get(createdBe.id as string); |
| 56 | + // expect(retrievedBe).toBeDefined(); |
| 57 | + // expect(retrievedBe.id).toEqual(createdBe.id); |
| 58 | + |
| 59 | + // // Update |
| 60 | + // const updates = new BuckslipEditable({ |
| 61 | + // description: "updated buckslip", |
| 62 | + // }); |
| 63 | + // const updatedBg = await buckslipsApi.update( |
| 64 | + // retrievedBe.id as string, |
| 65 | + // updates |
| 66 | + // ); |
| 67 | + // expect(updatedBg).toBeDefined(); |
| 68 | + // expect(updatedBg.description).toEqual("updated buckslip"); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + // describe("list billing groups", () => { |
| 73 | + // let createdBillingGroups: BillingGroup[] = []; |
| 74 | + |
| 75 | + // beforeAll(async () => { |
| 76 | + // // ensure there are at least 3 billing groups present, to test pagination |
| 77 | + // const bg1 = new BillingGroupEditable({ |
| 78 | + // description: "Billing Group 1", |
| 79 | + // name: "TestBillingGroup1", |
| 80 | + // }); |
| 81 | + // const bg2 = new BillingGroupEditable( |
| 82 | + // Object.assign({}, bg1, { |
| 83 | + // description: "Billing Group 2", |
| 84 | + // name: "TestBillingGroup2", |
| 85 | + // }) |
| 86 | + // ); |
| 87 | + // const bg3 = new BillingGroupEditable( |
| 88 | + // Object.assign({}, bg1, { |
| 89 | + // description: "Billing Group 3", |
| 90 | + // name: "TestBillingGroup2", |
| 91 | + // }) |
| 92 | + // ); |
| 93 | + |
| 94 | + // const billingGroupsApi = new BillingGroupsApi(CONFIG_FOR_INTEGRATION); |
| 95 | + // await Promise.all([ |
| 96 | + // billingGroupsApi.create(bg1), |
| 97 | + // billingGroupsApi.create(bg2), |
| 98 | + // billingGroupsApi.create(bg3), |
| 99 | + // ]) |
| 100 | + // .then((creationResults) => { |
| 101 | + // expect(creationResults.length).toEqual(3); |
| 102 | + // createdBillingGroups = createdBillingGroups.concat(creationResults); |
| 103 | + // }) |
| 104 | + // .catch((err) => { |
| 105 | + // throw err; |
| 106 | + // }); |
| 107 | + // }); |
| 108 | + |
| 109 | + // it("exists", () => { |
| 110 | + // const billingGroupsApi = new BillingGroupsApi(CONFIG_FOR_INTEGRATION); |
| 111 | + // expect(billingGroupsApi.list).toBeDefined(); |
| 112 | + // expect(typeof billingGroupsApi.list).toEqual("function"); |
| 113 | + // }); |
| 114 | + |
| 115 | + // it("lists billing groups", async () => { |
| 116 | + // const response = await new BillingGroupsApi( |
| 117 | + // CONFIG_FOR_INTEGRATION |
| 118 | + // ).list(); |
| 119 | + // expect(response.data).toBeDefined(); |
| 120 | + // expect(response.data?.length).toBeGreaterThan(0); |
| 121 | + // }); |
| 122 | +}); |
| 123 | +// }); |
0 commit comments