From e1bd45ad5cf4d757b18a60d6a71b7da6c7f1aa89 Mon Sep 17 00:00:00 2001 From: BennyKitchell Date: Mon, 7 Nov 2022 20:38:53 -0600 Subject: [PATCH] feat: add uploads to sdk --- __tests__/Uploads.spec.ts | 129 -------------------------------- __tests__/UploadsApi.spec.ts | 139 +++++++++++++++++++++++++++++++++++ __tests__/lobster-family.csv | 12 +++ 3 files changed, 151 insertions(+), 129 deletions(-) delete mode 100644 __tests__/Uploads.spec.ts create mode 100644 __tests__/UploadsApi.spec.ts create mode 100644 __tests__/lobster-family.csv diff --git a/__tests__/Uploads.spec.ts b/__tests__/Uploads.spec.ts deleted file mode 100644 index 9129bbf..0000000 --- a/__tests__/Uploads.spec.ts +++ /dev/null @@ -1,129 +0,0 @@ -// import { -// CONFIG_FOR_INTEGRATION, -// FILE_LOCATION, -// FILE_LOCATION_4X6, -// FILE_LOCATION_6X18, -// } from "./testFixtures"; -// import { BuckslipsApi } from "../api/buckslips-api"; -// import { BuckslipEditable, BuckslipEditableSizeEnum } from "../models"; -// import FormData from "form-data"; -// import fs from "fs"; - -// describe("BuckSlipsApi", () => { -// it.skip("Buckslips API can be instantiated", () => { -// const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION); -// expect(buckslipsApi).toBeDefined(); -// expect(typeof buckslipsApi).toEqual("object"); -// expect(buckslipsApi).toBeInstanceOf(BuckslipsApi); -// }); - -// it("all individual Buckslips functions exists", () => { -// const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION); -// expect(buckslipsApi.create).toBeDefined(); -// expect(typeof buckslipsApi.create).toEqual("function"); - -// expect(buckslipsApi.get).toBeDefined(); -// expect(typeof buckslipsApi.get).toEqual("function"); - -// expect(buckslipsApi.update).toBeDefined(); -// expect(typeof buckslipsApi.update).toEqual("function"); - -// expect(buckslipsApi.delete).toBeDefined(); -// expect(typeof buckslipsApi.delete).toEqual("function"); -// }); - -// describe("performs single-buckslips operations", () => { -// const createBe = new BuckslipEditable({ -// description: "Test Buckslip", -// front: -// 'lobster.pdf"', -// back: FILE_LOCATION_6X18, -// size: BuckslipEditableSizeEnum._875x375, -// }); - -// it("creates, updates, and gets a buckslip", async () => { -// const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION); -// // Create -// let data = new FormData(); -// data.append( -// "front", -// fs.createReadStream( -// "lobster.pdf" -// ) -// ); -// data.append("description", "Test Buckslip"); - -// const createdBe = await buckslipsApi.create(createBe, { data }); -// expect(createdBe.id).toBeDefined(); -// expect(createdBe.description).toEqual(createBe.description); - -// // // Get -// // const retrievedBe = await buckslipsApi.get(createdBe.id as string); -// // expect(retrievedBe).toBeDefined(); -// // expect(retrievedBe.id).toEqual(createdBe.id); - -// // // Update -// // const updates = new BuckslipEditable({ -// // description: "updated buckslip", -// // }); -// // const updatedBg = await buckslipsApi.update( -// // retrievedBe.id as string, -// // updates -// // ); -// // expect(updatedBg).toBeDefined(); -// // expect(updatedBg.description).toEqual("updated buckslip"); -// }); -// }); - -// // describe("list billing groups", () => { -// // let createdBillingGroups: BillingGroup[] = []; - -// // beforeAll(async () => { -// // // ensure there are at least 3 billing groups present, to test pagination -// // const bg1 = new BillingGroupEditable({ -// // description: "Billing Group 1", -// // name: "TestBillingGroup1", -// // }); -// // const bg2 = new BillingGroupEditable( -// // Object.assign({}, bg1, { -// // description: "Billing Group 2", -// // name: "TestBillingGroup2", -// // }) -// // ); -// // const bg3 = new BillingGroupEditable( -// // Object.assign({}, bg1, { -// // description: "Billing Group 3", -// // name: "TestBillingGroup2", -// // }) -// // ); - -// // const billingGroupsApi = new BillingGroupsApi(CONFIG_FOR_INTEGRATION); -// // await Promise.all([ -// // billingGroupsApi.create(bg1), -// // billingGroupsApi.create(bg2), -// // billingGroupsApi.create(bg3), -// // ]) -// // .then((creationResults) => { -// // expect(creationResults.length).toEqual(3); -// // createdBillingGroups = createdBillingGroups.concat(creationResults); -// // }) -// // .catch((err) => { -// // throw err; -// // }); -// // }); - -// // it("exists", () => { -// // const billingGroupsApi = new BillingGroupsApi(CONFIG_FOR_INTEGRATION); -// // expect(billingGroupsApi.list).toBeDefined(); -// // expect(typeof billingGroupsApi.list).toEqual("function"); -// // }); - -// // it("lists billing groups", async () => { -// // const response = await new BillingGroupsApi( -// // CONFIG_FOR_INTEGRATION -// // ).list(); -// // expect(response.data).toBeDefined(); -// // expect(response.data?.length).toBeGreaterThan(0); -// // }); -// }); -// // }); diff --git a/__tests__/UploadsApi.spec.ts b/__tests__/UploadsApi.spec.ts new file mode 100644 index 0000000..84e7be4 --- /dev/null +++ b/__tests__/UploadsApi.spec.ts @@ -0,0 +1,139 @@ +import { + Campaign, + CampaignWritable, + CampaignUpdatable, + CmpScheduleType, + UploadWritable, + ExportModel, + ExportModelTypeEnum, + UploadUpdatable, + UploadState, + Upload, +} from "../models"; +import { UploadsApi } from "../api/uploads-api"; +import { CONFIG_FOR_INTEGRATION } from "./testFixtures"; +import { CampaignsApi } from "../api/campaigns-api"; +import FormData from "form-data"; +import { createReadStream } from "fs"; +import { assert } from "console"; + +describe("UploadsApi", () => { + jest.setTimeout(1000 * 60); + + it("Uploads API can be instantiated", () => { + const uploadsApi = new UploadsApi(CONFIG_FOR_INTEGRATION); + expect(uploadsApi).toBeDefined(); + expect(typeof uploadsApi).toEqual("object"); + expect(uploadsApi).toBeInstanceOf(UploadsApi); + }); + + it("all individual Uploads functions exists", () => { + const uploadsApi = new UploadsApi(CONFIG_FOR_INTEGRATION); + expect(uploadsApi.create_export).toBeDefined(); + expect(typeof uploadsApi.create_export).toEqual("function"); + + expect(uploadsApi.create_upload).toBeDefined(); + expect(typeof uploadsApi.create_upload).toEqual("function"); + + expect(uploadsApi.delete_upload).toBeDefined(); + expect(typeof uploadsApi.delete_upload).toEqual("function"); + + expect(uploadsApi.get_export).toBeDefined(); + expect(typeof uploadsApi.get_export).toEqual("function"); + + expect(uploadsApi.get_upload).toBeDefined(); + expect(typeof uploadsApi.get_upload).toEqual("function"); + + expect(uploadsApi.list_upload).toBeDefined(); + expect(typeof uploadsApi.list_upload).toEqual("function"); + + expect(uploadsApi.update_upload).toBeDefined(); + expect(typeof uploadsApi.update_upload).toEqual("function"); + + expect(uploadsApi.upload_file).toBeDefined(); + expect(typeof uploadsApi.upload_file).toEqual("function"); + }); + + describe("performs single-uploads operations", () => { + ``; + let createdCampaign: Campaign; + let uploadWrite: UploadWritable; + let createdUpload: Upload; + + beforeAll(async () => { + try { + const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION); + + const campaignWrite = new CampaignWritable({ + name: + "TS Integration Test Campaign for uploads on day " + + Date.now().toString(), + schedule_type: CmpScheduleType.Immediate, + }); + createdCampaign = await campaignsApi.create(campaignWrite); + + expect(createdCampaign.id).toBeDefined(); + } catch (err: any) { + console.error(err.message); + } + + uploadWrite = new UploadWritable({ + campaignId: createdCampaign.id, + columnMapping: { + name: "recipient", + address_line1: "primary_line", + address_line2: "secondary_line", + address_city: "city", + address_state: "state", + addess_zip: "zip_code", + metadata: "metadata", + }, + }); + }); + + const exportModel = new ExportModel({ + type: ExportModelTypeEnum.All, + }); + + it("creates, updates, retrieves, and deletes an upload", async () => { + const uploadsApi = new UploadsApi(CONFIG_FOR_INTEGRATION); + + //create upload + + const file = createReadStream("lobster-family.csv"); + const data = new FormData(); + data.append("file", file); + + const createdUpload = await uploadsApi.create_upload(uploadWrite, { + data, + }); + expect(createdUpload.id).toBeDefined(); + + //create export + const createdExport = await uploadsApi.create_export( + createdUpload.id, + exportModel + ); + expect(createdExport).toBeDefined(); + + // //get upload + const fetchedUpload = await uploadsApi.get_upload(createdUpload.id); + expect(fetchedUpload).toBeDefined(); + expect(fetchedUpload.id).toEqual(createdUpload.id); + + //get export + const fetchedExport = await uploadsApi.get_export( + createdUpload.id, + createdExport.exportId + ); + expect(fetchedExport).toBeDefined(); + expect(fetchedExport.id).toEqual(createdExport.exportId); + expect(fetchedExport.uploadId).toEqual(createdUpload.id); + + // //list uploads + const listOfUploads = await uploadsApi.list_upload(createdCampaign.id); + expect(listOfUploads).toBeDefined(); + expect(listOfUploads.length).toBeGreaterThan(0); + }); + }); +}); diff --git a/__tests__/lobster-family.csv b/__tests__/lobster-family.csv new file mode 100644 index 0000000..480ef97 --- /dev/null +++ b/__tests__/lobster-family.csv @@ -0,0 +1,12 @@ +recipient,primary line,city,state,zip_code +Larry Lobster,210 King St,San Francisco,CA,94107 +Lloyd Lobster,210 King St,San Francisco,CA,94107 +Lisa Lobster,210 King St,San Francisco,CA,94107 +Linda Lobster,210 King St,San Francisco,CA,94107 +Leith Lobster,210 King St,San Francisco,CA,94107 +Lala Lobster,Not A Real Street,San Francisco,CA,94107 +Krusty Krab,212 King St,San Francisco,CA,94107 +Patrick Star,211 King St,San Francisco,CA,94107 +Christopher Crawdad,209 King St,San Francisco,CA,94107 +Lost Lobster,210 King St,,CA, +