This commit is contained in:
2020-05-09 01:02:24 +00:00
parent 3ddb29d3c1
commit 2d66eb49e8

View File

@@ -20,13 +20,39 @@ namespace raven_integration
public async void AttachmentUploadDownloadDeleteShouldWork()
{
//Make a user just for this test so can deal with dl token properly
var UniqueName = Util.Uniquify("AttachmentUploadDownloadDeleteShouldWork");
//CREATE
dynamic d = new JObject();
d.name = UniqueName;
d.active = true;
d.login = UniqueName;
d.password = UniqueName;
d.roles = 2;//bizadminfull needs widget rights
d.userType = 3;//non scheduleable
//Required by form custom rules
d.notes = "notes";
d.customFields = Util.UserRequiredCustomFieldsJsonString();
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
Util.ValidateDataReturnResponseOk(a);
long TestUserId=a.ObjectResponse["data"]["id"].Value<long>();
d = new JObject();
d.login = UniqueName;
d.password = UniqueName;
a = await Util.PostAsync("Auth", null, d.ToString());
string downloadToken = a.ObjectResponse["data"]["dlt"].Value<string>();
//////////////////////////////////////////
//// Upload the files
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
//Form data like the bizobject type and id
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
formDataContent.Add(new StringContent("3"), name: "AttachToObjectType");
formDataContent.Add(new StringContent(TestUserId.ToString()), name: "AttachToObjectId");
formDataContent.Add(new StringContent("Test:AttachmentUploadDownloadDeleteShouldWork"), name: "Notes");
formDataContent.Add(new StringContent("[{\"name\":\"test.zip\",\"lastModified\":1582822079618},{\"name\":\"test.png\",\"lastModified\":1586900220990}]"), name: "FileData");
@@ -47,12 +73,11 @@ namespace raven_integration
formDataContent.Add(file2);
//create via inventory full test user as attachments use the role of the object attaching to
ApiResponse a = await Util.PostFormDataAsync("Attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
a = await Util.PostFormDataAsync("Attachment", formDataContent, await Util.GetTokenAsync("manager", "l3tm3in"));
Util.ValidateDataReturnResponseOk(a);
long lTestPngAttachmentId = a.ObjectResponse["data"][0]["id"].Value<long>();
long lTestZipAttachmentId = a.ObjectResponse["data"][1]["id"].Value<long>();
@@ -64,19 +89,8 @@ namespace raven_integration
//////////////////////////////////////////
//// DOWNLOAD: Get the file attachment
//Get the inventoryfull account download token
// {
// "data": {
// "dlkey": "w7iE1cXF8kOxo8eomd1r8A",
// "expires": "2018-04-25T23:45:39.05665"
// }
// }
a = await Util.GetAsync("Attachment/DownloadToken", await Util.GetTokenAsync("InventoryFull"));
Util.ValidateDataReturnResponseOk(a);
string downloadToken = a.ObjectResponse["data"]["dlkey"].Value<string>();
//now get the file https://rockfish.ayanova.com/api/rfcaseblob/download/248?dlkey=9O2eDAAlZ0Wknj19SBK2iA
var dlresponse = await Util.DownloadFileAsync("Attachment/Download/" + lTestZipAttachmentId.ToString() + "?dlkey=" + downloadToken, await Util.GetTokenAsync("InventoryFull"));
//now get the file https://rockfish.ayanova.com/api/rfcaseblob/download/248?t=9O2eDAAlZ0Wknj19SBK2iA
var dlresponse = await Util.DownloadFileAsync("Attachment/Download/" + lTestZipAttachmentId.ToString() + "?t=" + downloadToken, null);
//ensure it's the zip file we expected
dlresponse.Content.Headers.ContentDisposition.FileName.Should().Be("test.zip");
@@ -85,11 +99,11 @@ namespace raven_integration
//////////////////////////////////////////
//// DELETE: Delete the file attachments
ApiResponse d = await Util.DeleteAsync("Attachment/" + lTestPngAttachmentId.ToString(), await Util.GetTokenAsync("InventoryFull"));
Util.ValidateHTTPStatusCode(d, 204);
a = await Util.DeleteAsync("Attachment/" + lTestPngAttachmentId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204);
d = await Util.DeleteAsync("Attachment/" + lTestZipAttachmentId.ToString(), await Util.GetTokenAsync("InventoryFull"));
Util.ValidateHTTPStatusCode(d, 204);
a = await Util.DeleteAsync("Attachment/" + lTestZipAttachmentId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
Util.ValidateHTTPStatusCode(a, 204);
}