Skip to content

Commit

Permalink
feat: add uploads to sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyKitchell committed Nov 8, 2022
1 parent 44bc85c commit e1bd45a
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 129 deletions.
129 changes: 0 additions & 129 deletions __tests__/Uploads.spec.ts

This file was deleted.

139 changes: 139 additions & 0 deletions __tests__/UploadsApi.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
12 changes: 12 additions & 0 deletions __tests__/lobster-family.csv
Original file line number Diff line number Diff line change
@@ -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,

0 comments on commit e1bd45a

Please sign in to comment.