-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44bc85c
commit e1bd45a
Showing
3 changed files
with
151 additions
and
129 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|