4648
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class ApiResponse
|
||||
{
|
||||
public HttpResponseMessage HttpResponse { get; set; }
|
||||
public JObject ObjectResponse { get; set; }
|
||||
public string CompactResponse
|
||||
{
|
||||
get
|
||||
{
|
||||
return ObjectResponse.ToString(Newtonsoft.Json.Formatting.None);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}//eoc
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class ApiResponse
|
||||
{
|
||||
public HttpResponseMessage HttpResponse { get; set; }
|
||||
public JObject ObjectResponse { get; set; }
|
||||
public string CompactResponse
|
||||
{
|
||||
get
|
||||
{
|
||||
return ObjectResponse.ToString(Newtonsoft.Json.Formatting.None);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
@@ -1,31 +1,31 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class ApiRoute
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerApiRootPageShouldFetch()
|
||||
{
|
||||
ApiTextResponse t = await Util.GetNonApiPageAsync("/api/v8/");
|
||||
Util.ValidateHTTPStatusCode(t, 200);
|
||||
t.TextResponse.Should().Contain("<title>AyaNova server</title>");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class ApiRoute
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ServerApiRootPageShouldFetch()
|
||||
{
|
||||
ApiTextResponse t = await Util.GetNonApiPageAsync("/api/v8/");
|
||||
Util.ValidateHTTPStatusCode(t, 200);
|
||||
t.TextResponse.Should().Contain("<title>AyaNova server</title>");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class ApiTextResponse
|
||||
{
|
||||
public HttpResponseMessage HttpResponse {get;set;}
|
||||
public string TextResponse {get;set;}
|
||||
|
||||
|
||||
}//eoc
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class ApiTextResponse
|
||||
{
|
||||
public HttpResponseMessage HttpResponse {get;set;}
|
||||
public string TextResponse {get;set;}
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
@@ -1,204 +1,204 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.IO;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
//https://stackoverflow.com/questions/17725882/testing-asp-net-web-api-multipart-form-data-file-upload
|
||||
public class AttachmentTest
|
||||
{
|
||||
/// <summary>
|
||||
/// test attach CRUD
|
||||
/// </summary>
|
||||
[Fact]
|
||||
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("superuser", "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("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");
|
||||
|
||||
//fileData in JSON stringify format which contains the actual last modified dates etc
|
||||
//"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]"
|
||||
//or if testing non-existant this is probably safe: long.MaxValue
|
||||
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
StreamContent file2 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.zip"));
|
||||
file2.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
|
||||
file2.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file2.Headers.ContentDisposition.FileName = "test.zip";
|
||||
formDataContent.Add(file2);
|
||||
|
||||
//create via inventory full test user as attachments use the role of the object attaching to
|
||||
a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
|
||||
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
long lTestPngAttachmentId = a.ObjectResponse["data"][0]["id"].Value<long>();
|
||||
long lTestZipAttachmentId = a.ObjectResponse["data"][1]["id"].Value<long>();
|
||||
|
||||
//saw negative values on a db issue that I corrected (I think)
|
||||
//Keeping these in case it arises again, if it does, see log, it's a db error with async issue of some kind
|
||||
lTestPngAttachmentId.Should().BePositive();
|
||||
lTestZipAttachmentId.Should().BePositive();
|
||||
|
||||
//////////////////////////////////////////
|
||||
//// DOWNLOAD: Get the file attachment
|
||||
|
||||
//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");
|
||||
dlresponse.Content.Headers.ContentLength.Should().BeGreaterThan(2000);
|
||||
|
||||
|
||||
//////////////////////////////////////////
|
||||
//// DELETE: Delete the file attachments
|
||||
a = await Util.DeleteAsync("attachment/" + lTestPngAttachmentId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("attachment/" + lTestZipAttachmentId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test no rights
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void NoRightsTest()
|
||||
{
|
||||
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
|
||||
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
|
||||
formDataContent.Add(new StringContent("Test:AttachmentUploadDownloadDeleteShouldWork"), name: "Notes");
|
||||
formDataContent.Add(new StringContent("[{\"name\":\"test.png\",\"lastModified\":1586900220990}]"), name: "FileData");
|
||||
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
|
||||
//ERROR CONDITION: BizAdminLimited user should not be able to attach a file to a widget
|
||||
ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("BizAdminLimited"));
|
||||
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test not attachable
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void UnattachableTest()
|
||||
{
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
//Form data bizobject type and id
|
||||
|
||||
//HERE IS THE ERROR CONDITION: LICENSE TYPE OBJECT WHICH IS UNATTACHABLE
|
||||
formDataContent.Add(new StringContent("5"), name: "AttachToObjectType");
|
||||
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
|
||||
|
||||
//2203 unattachable object
|
||||
Util.ValidateErrorCodeResponse(a, 2203, 400);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test bad object values
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BadObject()
|
||||
{
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
//Form data like the bizobject type and id
|
||||
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
|
||||
|
||||
//HERE IS THE ERROR CONDITION, A NON EXISTENT ID VALUE FOR THE WIDGET
|
||||
formDataContent.Add(new StringContent(long.MaxValue.ToString()), name: "AttachToObjectId");//non-existent widget
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
|
||||
|
||||
//2203 invalid attachment object
|
||||
Util.ValidateErrorCodeResponse(a, 2203, 400);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.IO;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
//https://stackoverflow.com/questions/17725882/testing-asp-net-web-api-multipart-form-data-file-upload
|
||||
public class AttachmentTest
|
||||
{
|
||||
/// <summary>
|
||||
/// test attach CRUD
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task 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("superuser", "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("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");
|
||||
|
||||
//fileData in JSON stringify format which contains the actual last modified dates etc
|
||||
//"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]"
|
||||
//or if testing non-existant this is probably safe: long.MaxValue
|
||||
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
StreamContent file2 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.zip"));
|
||||
file2.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
|
||||
file2.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file2.Headers.ContentDisposition.FileName = "test.zip";
|
||||
formDataContent.Add(file2);
|
||||
|
||||
//create via inventory full test user as attachments use the role of the object attaching to
|
||||
a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
|
||||
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
long lTestPngAttachmentId = a.ObjectResponse["data"][0]["id"].Value<long>();
|
||||
long lTestZipAttachmentId = a.ObjectResponse["data"][1]["id"].Value<long>();
|
||||
|
||||
//saw negative values on a db issue that I corrected (I think)
|
||||
//Keeping these in case it arises again, if it does, see log, it's a db error with async issue of some kind
|
||||
lTestPngAttachmentId.Should().BePositive();
|
||||
lTestZipAttachmentId.Should().BePositive();
|
||||
|
||||
//////////////////////////////////////////
|
||||
//// DOWNLOAD: Get the file attachment
|
||||
|
||||
//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");
|
||||
dlresponse.Content.Headers.ContentLength.Should().BeGreaterThan(2000);
|
||||
|
||||
|
||||
//////////////////////////////////////////
|
||||
//// DELETE: Delete the file attachments
|
||||
a = await Util.DeleteAsync("attachment/" + lTestPngAttachmentId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("attachment/" + lTestZipAttachmentId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test no rights
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task NoRightsTest()
|
||||
{
|
||||
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
|
||||
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
|
||||
formDataContent.Add(new StringContent("Test:AttachmentUploadDownloadDeleteShouldWork"), name: "Notes");
|
||||
formDataContent.Add(new StringContent("[{\"name\":\"test.png\",\"lastModified\":1586900220990}]"), name: "FileData");
|
||||
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
|
||||
//ERROR CONDITION: BizAdminLimited user should not be able to attach a file to a widget
|
||||
ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("BizAdminLimited"));
|
||||
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test not attachable
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task UnattachableTest()
|
||||
{
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
//Form data bizobject type and id
|
||||
|
||||
//HERE IS THE ERROR CONDITION: LICENSE TYPE OBJECT WHICH IS UNATTACHABLE
|
||||
formDataContent.Add(new StringContent("5"), name: "AttachToObjectType");
|
||||
formDataContent.Add(new StringContent("1"), name: "AttachToObjectId");
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
|
||||
|
||||
//2203 unattachable object
|
||||
Util.ValidateErrorCodeResponse(a, 2203, 400);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test bad object values
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BadObject()
|
||||
{
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
|
||||
|
||||
//Form data like the bizobject type and id
|
||||
formDataContent.Add(new StringContent("2"), name: "AttachToObjectType");
|
||||
|
||||
//HERE IS THE ERROR CONDITION, A NON EXISTENT ID VALUE FOR THE WIDGET
|
||||
formDataContent.Add(new StringContent(long.MaxValue.ToString()), name: "AttachToObjectId");//non-existent widget
|
||||
|
||||
StreamContent file1 = new StreamContent(File.OpenRead($"{Util.TEST_DATA_FOLDER}\\test.png"));
|
||||
file1.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
file1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
|
||||
file1.Headers.ContentDisposition.FileName = "test.png";
|
||||
formDataContent.Add(file1);
|
||||
ApiResponse a = await Util.PostFormDataAsync("attachment", formDataContent, await Util.GetTokenAsync("InventoryFull"));
|
||||
|
||||
//2203 invalid attachment object
|
||||
Util.ValidateErrorCodeResponse(a, 2203, 400);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,137 +1,137 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class auth
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BadLoginShouldNotWork()
|
||||
{
|
||||
//Expect status code 401 and result:
|
||||
// {{
|
||||
// "error": {
|
||||
// "code": "2003",
|
||||
// "message": "Authentication failed"
|
||||
// }
|
||||
// }}
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.login = "BOGUS";
|
||||
d.password = "ACCOUNT";
|
||||
ApiResponse a = await Util.PostAsync("auth", null, d.ToString());
|
||||
Util.ValidateErrorCodeResponse(a, 2003, 401);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//NOTE: These tests are for Debug builds, they should still pass in a release build because none of the creds will work and it checks for 401 only
|
||||
//but a true test of these JWT tokens is only in server debug mode
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void JWTExpiredTokenShouldFail()
|
||||
{
|
||||
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "EXPIRED"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void JWTWrongIssuerShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_ISSUER"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void JWTNoAlgorithmShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "NO_ALGORITHM"));
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void JWTBadSecretShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_SECRET"));
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void JWTTruncatedSignatureShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "TRUNCATED_SIGNATURE"));
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void JWTTransposedSignatureShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "TRANSPOSE_SIGNATURE"));
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Auth
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BadLoginShouldNotWork()
|
||||
{
|
||||
//Expect status code 401 and result:
|
||||
// {{
|
||||
// "error": {
|
||||
// "code": "2003",
|
||||
// "message": "Authentication failed"
|
||||
// }
|
||||
// }}
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.login = "BOGUS";
|
||||
d.password = "ACCOUNT";
|
||||
ApiResponse a = await Util.PostAsync("auth", null, d.ToString());
|
||||
Util.ValidateErrorCodeResponse(a, 2003, 401);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//NOTE: These tests are for Debug builds, they should still pass in a release build because none of the creds will work and it checks for 401 only
|
||||
//but a true test of these JWT tokens is only in server debug mode
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task JWTExpiredTokenShouldFail()
|
||||
{
|
||||
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "EXPIRED"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task JWTWrongIssuerShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_ISSUER"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task JWTNoAlgorithmShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "NO_ALGORITHM"));
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task JWTBadSecretShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_SECRET"));
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task JWTTruncatedSignatureShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "TRUNCATED_SIGNATURE"));
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task JWTTransposedSignatureShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("INTEGRATION_TEST", "TRANSPOSE_SIGNATURE"));
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -1,30 +1,30 @@
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class DataListRights
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void InsufficentRightsShouldNotRetrieve()
|
||||
{
|
||||
//Get without rights
|
||||
/*
|
||||
"{\"error\":{\"code\":\"2004\",\"message\":\"User not authorized for this resource operation (insufficient rights)\"}}"
|
||||
*/
|
||||
//ApiResponse a = await Util.GetAsync("data-list/list?DataListKey=TestWidgetDataList&Offset=0&Limit=3", await Util.GetTokenAsync("CustomerLimited"));
|
||||
ApiResponse a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("CustomerLimited"), Util.BuildDataListRequestEx());
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class DataListRights
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task InsufficentRightsShouldNotRetrieve()
|
||||
{
|
||||
//Get without rights
|
||||
/*
|
||||
"{\"error\":{\"code\":\"2004\",\"message\":\"User not authorized for this resource operation (insufficient rights)\"}}"
|
||||
*/
|
||||
//ApiResponse a = await Util.GetAsync("data-list/list?DataListKey=TestWidgetDataList&Offset=0&Limit=3", await Util.GetTokenAsync("CustomerLimited"));
|
||||
ApiResponse a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("CustomerLimited"), Util.BuildDataListRequestEx());
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,413 +1,413 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
|
||||
public class DataListSorting
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void DefaultSortByIdWorks()
|
||||
{
|
||||
|
||||
var WidgetNameStart = Util.Uniquify("DefaultSortByIdWorks");
|
||||
|
||||
//CREATE 3 TEST WIDGETS TO TEST ORDER
|
||||
long FirstInOrderWidgetId = 0;
|
||||
long SecondInOrderWidgetId = 0;
|
||||
long ThirdInOrderWidgetId = 0;
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.usertype = 1;
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
|
||||
dynamic dListView = new JArray();
|
||||
|
||||
|
||||
//name starts with filter to constrict to widgets that this test block created only
|
||||
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart));
|
||||
|
||||
//NOW FETCH WIDGET LIST WITH FILTER
|
||||
// a = await Util.GetAsync($"data-list/list?DataListKey=TestWidgetDataList&Offset=0&Limit=999&DataFilterId={DataFilterId.ToString()}", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//assert contains exactly 3 records
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(3);
|
||||
|
||||
//assert the order returned
|
||||
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
|
||||
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
|
||||
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
|
||||
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void SortByFieldAscendingWorks()
|
||||
{
|
||||
|
||||
var WidgetNameStart = Util.Uniquify("SortByFieldAscendingWorks");
|
||||
|
||||
//CREATE 3 TEST WIDGETS TO TEST ORDER
|
||||
long FirstInOrderWidgetId = 0;
|
||||
long SecondInOrderWidgetId = 0;
|
||||
long ThirdInOrderWidgetId = 0;
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.startDate = DateTime.Now;
|
||||
w.endDate = DateTime.Now.AddHours(1);
|
||||
w.usertype = 1;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.startDate = DateTime.Now.AddHours(1);
|
||||
w.endDate = DateTime.Now.AddHours(2);
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.startDate = DateTime.Now.AddHours(2);
|
||||
w.endDate = DateTime.Now.AddHours(3);
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
//FILTER IN BY NAME FOR TESTING THIS RUN ONLY
|
||||
dynamic dListView = new JArray();
|
||||
//name starts with filter to constrict to widgets that this test block created only
|
||||
|
||||
|
||||
//SORT ORDER ###################
|
||||
// dynamic dsortarray = new JArray();
|
||||
// dynamic dsort = new JObject();
|
||||
// dsort.fld = "widgetstartdate";
|
||||
// dsort.dir = "+";
|
||||
// dsortarray.Add(dsort);
|
||||
|
||||
//both conditions filter and sort here
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart, "+"));
|
||||
|
||||
|
||||
|
||||
//NOW FETCH WIDGET LIST WITH FILTER
|
||||
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//assert contains exactly 3 records
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(3);
|
||||
|
||||
//assert the order returned
|
||||
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
|
||||
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
|
||||
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
|
||||
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void SortByFieldDescendingWorks()
|
||||
{
|
||||
|
||||
var WidgetNameStart = Util.Uniquify("SortByFieldDescendingWorks");
|
||||
|
||||
//CREATE 3 TEST WIDGETS TO TEST ORDER
|
||||
long FirstInOrderWidgetId = 0;
|
||||
long SecondInOrderWidgetId = 0;
|
||||
long ThirdInOrderWidgetId = 0;
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.count = 999;
|
||||
w.usertype = 1;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.count = 665;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.count = 333;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
|
||||
//FILTER IN BY NAME FOR TESTING THIS RUN ONLY
|
||||
dynamic dListView = new JArray();
|
||||
//name starts with filter to constrict to widgets that this test block created only
|
||||
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart));
|
||||
|
||||
|
||||
//SORT ORDER ###################
|
||||
// dynamic dsortarray = new JArray();
|
||||
// dynamic dsort = new JObject();
|
||||
// dsort.fld = "widgetcount";
|
||||
// dsort.dir = "-";
|
||||
dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetcount", "-"));
|
||||
|
||||
//NOW FETCH WIDGET LIST WITH FILTER
|
||||
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//assert contains exactly 3 records
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(3);
|
||||
|
||||
//assert the order returned
|
||||
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
|
||||
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
|
||||
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
|
||||
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void SortByMultipleFieldsWorks()
|
||||
{
|
||||
/*
|
||||
|
||||
Created order:
|
||||
dollaramount, count
|
||||
2,1
|
||||
1,2
|
||||
2,2
|
||||
1,1
|
||||
|
||||
|
||||
sorted order:
|
||||
dollar asc, count desc
|
||||
1,2
|
||||
1,1
|
||||
2,2
|
||||
2,1
|
||||
|
||||
*/
|
||||
var WidgetNameStart = Util.Uniquify("SortByMultipleFieldsWorks");
|
||||
|
||||
//CREATE 4 TEST WIDGETS TO TEST ORDER
|
||||
long FirstInOrderWidgetId = 0;
|
||||
long SecondInOrderWidgetId = 0;
|
||||
long ThirdInOrderWidgetId = 0;
|
||||
long FourthInOrderWidgetId = 0;
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.dollaramount = 2.22;
|
||||
w.count = 1;
|
||||
w.usertype = 1;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FourthInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.dollaramount = 1.11;
|
||||
w.count = 2;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.dollaramount = 1.11;
|
||||
w.count = 1;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.dollaramount = 2.22;
|
||||
w.count = 2;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
|
||||
//FILTER IN BY NAME FOR TESTING THIS RUN ONLY
|
||||
dynamic dListView = new JArray();
|
||||
//name starts with filter to constrict to widgets that this test block created only
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart));
|
||||
|
||||
//SORT ORDER ###################
|
||||
// dynamic dsortarray = new JArray();
|
||||
|
||||
//First column
|
||||
// dynamic dsort1 = new JObject();
|
||||
// dsort1.fld = "widgetdollaramount";
|
||||
// dsort1.dir = "+";
|
||||
// dsortarray.Add(dsort1);
|
||||
dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetdollaramount", "+"));
|
||||
|
||||
//Second column
|
||||
// dynamic dsort2 = new JObject();
|
||||
// dsort2.fld = "widgetcount";
|
||||
// dsort2.dir = "-";
|
||||
// dsortarray.Add(dsort2);
|
||||
dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetcount", "-"));
|
||||
|
||||
|
||||
//NOW FETCH WIDGET LIST WITH FILTER
|
||||
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//assert contains exactly 3 records
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(4);
|
||||
|
||||
//assert the order returned
|
||||
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
|
||||
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
|
||||
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
|
||||
a.ObjectResponse["data"][3][0]["i"].Value<long>().Should().Be(FourthInOrderWidgetId);
|
||||
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FourthInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
|
||||
public class DataListSorting
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DefaultSortByIdWorks()
|
||||
{
|
||||
|
||||
var WidgetNameStart = Util.Uniquify("DefaultSortByIdWorks");
|
||||
|
||||
//CREATE 3 TEST WIDGETS TO TEST ORDER
|
||||
long FirstInOrderWidgetId = 0;
|
||||
long SecondInOrderWidgetId = 0;
|
||||
long ThirdInOrderWidgetId = 0;
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.usertype = 1;
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
|
||||
dynamic dListView = new JArray();
|
||||
|
||||
|
||||
//name starts with filter to constrict to widgets that this test block created only
|
||||
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart));
|
||||
|
||||
//NOW FETCH WIDGET LIST WITH FILTER
|
||||
// a = await Util.GetAsync($"data-list/list?DataListKey=TestWidgetDataList&Offset=0&Limit=999&DataFilterId={DataFilterId.ToString()}", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//assert contains exactly 3 records
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(3);
|
||||
|
||||
//assert the order returned
|
||||
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
|
||||
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
|
||||
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
|
||||
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task SortByFieldAscendingWorks()
|
||||
{
|
||||
|
||||
var WidgetNameStart = Util.Uniquify("SortByFieldAscendingWorks");
|
||||
|
||||
//CREATE 3 TEST WIDGETS TO TEST ORDER
|
||||
long FirstInOrderWidgetId = 0;
|
||||
long SecondInOrderWidgetId = 0;
|
||||
long ThirdInOrderWidgetId = 0;
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.startDate = DateTime.Now;
|
||||
w.endDate = DateTime.Now.AddHours(1);
|
||||
w.usertype = 1;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.startDate = DateTime.Now.AddHours(1);
|
||||
w.endDate = DateTime.Now.AddHours(2);
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.startDate = DateTime.Now.AddHours(2);
|
||||
w.endDate = DateTime.Now.AddHours(3);
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
//FILTER IN BY NAME FOR TESTING THIS RUN ONLY
|
||||
dynamic dListView = new JArray();
|
||||
//name starts with filter to constrict to widgets that this test block created only
|
||||
|
||||
|
||||
//SORT ORDER ###################
|
||||
// dynamic dsortarray = new JArray();
|
||||
// dynamic dsort = new JObject();
|
||||
// dsort.fld = "widgetstartdate";
|
||||
// dsort.dir = "+";
|
||||
// dsortarray.Add(dsort);
|
||||
|
||||
//both conditions filter and sort here
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart, "+"));
|
||||
|
||||
|
||||
|
||||
//NOW FETCH WIDGET LIST WITH FILTER
|
||||
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//assert contains exactly 3 records
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(3);
|
||||
|
||||
//assert the order returned
|
||||
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
|
||||
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
|
||||
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
|
||||
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task SortByFieldDescendingWorks()
|
||||
{
|
||||
|
||||
var WidgetNameStart = Util.Uniquify("SortByFieldDescendingWorks");
|
||||
|
||||
//CREATE 3 TEST WIDGETS TO TEST ORDER
|
||||
long FirstInOrderWidgetId = 0;
|
||||
long SecondInOrderWidgetId = 0;
|
||||
long ThirdInOrderWidgetId = 0;
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.count = 999;
|
||||
w.usertype = 1;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.count = 665;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.count = 333;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
|
||||
//FILTER IN BY NAME FOR TESTING THIS RUN ONLY
|
||||
dynamic dListView = new JArray();
|
||||
//name starts with filter to constrict to widgets that this test block created only
|
||||
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart));
|
||||
|
||||
|
||||
//SORT ORDER ###################
|
||||
// dynamic dsortarray = new JArray();
|
||||
// dynamic dsort = new JObject();
|
||||
// dsort.fld = "widgetcount";
|
||||
// dsort.dir = "-";
|
||||
dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetcount", "-"));
|
||||
|
||||
//NOW FETCH WIDGET LIST WITH FILTER
|
||||
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//assert contains exactly 3 records
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(3);
|
||||
|
||||
//assert the order returned
|
||||
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
|
||||
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
|
||||
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
|
||||
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task SortByMultipleFieldsWorks()
|
||||
{
|
||||
/*
|
||||
|
||||
Created order:
|
||||
dollaramount, count
|
||||
2,1
|
||||
1,2
|
||||
2,2
|
||||
1,1
|
||||
|
||||
|
||||
sorted order:
|
||||
dollar asc, count desc
|
||||
1,2
|
||||
1,1
|
||||
2,2
|
||||
2,1
|
||||
|
||||
*/
|
||||
var WidgetNameStart = Util.Uniquify("SortByMultipleFieldsWorks");
|
||||
|
||||
//CREATE 4 TEST WIDGETS TO TEST ORDER
|
||||
long FirstInOrderWidgetId = 0;
|
||||
long SecondInOrderWidgetId = 0;
|
||||
long ThirdInOrderWidgetId = 0;
|
||||
long FourthInOrderWidgetId = 0;
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.dollaramount = 2.22;
|
||||
w.count = 1;
|
||||
w.usertype = 1;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FourthInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.dollaramount = 1.11;
|
||||
w.count = 2;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
FirstInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.dollaramount = 1.11;
|
||||
w.count = 1;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
SecondInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.dollaramount = 2.22;
|
||||
w.count = 2;
|
||||
w.usertype = 1;
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ThirdInOrderWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
|
||||
//FILTER IN BY NAME FOR TESTING THIS RUN ONLY
|
||||
dynamic dListView = new JArray();
|
||||
//name starts with filter to constrict to widgets that this test block created only
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart));
|
||||
|
||||
//SORT ORDER ###################
|
||||
// dynamic dsortarray = new JArray();
|
||||
|
||||
//First column
|
||||
// dynamic dsort1 = new JObject();
|
||||
// dsort1.fld = "widgetdollaramount";
|
||||
// dsort1.dir = "+";
|
||||
// dsortarray.Add(dsort1);
|
||||
dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetdollaramount", "+"));
|
||||
|
||||
//Second column
|
||||
// dynamic dsort2 = new JObject();
|
||||
// dsort2.fld = "widgetcount";
|
||||
// dsort2.dir = "-";
|
||||
// dsortarray.Add(dsort2);
|
||||
dListView.Add(Util.BuildSimpleSortDataListViewColumn("widgetcount", "-"));
|
||||
|
||||
|
||||
//NOW FETCH WIDGET LIST WITH FILTER
|
||||
a = await Util.PostAsync($"data-list", await Util.GetTokenAsync("superuser", "l3tm3in"), Util.BuildDataListRequestEx(dListView));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//assert contains exactly 3 records
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(4);
|
||||
|
||||
//assert the order returned
|
||||
a.ObjectResponse["data"][0][0]["i"].Value<long>().Should().Be(FirstInOrderWidgetId);
|
||||
a.ObjectResponse["data"][1][0]["i"].Value<long>().Should().Be(SecondInOrderWidgetId);
|
||||
a.ObjectResponse["data"][2][0]["i"].Value<long>().Should().Be(ThirdInOrderWidgetId);
|
||||
a.ObjectResponse["data"][3][0]["i"].Value<long>().Should().Be(FourthInOrderWidgetId);
|
||||
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FirstInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + SecondInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + ThirdInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("widget/" + FourthInOrderWidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,202 +1,202 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class DataListFilterCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void CRUD()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("Test DataListView");
|
||||
|
||||
d["public"] = true;
|
||||
d.listKey="TestWidgetDataList";
|
||||
|
||||
//"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
|
||||
dynamic dListView = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "widgetname";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dListView.Add(df);
|
||||
// d.filter = dListView.ToString();//it expects it to be a json string, not actual json
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, "Generic"));
|
||||
d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
long Id = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
//Get one
|
||||
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataListView");
|
||||
|
||||
//Get as alternate user should work for public filter
|
||||
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataListView");
|
||||
|
||||
|
||||
//UPDATE
|
||||
|
||||
//PUT, make private
|
||||
d["public"] = false;
|
||||
d.name = Util.Uniquify("Put - Test DataListView (privatized)");
|
||||
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
a = await Util.PutAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//check PUT worked
|
||||
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateNoErrorInResponse(a);
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().Be(d.name.ToString());
|
||||
|
||||
|
||||
//FETCH DISALLOWED
|
||||
//Get as alternate user should fail for private filter
|
||||
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited"));
|
||||
Util.ValidateResponseNotFound(a);
|
||||
|
||||
// //DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void InvalidListKeyShouldFail()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("Test DataListView");
|
||||
|
||||
d["public"] = true;
|
||||
d.listKey = "nonexistant";
|
||||
|
||||
//"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
|
||||
// dynamic dfilter = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "name";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dfilter.Add(df);
|
||||
|
||||
// d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
// ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
|
||||
dynamic dListView = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "widgetname";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dListView.Add(df);
|
||||
// d.filter = dListView.ToString();//it expects it to be a json string, not actual json
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, "Generic"));
|
||||
d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "ListKey", "2203");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void InvalidFieldNameShouldFail()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("Test DataListView");
|
||||
|
||||
d["public"] = true;
|
||||
d.listKey="TestWidgetDataList";
|
||||
|
||||
//"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
|
||||
// dynamic dfilter = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "doesntexist";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dfilter.Add(df);
|
||||
|
||||
// d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
// ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
dynamic dListView = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "widgetname";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dListView.Add(df);
|
||||
// d.filter = dListView.ToString();//it expects it to be a json string, not actual json
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("doesntexist", Util.OpStartsWith, "Generic"));
|
||||
d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "ListView", "2203");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//REMOVED THIS VALIDATION TEST AS SWITCH TO DATALISTVIEW NO LONGER VALIDATES FILTER ANYWAY
|
||||
//ONLY COLUMN NAMES AND LIST NAME
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// [Fact]
|
||||
// public async void InvalidOperatorShouldFail()
|
||||
// {
|
||||
// //CREATE
|
||||
// dynamic d = new JObject();
|
||||
// d.name = Util.Uniquify("Test DataListView");
|
||||
|
||||
// d["public"] = true;
|
||||
// d.listKey="TestWidgetDataList";
|
||||
|
||||
// //"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
|
||||
// dynamic dfilter = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "name";
|
||||
// df.op = "wtf";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dfilter.Add(df);
|
||||
|
||||
// d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
// ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
// Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
// Util.ShouldContainValidationError(a, "Filter", "2203");
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class DataListFilterCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task CRUD()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("Test DataListView");
|
||||
|
||||
d["public"] = true;
|
||||
d.listKey="TestWidgetDataList";
|
||||
|
||||
//"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
|
||||
dynamic dListView = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "widgetname";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dListView.Add(df);
|
||||
// d.filter = dListView.ToString();//it expects it to be a json string, not actual json
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, "Generic"));
|
||||
d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
long Id = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
//Get one
|
||||
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataListView");
|
||||
|
||||
//Get as alternate user should work for public filter
|
||||
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().StartWith("Test DataListView");
|
||||
|
||||
|
||||
//UPDATE
|
||||
|
||||
//PUT, make private
|
||||
d["public"] = false;
|
||||
d.name = Util.Uniquify("Put - Test DataListView (privatized)");
|
||||
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
a = await Util.PutAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//check PUT worked
|
||||
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateNoErrorInResponse(a);
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().Be(d.name.ToString());
|
||||
|
||||
|
||||
//FETCH DISALLOWED
|
||||
//Get as alternate user should fail for private filter
|
||||
a = await Util.GetAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("SubContractorLimited"));
|
||||
Util.ValidateResponseNotFound(a);
|
||||
|
||||
// //DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("data-list-view/" + Id.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task InvalidListKeyShouldFail()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("Test DataListView");
|
||||
|
||||
d["public"] = true;
|
||||
d.listKey = "nonexistant";
|
||||
|
||||
//"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
|
||||
// dynamic dfilter = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "name";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dfilter.Add(df);
|
||||
|
||||
// d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
// ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
|
||||
dynamic dListView = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "widgetname";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dListView.Add(df);
|
||||
// d.filter = dListView.ToString();//it expects it to be a json string, not actual json
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, "Generic"));
|
||||
d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "ListKey", "2203");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task InvalidFieldNameShouldFail()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("Test DataListView");
|
||||
|
||||
d["public"] = true;
|
||||
d.listKey="TestWidgetDataList";
|
||||
|
||||
//"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
|
||||
// dynamic dfilter = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "doesntexist";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dfilter.Add(df);
|
||||
|
||||
// d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
// ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
dynamic dListView = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "widgetname";
|
||||
// df.op = "%-";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dListView.Add(df);
|
||||
// d.filter = dListView.ToString();//it expects it to be a json string, not actual json
|
||||
dListView.Add(Util.BuildSimpleFilterDataListViewColumn("doesntexist", Util.OpStartsWith, "Generic"));
|
||||
d.listView=dListView.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "ListView", "2203");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//REMOVED THIS VALIDATION TEST AS SWITCH TO DATALISTVIEW NO LONGER VALIDATES FILTER ANYWAY
|
||||
//ONLY COLUMN NAMES AND LIST NAME
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// [Fact]
|
||||
// public async Task InvalidOperatorShouldFail()
|
||||
// {
|
||||
// //CREATE
|
||||
// dynamic d = new JObject();
|
||||
// d.name = Util.Uniquify("Test DataListView");
|
||||
|
||||
// d["public"] = true;
|
||||
// d.listKey="TestWidgetDataList";
|
||||
|
||||
// //"[{fld:"name",op:"!=",value:"Notequaltothis"},{fld:"tags",op:"Eq",value:"[23,456,54]"}]
|
||||
// dynamic dfilter = new JArray();
|
||||
// dynamic df = new JObject();
|
||||
// df.fld = "name";
|
||||
// df.op = "wtf";
|
||||
// df.value = "Generic";//lots of seed widgets start with Generic
|
||||
// dfilter.Add(df);
|
||||
|
||||
// d.filter = dfilter.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
// ApiResponse a = await Util.PostAsync("data-list-view", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
// Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
// Util.ShouldContainValidationError(a, "Filter", "2203");
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
62
Docs/Docs.cs
62
Docs/Docs.cs
@@ -1,31 +1,31 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Docs
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void UserManualShouldFetch()
|
||||
{
|
||||
ApiTextResponse t = await Util.GetNonApiPageAsync("docs/");
|
||||
Util.ValidateHTTPStatusCode(t, 200);
|
||||
t.TextResponse.Should().Contain("<title>AyaNova manual</title>");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Docs
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task UserManualShouldFetch()
|
||||
{
|
||||
ApiTextResponse t = await Util.GetNonApiPageAsync("docs/");
|
||||
Util.ValidateHTTPStatusCode(t, 200);
|
||||
t.TextResponse.Should().Contain("<title>AyaNova manual</title>");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class EnumListOps
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetListOfEnumListsAndGetAllEnumListsWorks()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("enum-list/listkeys", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(2);
|
||||
|
||||
//iterate all the list names and fetch each one in turn and see that it fetches ok and has at least 2 list items in it
|
||||
foreach (JObject jListName in a.ObjectResponse["data"])
|
||||
{
|
||||
|
||||
ApiResponse b = await Util.GetAsync($"enum-list/list/{jListName["key"].Value<string>()}", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(b);
|
||||
Util.ValidateHTTPStatusCode(b, 200);
|
||||
((JArray)b.ObjectResponse["data"]).Count.Should().BeGreaterThan(1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class EnumListOps
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetListOfEnumListsAndGetAllEnumListsWorks()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("enum-list/listkeys", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(2);
|
||||
|
||||
//iterate all the list names and fetch each one in turn and see that it fetches ok and has at least 2 list items in it
|
||||
foreach (JObject jListName in a.ObjectResponse["data"])
|
||||
{
|
||||
|
||||
ApiResponse b = await Util.GetAsync($"enum-list/list/{jListName["key"].Value<string>()}", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(b);
|
||||
Util.ValidateHTTPStatusCode(b, 200);
|
||||
((JArray)b.ObjectResponse["data"]).Count.Should().BeGreaterThan(1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,221 +1,221 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class EventLog
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ObjectLogWorks()
|
||||
{
|
||||
//CRUD a widget and confirm it logs properly
|
||||
//http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1
|
||||
//http://localhost:7575/api/v8.0/event-log/objectlog?AyType=2&AyId=242
|
||||
//http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1&StartDate=2018-08-23&EndDate=2018-08-24
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify("EventLog Test WIDGET");
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.created = DateTime.Now.ToString();
|
||||
w.dollarAmount = 2.22m;
|
||||
w.active = true;
|
||||
w.usertype = 1;
|
||||
|
||||
//*** CREATED
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
ApiResponse EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(1);//only one event so far
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull();
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(1);//AyEvent 1 = created
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Should().BeNullOrEmpty();
|
||||
|
||||
//Get current user doing modifications ID
|
||||
long CurrentUserId = EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Value<long>();
|
||||
|
||||
//*** RETRIEVED
|
||||
//Get one
|
||||
ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
|
||||
Util.ValidateDataReturnResponseOk(r3);
|
||||
r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w.name.ToString());
|
||||
w = r3.ObjectResponse["data"];
|
||||
|
||||
|
||||
EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
//confirm event count, type and sort order (descending by date most recent first)
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(2);
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull();
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(2);//AyEvent 2 = retrieved
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Should().BeNullOrEmpty();
|
||||
|
||||
//*** MODIFIED
|
||||
//PUT
|
||||
//update w2id
|
||||
w.name = Util.Uniquify("UPDATED VIA PUT EVENTLOG TEST WIDGET");
|
||||
w.UserId = 1;
|
||||
w.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("InventoryFull"), w.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//*** RETRIEVED
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w.name.ToString());
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(4);
|
||||
//put op is the second item in the list, top item is the recent fetch
|
||||
EventLogResponse.ObjectResponse["data"]["events"][1]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
|
||||
EventLogResponse.ObjectResponse["data"]["events"][1]["userId"].Should().NotBeNull();
|
||||
EventLogResponse.ObjectResponse["data"]["events"][1]["event"].Value<int>().Should().Be(3);//AyEvent 3 = Modified
|
||||
EventLogResponse.ObjectResponse["data"]["events"][1]["textra"].Should().BeNullOrEmpty();
|
||||
|
||||
|
||||
//Check user log for basic accessibility userlog?UserId=7
|
||||
EventLogResponse = await Util.GetAsync($"event-log/userlog?UserId={CurrentUserId}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().BeGreaterOrEqualTo(4);//just one run of the above will be 4 events plus any others from other tests
|
||||
//Not sure of any easy way to assert the User log is correct other than the count as other tests running concurrently could easily skew this
|
||||
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
//All events should be cleared up on deletion with the sole exception of the deleted event
|
||||
EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(1);
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull();
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(0);//AyEvent 0 = deleted
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Value<string>().Should().Be(w.name.ToString());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void UserLogWorks()
|
||||
{
|
||||
//get admin log, sb lots of shit
|
||||
ApiResponse a = await Util.GetAsync($"event-log/userlog?UserId=1&Offset=0&Limit=999", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().BeGreaterThan(90);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void EventLogLimitOffSetWorks()
|
||||
{
|
||||
|
||||
var UniqueName = Util.Uniquify("EventLogLimitOffSetWorks");
|
||||
//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("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long UserId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//Loop and make 10 widgets
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("EventLogLimitOffSetWorks");
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
d.notes = "note here";
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync(UniqueName, UniqueName), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=0&Limit=9", await Util.GetTokenAsync("BizAdminFull"));
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(9);
|
||||
//capture events, then compare to paged ones
|
||||
var eventList = ((JArray)a.ObjectResponse["data"]["events"]);
|
||||
List<string> allEvents = new List<string>(9);
|
||||
foreach (JObject o in eventList)
|
||||
{
|
||||
allEvents.Add(o["date"].Value<string>() + o["objectType"].Value<string>()
|
||||
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
|
||||
);
|
||||
}
|
||||
|
||||
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=0&Limit=3", await Util.GetTokenAsync("BizAdminFull"));
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3);
|
||||
var pageEventList = ((JArray)a.ObjectResponse["data"]["events"]);
|
||||
foreach (JObject o in pageEventList)
|
||||
{
|
||||
allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>()
|
||||
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
|
||||
);
|
||||
}
|
||||
|
||||
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=1&Limit=3", await Util.GetTokenAsync("BizAdminFull"));
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3);
|
||||
pageEventList = ((JArray)a.ObjectResponse["data"]["events"]);
|
||||
foreach (JObject o in pageEventList)
|
||||
{
|
||||
allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>()
|
||||
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=2&Limit=3", await Util.GetTokenAsync("BizAdminFull"));
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3);
|
||||
pageEventList = ((JArray)a.ObjectResponse["data"]["events"]);
|
||||
foreach (JObject o in pageEventList)
|
||||
{
|
||||
allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>()
|
||||
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class EventLog
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ObjectLogWorks()
|
||||
{
|
||||
//CRUD a widget and confirm it logs properly
|
||||
//http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1
|
||||
//http://localhost:7575/api/v8.0/event-log/objectlog?AyType=2&AyId=242
|
||||
//http://localhost:7575/api/v8.0/event-log/userlog?AyType=3&AyId=1&StartDate=2018-08-23&EndDate=2018-08-24
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify("EventLog Test WIDGET");
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.created = DateTime.Now.ToString();
|
||||
w.dollarAmount = 2.22m;
|
||||
w.active = true;
|
||||
w.usertype = 1;
|
||||
|
||||
//*** CREATED
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
ApiResponse EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(1);//only one event so far
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull();
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(1);//AyEvent 1 = created
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Should().BeNullOrEmpty();
|
||||
|
||||
//Get current user doing modifications ID
|
||||
long CurrentUserId = EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Value<long>();
|
||||
|
||||
//*** RETRIEVED
|
||||
//Get one
|
||||
ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
|
||||
Util.ValidateDataReturnResponseOk(r3);
|
||||
r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w.name.ToString());
|
||||
w = r3.ObjectResponse["data"];
|
||||
|
||||
|
||||
EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
//confirm event count, type and sort order (descending by date most recent first)
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(2);
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull();
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(2);//AyEvent 2 = retrieved
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Should().BeNullOrEmpty();
|
||||
|
||||
//*** MODIFIED
|
||||
//PUT
|
||||
//update w2id
|
||||
w.name = Util.Uniquify("UPDATED VIA PUT EVENTLOG TEST WIDGET");
|
||||
w.UserId = 1;
|
||||
w.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("InventoryFull"), w.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//*** RETRIEVED
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w.name.ToString());
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(4);
|
||||
//put op is the second item in the list, top item is the recent fetch
|
||||
EventLogResponse.ObjectResponse["data"]["events"][1]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
|
||||
EventLogResponse.ObjectResponse["data"]["events"][1]["userId"].Should().NotBeNull();
|
||||
EventLogResponse.ObjectResponse["data"]["events"][1]["event"].Value<int>().Should().Be(3);//AyEvent 3 = Modified
|
||||
EventLogResponse.ObjectResponse["data"]["events"][1]["textra"].Should().BeNullOrEmpty();
|
||||
|
||||
|
||||
//Check user log for basic accessibility userlog?UserId=7
|
||||
EventLogResponse = await Util.GetAsync($"event-log/userlog?UserId={CurrentUserId}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().BeGreaterOrEqualTo(4);//just one run of the above will be 4 events plus any others from other tests
|
||||
//Not sure of any easy way to assert the User log is correct other than the count as other tests running concurrently could easily skew this
|
||||
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("InventoryFull"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
//All events should be cleared up on deletion with the sole exception of the deleted event
|
||||
EventLogResponse = await Util.GetAsync($"event-log/objectlog?AyaType=2&AyId={w2Id}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(EventLogResponse, 200);
|
||||
((JArray)EventLogResponse.ObjectResponse["data"]["events"]).Count.Should().Be(1);
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["date"].Value<DateTime>().Should().BeLessThan(new TimeSpan(1, 0, 0)).Before(DateTime.UtcNow);//should be less than one hour before now
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["userId"].Should().NotBeNull();
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["event"].Value<int>().Should().Be(0);//AyEvent 0 = deleted
|
||||
EventLogResponse.ObjectResponse["data"]["events"][0]["textra"].Value<string>().Should().Be(w.name.ToString());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task UserLogWorks()
|
||||
{
|
||||
//get admin log, sb lots of shit
|
||||
ApiResponse a = await Util.GetAsync($"event-log/userlog?UserId=1&Offset=0&Limit=999", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().BeGreaterThan(90);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task EventLogLimitOffSetWorks()
|
||||
{
|
||||
|
||||
var UniqueName = Util.Uniquify("EventLogLimitOffSetWorks");
|
||||
//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("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long UserId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//Loop and make 10 widgets
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("EventLogLimitOffSetWorks");
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
d.notes = "note here";
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync(UniqueName, UniqueName), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=0&Limit=9", await Util.GetTokenAsync("BizAdminFull"));
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(9);
|
||||
//capture events, then compare to paged ones
|
||||
var eventList = ((JArray)a.ObjectResponse["data"]["events"]);
|
||||
List<string> allEvents = new List<string>(9);
|
||||
foreach (JObject o in eventList)
|
||||
{
|
||||
allEvents.Add(o["date"].Value<string>() + o["objectType"].Value<string>()
|
||||
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
|
||||
);
|
||||
}
|
||||
|
||||
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=0&Limit=3", await Util.GetTokenAsync("BizAdminFull"));
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3);
|
||||
var pageEventList = ((JArray)a.ObjectResponse["data"]["events"]);
|
||||
foreach (JObject o in pageEventList)
|
||||
{
|
||||
allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>()
|
||||
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
|
||||
);
|
||||
}
|
||||
|
||||
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=1&Limit=3", await Util.GetTokenAsync("BizAdminFull"));
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3);
|
||||
pageEventList = ((JArray)a.ObjectResponse["data"]["events"]);
|
||||
foreach (JObject o in pageEventList)
|
||||
{
|
||||
allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>()
|
||||
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
a = await Util.GetAsync($"event-log/userlog?UserId={UserId}&Offset=2&Limit=3", await Util.GetTokenAsync("BizAdminFull"));
|
||||
((JArray)a.ObjectResponse["data"]["events"]).Count.Should().Be(3);
|
||||
pageEventList = ((JArray)a.ObjectResponse["data"]["events"]);
|
||||
foreach (JObject o in pageEventList)
|
||||
{
|
||||
allEvents.Should().Contain(o["date"].Value<string>() + o["objectType"].Value<string>()
|
||||
+ o["objectId"].Value<string>() + o["name"].Value<string>() + o["event"].Value<string>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,241 +1,241 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class FormCustom
|
||||
{
|
||||
public enum AyaUiFieldDataType : int
|
||||
{
|
||||
NoType = 0,
|
||||
DateTime = 1,
|
||||
Date = 2,
|
||||
Time = 3,
|
||||
Text = 4,
|
||||
Integer = 5,
|
||||
Bool = 6,
|
||||
Decimal = 7,
|
||||
Currency = 8,
|
||||
Tags = 9,
|
||||
Enum = 10,
|
||||
EmailAddress = 11
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test create or update
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void FormCustomUpdate()
|
||||
{
|
||||
|
||||
//This is a special case, you can PUT a formcustom, but you can't delete one and you can't create one
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.formkey = "User";
|
||||
|
||||
dynamic dtemplate = new JArray();
|
||||
|
||||
dynamic dt = new JObject();
|
||||
dt.fld = "UserCustom1";
|
||||
dt.hide = false;
|
||||
dt.required = true;
|
||||
dt.type = AyaUiFieldDataType.Text;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "Notes";
|
||||
dt.required = true;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "UserCustom2";
|
||||
dt.hide = true;
|
||||
dt.required = false;
|
||||
dt.type = AyaUiFieldDataType.Bool;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
d.template = dtemplate.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
//Get the current one (server will create if non-existent)
|
||||
ApiResponse a = await Util.GetAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"));
|
||||
|
||||
//Update
|
||||
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
a = await Util.PutAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//check the concurrency token cache scheme
|
||||
uint token = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
//This should return a 304 not modified
|
||||
a = await Util.GetAsync($"form-custom/User?concurrency={token}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 304);
|
||||
|
||||
//and this should return the whole object
|
||||
token--;//make the token not match
|
||||
//This should return a 200 and the whole object
|
||||
a = await Util.GetAsync($"form-custom/User?concurrency={token}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ensure validation works in FormCustombiz
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ValidatesProperly()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.formkey = "User";
|
||||
|
||||
dynamic dtemplate = new JArray();
|
||||
|
||||
dynamic dt = new JObject();
|
||||
dt.fld = string.Empty;//expected ApiErrorCode.VALIDATION_REQUIRED Missing key 2 errors 2201 and 2203
|
||||
dt.hide = false;
|
||||
dt.required = true;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "ThisFieldKeyDoesNotExist";//expected ApiErrorCode.VALIDATION_INVALID_VALUE Bad key
|
||||
dt.required = true;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "Name";//expect ApiErrorCode.VALIDATION_INVALID_VALUE required field not hideable
|
||||
dt.hide = true;
|
||||
dt.required = true;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "UserCustom1";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field
|
||||
dt.hide = false;
|
||||
dt.required = false;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "EmployeeNumber";//expect ApiErrorCode.VALIDATION_INVALID_VALUE not custom field but type specified anyway
|
||||
dt.hide = true;
|
||||
dt.required = false;
|
||||
dt.type = AyaUiFieldDataType.EmailAddress;//type specified (doesn't matter what type)
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "UserCustom2";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field
|
||||
dt.hide = false;
|
||||
dt.required = false;
|
||||
dtemplate.Add(dt);
|
||||
dt.type = 999;//not a valid type
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "Notes";//expect ApiErrorCode.VALIDATION_REQUIRED required property is always required (no idea why, just designed that way and that's the rule)
|
||||
dt.hide = true;
|
||||
// dt.required = false; Deliberately not set
|
||||
dtemplate.Add(dt);
|
||||
|
||||
d.template = dtemplate.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
//Get the current one (server will create if non-existent)
|
||||
ApiResponse a = await Util.GetAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"));
|
||||
|
||||
//Update
|
||||
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
a = await Util.PutAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateHTTPStatusCode(a, 400);
|
||||
Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 0, \"fld\" property exists but is empty, a value is required");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 0, fld property value \"\" is not a valid form field value for formKey specified");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 1, fld property value \"ThisFieldKeyDoesNotExist\" is not a valid form field value for formKey specified");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 2 (\"Name\"), \"hide\" property value of \"True\" is not valid, this field is core and cannot be hidden");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 3 (\"UserCustom1\"), \"type\" property value is MISSING for custom field, Custom fields MUST have types specified");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 4 (\"EmployeeNumber\"), \"type\" property value is not valid, only Custom fields can have types specified");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 5 (\"UserCustom2\"), \"type\" property value of \"999\" is not a valid custom field type");
|
||||
Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 6, object is missing \"required\" property. All items must contain this property.");
|
||||
|
||||
/*
|
||||
"{\"error\":{\"code\":\"2200\",\"details\":[
|
||||
{\"message\":\"Template array item 0, \\\"fld\\\" property exists but is empty, a value is required\",\"target\":\"Template\",\"error\":\"2201\"},
|
||||
{\"message\":\"Template array item 0, fld property value \\\"\\\" is not a valid form field value for formKey specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 1, fld property value \\\"ThisFieldKeyDoesNotExist\\\" is not a valid form field value for formKey specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 2 (\\\"Name\\\"), \\\"hide\\\" property value of \\\"True\\\" is not valid, this field is core and cannot be hidden\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 3 (\\\"UserCustom1\\\"), \\\"type\\\" property value is MISSING for custom filed, Custom fields MUST have types specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 4 (\\\"EmployeeNumber\\\"), \\\"type\\\" property value is not valid, only Custom fields can have types specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 5 (\\\"UserCustom2\\\"), \\\"type\\\" property value of \\\"999\\\" is not a valid custom field type\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 6, object is missing \\\"required\\\" property. All items must contain this property. \",\"target\":\"Template\",\"error\":\"2201\"}
|
||||
],\"message\":\"Object did not pass validation\"}}"
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void InvalidObjectFieldsFormKeyShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("form-field-definition/nonexistent", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateErrorCodeResponse(a, 2010, 404);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ObjectFieldsWorks()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("form-field-definition/Widget", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(25);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void AvailableCustomizableFormKeysWorks()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("form-custom/availablecustomizableformkeys", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1);//is 2 as of writing (widget,user)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void AvailableCustomTypesWorks()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("form-custom/availablecustomtypes", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class FormCustom
|
||||
{
|
||||
public enum AyaUiFieldDataType : int
|
||||
{
|
||||
NoType = 0,
|
||||
DateTime = 1,
|
||||
Date = 2,
|
||||
Time = 3,
|
||||
Text = 4,
|
||||
Integer = 5,
|
||||
Bool = 6,
|
||||
Decimal = 7,
|
||||
Currency = 8,
|
||||
Tags = 9,
|
||||
Enum = 10,
|
||||
EmailAddress = 11
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test create or update
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task FormCustomUpdate()
|
||||
{
|
||||
|
||||
//This is a special case, you can PUT a formcustom, but you can't delete one and you can't create one
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.formkey = "User";
|
||||
|
||||
dynamic dtemplate = new JArray();
|
||||
|
||||
dynamic dt = new JObject();
|
||||
dt.fld = "UserCustom1";
|
||||
dt.hide = false;
|
||||
dt.required = true;
|
||||
dt.type = AyaUiFieldDataType.Text;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "Notes";
|
||||
dt.required = true;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "UserCustom2";
|
||||
dt.hide = true;
|
||||
dt.required = false;
|
||||
dt.type = AyaUiFieldDataType.Bool;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
d.template = dtemplate.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
//Get the current one (server will create if non-existent)
|
||||
ApiResponse a = await Util.GetAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"));
|
||||
|
||||
//Update
|
||||
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
a = await Util.PutAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
//check the concurrency token cache scheme
|
||||
uint token = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
//This should return a 304 not modified
|
||||
a = await Util.GetAsync($"form-custom/User?concurrency={token}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 304);
|
||||
|
||||
//and this should return the whole object
|
||||
token--;//make the token not match
|
||||
//This should return a 200 and the whole object
|
||||
a = await Util.GetAsync($"form-custom/User?concurrency={token}", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ensure validation works in FormCustombiz
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ValidatesProperly()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.formkey = "User";
|
||||
|
||||
dynamic dtemplate = new JArray();
|
||||
|
||||
dynamic dt = new JObject();
|
||||
dt.fld = string.Empty;//expected ApiErrorCode.VALIDATION_REQUIRED Missing key 2 errors 2201 and 2203
|
||||
dt.hide = false;
|
||||
dt.required = true;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "ThisFieldKeyDoesNotExist";//expected ApiErrorCode.VALIDATION_INVALID_VALUE Bad key
|
||||
dt.required = true;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "Name";//expect ApiErrorCode.VALIDATION_INVALID_VALUE required field not hideable
|
||||
dt.hide = true;
|
||||
dt.required = true;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "UserCustom1";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field
|
||||
dt.hide = false;
|
||||
dt.required = false;
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "EmployeeNumber";//expect ApiErrorCode.VALIDATION_INVALID_VALUE not custom field but type specified anyway
|
||||
dt.hide = true;
|
||||
dt.required = false;
|
||||
dt.type = AyaUiFieldDataType.EmailAddress;//type specified (doesn't matter what type)
|
||||
dtemplate.Add(dt);
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "UserCustom2";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field
|
||||
dt.hide = false;
|
||||
dt.required = false;
|
||||
dtemplate.Add(dt);
|
||||
dt.type = 999;//not a valid type
|
||||
|
||||
dt = new JObject();
|
||||
dt.fld = "Notes";//expect ApiErrorCode.VALIDATION_REQUIRED required property is always required (no idea why, just designed that way and that's the rule)
|
||||
dt.hide = true;
|
||||
// dt.required = false; Deliberately not set
|
||||
dtemplate.Add(dt);
|
||||
|
||||
d.template = dtemplate.ToString();//it expects it to be a json string, not actual json
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
//Get the current one (server will create if non-existent)
|
||||
ApiResponse a = await Util.GetAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"));
|
||||
|
||||
//Update
|
||||
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
a = await Util.PutAsync("form-custom/User", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateHTTPStatusCode(a, 400);
|
||||
Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 0, \"fld\" property exists but is empty, a value is required");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 0, fld property value \"\" is not a valid form field value for formKey specified");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 1, fld property value \"ThisFieldKeyDoesNotExist\" is not a valid form field value for formKey specified");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 2 (\"Name\"), \"hide\" property value of \"True\" is not valid, this field is core and cannot be hidden");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 3 (\"UserCustom1\"), \"type\" property value is MISSING for custom field, Custom fields MUST have types specified");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 4 (\"EmployeeNumber\"), \"type\" property value is not valid, only Custom fields can have types specified");
|
||||
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 5 (\"UserCustom2\"), \"type\" property value of \"999\" is not a valid custom field type");
|
||||
Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 6, object is missing \"required\" property. All items must contain this property.");
|
||||
|
||||
/*
|
||||
"{\"error\":{\"code\":\"2200\",\"details\":[
|
||||
{\"message\":\"Template array item 0, \\\"fld\\\" property exists but is empty, a value is required\",\"target\":\"Template\",\"error\":\"2201\"},
|
||||
{\"message\":\"Template array item 0, fld property value \\\"\\\" is not a valid form field value for formKey specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 1, fld property value \\\"ThisFieldKeyDoesNotExist\\\" is not a valid form field value for formKey specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 2 (\\\"Name\\\"), \\\"hide\\\" property value of \\\"True\\\" is not valid, this field is core and cannot be hidden\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 3 (\\\"UserCustom1\\\"), \\\"type\\\" property value is MISSING for custom filed, Custom fields MUST have types specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 4 (\\\"EmployeeNumber\\\"), \\\"type\\\" property value is not valid, only Custom fields can have types specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 5 (\\\"UserCustom2\\\"), \\\"type\\\" property value of \\\"999\\\" is not a valid custom field type\",\"target\":\"Template\",\"error\":\"2203\"},
|
||||
{\"message\":\"Template array item 6, object is missing \\\"required\\\" property. All items must contain this property. \",\"target\":\"Template\",\"error\":\"2201\"}
|
||||
],\"message\":\"Object did not pass validation\"}}"
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task InvalidObjectFieldsFormKeyShouldFail()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("form-field-definition/nonexistent", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateErrorCodeResponse(a, 2010, 404);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ObjectFieldsWorks()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("form-field-definition/Widget", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(25);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task AvailableCustomizableFormKeysWorks()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("form-custom/availablecustomizableformkeys", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1);//is 2 as of writing (widget,user)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task AvailableCustomTypesWorks()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("form-custom/availablecustomtypes", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class GlobalAll
|
||||
{
|
||||
/// <summary>
|
||||
/// Test Global routes
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GlobalOps()
|
||||
{
|
||||
//excercise the fetch and update routes but no actual changes because making a change of any kind to global will likely break other tests
|
||||
//and we just need to see the routes are active really
|
||||
|
||||
ApiResponse a = await Util.GetAsync("global-biz-setting", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"]["searchCaseSensitiveOnly"].Should().NotBeNull();
|
||||
|
||||
var g = a.ObjectResponse["data"];
|
||||
a = await Util.PutAsync("global-biz-setting", await Util.GetTokenAsync("BizAdminFull"), g.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class GlobalAll
|
||||
{
|
||||
/// <summary>
|
||||
/// Test Global routes
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GlobalOps()
|
||||
{
|
||||
//excercise the fetch and update routes but no actual changes because making a change of any kind to global will likely break other tests
|
||||
//and we just need to see the routes are active really
|
||||
|
||||
ApiResponse a = await Util.GetAsync("global-biz-setting", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"]["searchCaseSensitiveOnly"].Should().NotBeNull();
|
||||
|
||||
var g = a.ObjectResponse["data"];
|
||||
a = await Util.PutAsync("global-biz-setting", await Util.GetTokenAsync("BizAdminFull"), g.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class LogFiles
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void MostRecentLogShouldFetch()
|
||||
{
|
||||
ApiTextResponse t = await Util.GetTextResultAsync("log-file/log-ayanova.txt", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(t, 200);
|
||||
string[] ExpectedLogItems = {"|INFO|","|ERROR|","|FATAL|", "|WARN|"};//assumes any log will have at least one of these items in it
|
||||
t.TextResponse.Should().ContainAny(ExpectedLogItems);
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class LogFiles
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task MostRecentLogShouldFetch()
|
||||
{
|
||||
ApiTextResponse t = await Util.GetTextResultAsync("log-file/log-ayanova.txt", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(t, 200);
|
||||
string[] ExpectedLogItems = {"|INFO|","|ERROR|","|FATAL|", "|WARN|"};//assumes any log will have at least one of these items in it
|
||||
t.TextResponse.Should().ContainAny(ExpectedLogItems);
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Metrics
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void MetricsShouldFetch()
|
||||
{
|
||||
// DateTime tsEnd = DateTime.Now.ToOffsetAdjustedUniversalTime();//{2020-05-29 3:30:21 PM}
|
||||
// DateTime tsStart = DateTime.Now.AddHours(-6).ToOffsetAdjustedUniversalTime();//{2020-05-29 9:30:21 AM}
|
||||
|
||||
// DateTime tsEnd = DateTime.UtcNow;//{2020-05-29 3:32:54 PM}
|
||||
// DateTime tsStart = DateTime.UtcNow.AddHours(-6); //{2020-05-29 9:32:54 AM}
|
||||
|
||||
//weirdly, this is the only way to get the correct date range
|
||||
//just as the html client does but from here
|
||||
//in both cases the server shows parameters as local time to the server
|
||||
//and in the route I have to adjust them back to universal time before sending them to the db query
|
||||
//as the db data is in utc and the db server doesn't know what timezone it is
|
||||
DateTime tsEnd = DateTime.Now;//{2020-05-29 8:36:48 AM}
|
||||
DateTime tsStart = DateTime.Now.AddHours(-6); //{2020-05-29 2:36:48 AM}
|
||||
|
||||
|
||||
|
||||
//http://localhost:7575/api/v8.0/server-metric/mm?maxRecords=200&tsStart=2020-05-29T09:23:18.114Z&tsEnd=2020-05-29T15:23:19.114Z
|
||||
//from client at server route {2020-05-29 2:29:25 AM} {2020-05-29 8:29:26 AM}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ApiResponse a = await Util.GetAsync($"server-metric/memcpu?tsStart={tsStart}&tsEnd={tsEnd}", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"].Should().NotBeNull();//can't get more detailed as there might not be any data here to see
|
||||
|
||||
a = await Util.GetAsync($"server-metric/storage?tsStart={tsStart}&tsEnd={tsEnd}", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"].Should().NotBeNull();//can't get more detailed as there might not be any data here to see
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Metrics
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task MetricsShouldFetch()
|
||||
{
|
||||
// DateTime tsEnd = DateTime.Now.ToOffsetAdjustedUniversalTime();//{2020-05-29 3:30:21 PM}
|
||||
// DateTime tsStart = DateTime.Now.AddHours(-6).ToOffsetAdjustedUniversalTime();//{2020-05-29 9:30:21 AM}
|
||||
|
||||
// DateTime tsEnd = DateTime.UtcNow;//{2020-05-29 3:32:54 PM}
|
||||
// DateTime tsStart = DateTime.UtcNow.AddHours(-6); //{2020-05-29 9:32:54 AM}
|
||||
|
||||
//weirdly, this is the only way to get the correct date range
|
||||
//just as the html client does but from here
|
||||
//in both cases the server shows parameters as local time to the server
|
||||
//and in the route I have to adjust them back to universal time before sending them to the db query
|
||||
//as the db data is in utc and the db server doesn't know what timezone it is
|
||||
DateTime tsEnd = DateTime.Now;//{2020-05-29 8:36:48 AM}
|
||||
DateTime tsStart = DateTime.Now.AddHours(-6); //{2020-05-29 2:36:48 AM}
|
||||
|
||||
|
||||
|
||||
//http://localhost:7575/api/v8.0/server-metric/mm?maxRecords=200&tsStart=2020-05-29T09:23:18.114Z&tsEnd=2020-05-29T15:23:19.114Z
|
||||
//from client at server route {2020-05-29 2:29:25 AM} {2020-05-29 8:29:26 AM}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ApiResponse a = await Util.GetAsync($"server-metric/memcpu?tsStart={tsStart}&tsEnd={tsEnd}", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"].Should().NotBeNull();//can't get more detailed as there might not be any data here to see
|
||||
|
||||
a = await Util.GetAsync($"server-metric/storage?tsStart={tsStart}&tsEnd={tsEnd}", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
a.ObjectResponse["data"].Should().NotBeNull();//can't get more detailed as there might not be any data here to see
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,466 +1,466 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class PickListAllTests
|
||||
{
|
||||
//NOTE: in order not to interfere in each other will use Widget picklist to test with standard unmodified picklist template
|
||||
//and will use User pick-list to test the template functionality
|
||||
|
||||
/// <summary>
|
||||
/// Test all Template editing related routes
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void UserPickListTemplatesOps()
|
||||
{
|
||||
//NOTE: Due to there being only one possible template per type, this test will need to test ALL potential tests in one function
|
||||
//and only for the User picklist in order to not step over other potential tests running in parallel
|
||||
|
||||
//REPLACE USER TEMPLATE
|
||||
dynamic d = new JObject();
|
||||
d.Id = 3;//User type
|
||||
|
||||
//custom template, only one field employee number
|
||||
dynamic dTemplateArray = new JArray();
|
||||
dynamic df = new JObject();
|
||||
df.fld = "useremployeenumber";
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
//replace the User template at the server
|
||||
ApiResponse a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
//Get one
|
||||
a = await Util.GetAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains ONE record ONLY and it's the one we set
|
||||
var templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>());
|
||||
templateArray.Count.Should().Be(1);
|
||||
templateArray[0]["fld"].Value<string>().Should().Be("useremployeenumber");
|
||||
|
||||
|
||||
//CONFIRM THE CUSTOM PICKLIST TEMPLATE WORKS PROPERLY
|
||||
//MAKE THE TEST USERS
|
||||
//First make a unique string for this iteration of this test only
|
||||
var UniquePhrase = Util.Uniquify("pick").Replace(" ", "");
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("UserPickListTemplatesOps") + UniquePhrase;
|
||||
d.active = true;
|
||||
d.login = Util.Uniquify("LOGIN");
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
|
||||
d.userType = 3;//non scheduleable
|
||||
//Required by form custom rules
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long InNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("UserPickListTemplatesOps");
|
||||
d.employeeNumber = UniquePhrase;
|
||||
d.login = Util.Uniquify("LOGIN");
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
d.active = true;
|
||||
//Required by form custom rules
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long InEmployeeNumberId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//GET PICKLIST FOR unique phrase query sb only employee number due to custom template
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(1);
|
||||
pickList[0]["id"].Value<long>().Should().Be(InEmployeeNumberId);
|
||||
|
||||
//custom template, only one field user name
|
||||
d = new JObject();
|
||||
d.Id = 3;//User type
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "username";
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
//replace the User template at the server
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
//GET PICKLIST FOR unique phrase query sb only user name field due to custom template
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull"));
|
||||
//"select auser.id as plId, auser.active as plActive, concat_ws(' ', auser.name) as plname from auser where auser.active = true and ((auser.name like '%pick1584556347748%')) order by auser.name limit 100"
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(1);
|
||||
pickList[0]["id"].Value<long>().Should().Be(InNameId);
|
||||
|
||||
//DELETE TEST USERS NO LONGER NEEDED
|
||||
a = await Util.DeleteAsync("User/" + InNameId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("User/" + InEmployeeNumberId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
// RESET TEMPLATE TO DEFAULT
|
||||
a = await Util.DeleteAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
//RETRIEVE (Confirm it's back to default)
|
||||
//Get one
|
||||
a = await Util.GetAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains default template record ONLY and it's the one we set
|
||||
templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>());
|
||||
templateArray.Count.Should().Be(3);
|
||||
templateArray[0]["fld"].Value<string>().Should().Be("username");
|
||||
|
||||
|
||||
//Now test error conditions....
|
||||
//BAD FIELD NAME VALIDATION ERROR
|
||||
d = new JObject();
|
||||
d.Id = 3;//User type
|
||||
//template, simple test, nothing fancy
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "DOES_NOT_EXIST";//<-- ERROR BAD FIELD NAME
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Template", "2203");
|
||||
|
||||
//BAD AYATYPE ERROR
|
||||
d = new JObject();
|
||||
d.Id = 0;//<==ERROR NO_TYPE, INVALID
|
||||
//template, simple test, nothing fancy
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "useremployeenumber";
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
//replace the User template at the server
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "ayaType", "2203");
|
||||
|
||||
//RIGHTS ISSUE,
|
||||
//currently only bizadminfull can change a picklist template
|
||||
d = new JObject();
|
||||
d.Id = 3;//User
|
||||
//template, simple test, nothing fancy
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "useremployeenumber";
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
//ERROR NO RIGHTS USER
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("CustomerLimited"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
//"{\"error\":{\"code\":\"2004\",\"message\":\"User not authorized for this resource operation (insufficient rights)\"}}"
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
|
||||
//EMPTY TEMPLATE VALIDATION ERROR
|
||||
d = new JObject();
|
||||
d.Id = 3;//User
|
||||
d.Template = "";//<-- ERROR no template
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Template", "2201");
|
||||
|
||||
|
||||
//MALFORMED TEMPLATE JSON ERROR
|
||||
d = new JObject();
|
||||
d.Id = 3;//User type
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "useremployeenumber";
|
||||
dTemplateArray.Add(df);
|
||||
string sTemplate = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
d.Template = sTemplate.Substring(2);//<-- ERROR missing first two characters of json template array
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template is not valid JSON string: Error reading JArray from JsonReader. Current JsonReader item is not an array: String. Path '', line 1, position 5.\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Template", "2203");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test get templates list
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PickListTemplateList()
|
||||
{
|
||||
//RETRIEVE
|
||||
ApiResponse a = await Util.GetAsync("pick-list/template/list", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains at least two records (as we only have two at time of writing this test)
|
||||
var templateList = ((JArray)a.ObjectResponse["data"]);
|
||||
templateList.Count.Should().BeGreaterThan(1);
|
||||
templateList[0]["id"].Value<long>().Should().Be(2);//first one should be a widget
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist fields list for widget template
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void WidgetPickListTemplateFieldList()
|
||||
{
|
||||
//RETRIEVE WIDGET PICKLIST FIELDS
|
||||
ApiResponse a = await Util.GetAsync("pick-list/template/ListFields/2", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains at least two records (as we only have two at time of writing this test)
|
||||
var templateList = ((JArray)a.ObjectResponse["data"]);
|
||||
templateList.Count.Should().BeGreaterThan(4);
|
||||
templateList[0]["fieldKey"].Value<string>().Should().Be("widgetactive");//first one should be a widgetactive field
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist for widget without query
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void FetchWidgetPickListNoQuery()
|
||||
{
|
||||
//RETRIEVE WIDGET PICKLIST no filter
|
||||
ApiResponse a = await Util.GetAsync("pick-list/list?ayaType=2", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains 100 records (current picklist maximum count)
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(100);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist for single predefined value only
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void FetchWidgetPickListPreDefined()
|
||||
{
|
||||
//fetch the SuperUser account which always exists
|
||||
ApiResponse a = await Util.GetAsync("pick-list/list?ayaType=3&preId=1", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains 1 record
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(1);
|
||||
pickList[0]["id"].Value<long>().Should().Be(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist for widget with basic autocomplete query only
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void FetchWidgetPickListAutoComplete()
|
||||
{
|
||||
|
||||
//make key widget
|
||||
|
||||
var WidgetNameStart = "FetchWidgetPickListAutoComplete_a1b2c3";
|
||||
long IncludedWidgetId = 0;
|
||||
//CREATE TEST WIDGETS
|
||||
//included widget
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.active = true;
|
||||
w.usertype = 1;
|
||||
w.dollarAmount = 555.55;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE WIDGET PICKLIST with name filter
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=2&query=a1b2c3", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().BeGreaterThan(0);
|
||||
pickList[0]["name"].Value<string>().Should().Contain("_a1b2c3");
|
||||
|
||||
//DELETE WIDGETS
|
||||
a = await Util.DeleteAsync("widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void FetchWidgetPickListTags()
|
||||
{
|
||||
|
||||
//make key widget
|
||||
var WidgetNameStart = "FetchWidgetPickListTags";
|
||||
long IncludedWidgetId = 0;
|
||||
//CREATE TEST WIDGETS
|
||||
//included widget
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.active = true;
|
||||
w.usertype = 1;
|
||||
w.dollarAmount = 555.55;
|
||||
//Tags
|
||||
dynamic InclusiveTagsArray = new JArray();
|
||||
InclusiveTagsArray.Add("plred");
|
||||
InclusiveTagsArray.Add("plblue");
|
||||
w.tags = InclusiveTagsArray;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE WIDGET PICKLIST with name filter
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=2&query=..lblu", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(1);
|
||||
pickList[0]["id"].Value<long>().Should().Be(IncludedWidgetId);
|
||||
|
||||
//DELETE WIDGETS
|
||||
a = await Util.DeleteAsync("widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist for widget with basic autocomplete query only
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void FetchWidgetPickListInactiveActive()
|
||||
{
|
||||
|
||||
//make key widget
|
||||
|
||||
var WidgetNameStart = "FetchWidgetPickListInactiveActive";
|
||||
List<long> ActiveWidgetIdList = new List<long>();
|
||||
List<long> NotActiveWidgetIdList = new List<long>();
|
||||
|
||||
//CREATE 4 TEST WIDGETS
|
||||
//two active and two non active
|
||||
|
||||
//first active widget
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.active = true;
|
||||
w.usertype = 1;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//second active widget
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
|
||||
//first NON active widget
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.active = false;
|
||||
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//second NON active widget
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.active = false;
|
||||
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
|
||||
//CONFIRM BOTH INACTIVE AND ACTIVE
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=2&query=ickListInactiveAct&inactive=true", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
//assert contains at least two records
|
||||
pickList.Count.Should().BeGreaterThan(1);
|
||||
int nActiveMatches = 0;
|
||||
int nInactiveMatches = 0;
|
||||
foreach (JObject o in pickList)
|
||||
{
|
||||
if (ActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
nActiveMatches++;
|
||||
if (NotActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
nInactiveMatches++;
|
||||
}
|
||||
nActiveMatches.Should().Be(ActiveWidgetIdList.Count);
|
||||
nInactiveMatches.Should().Be(NotActiveWidgetIdList.Count);
|
||||
|
||||
|
||||
//CONFIRM ACTIVE ONLY
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=2&query=ickListInactiveAct", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
//assert contains at least two records
|
||||
pickList.Count.Should().BeGreaterThan(1);
|
||||
nActiveMatches = 0;
|
||||
nInactiveMatches = 0;
|
||||
foreach (JObject o in pickList)
|
||||
{
|
||||
if (ActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
nActiveMatches++;
|
||||
if (NotActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
nInactiveMatches++;
|
||||
}
|
||||
nActiveMatches.Should().Be(ActiveWidgetIdList.Count);
|
||||
nInactiveMatches.Should().Be(0);
|
||||
|
||||
//DELETE WIDGETS
|
||||
foreach (long l in ActiveWidgetIdList)
|
||||
{
|
||||
a = await Util.DeleteAsync("widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
foreach (long l in NotActiveWidgetIdList)
|
||||
{
|
||||
a = await Util.DeleteAsync("widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class PickListAllTests
|
||||
{
|
||||
//NOTE: in order not to interfere in each other will use Widget picklist to test with standard unmodified picklist template
|
||||
//and will use User pick-list to test the template functionality
|
||||
|
||||
/// <summary>
|
||||
/// Test all Template editing related routes
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task UserPickListTemplatesOps()
|
||||
{
|
||||
//NOTE: Due to there being only one possible template per type, this test will need to test ALL potential tests in one function
|
||||
//and only for the User picklist in order to not step over other potential tests running in parallel
|
||||
|
||||
//REPLACE USER TEMPLATE
|
||||
dynamic d = new JObject();
|
||||
d.Id = 3;//User type
|
||||
|
||||
//custom template, only one field employee number
|
||||
dynamic dTemplateArray = new JArray();
|
||||
dynamic df = new JObject();
|
||||
df.fld = "useremployeenumber";
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
//replace the User template at the server
|
||||
ApiResponse a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
//Get one
|
||||
a = await Util.GetAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains ONE record ONLY and it's the one we set
|
||||
var templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>());
|
||||
templateArray.Count.Should().Be(1);
|
||||
templateArray[0]["fld"].Value<string>().Should().Be("useremployeenumber");
|
||||
|
||||
|
||||
//CONFIRM THE CUSTOM PICKLIST TEMPLATE WORKS PROPERLY
|
||||
//MAKE THE TEST USERS
|
||||
//First make a unique string for this iteration of this test only
|
||||
var UniquePhrase = Util.Uniquify("pick").Replace(" ", "");
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("UserPickListTemplatesOps") + UniquePhrase;
|
||||
d.active = true;
|
||||
d.login = Util.Uniquify("LOGIN");
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
|
||||
d.userType = 3;//non scheduleable
|
||||
//Required by form custom rules
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long InNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("UserPickListTemplatesOps");
|
||||
d.employeeNumber = UniquePhrase;
|
||||
d.login = Util.Uniquify("LOGIN");
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
d.active = true;
|
||||
//Required by form custom rules
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long InEmployeeNumberId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//GET PICKLIST FOR unique phrase query sb only employee number due to custom template
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(1);
|
||||
pickList[0]["id"].Value<long>().Should().Be(InEmployeeNumberId);
|
||||
|
||||
//custom template, only one field user name
|
||||
d = new JObject();
|
||||
d.Id = 3;//User type
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "username";
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
|
||||
//replace the User template at the server
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
//GET PICKLIST FOR unique phrase query sb only user name field due to custom template
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull"));
|
||||
//"select auser.id as plId, auser.active as plActive, concat_ws(' ', auser.name) as plname from auser where auser.active = true and ((auser.name like '%pick1584556347748%')) order by auser.name limit 100"
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(1);
|
||||
pickList[0]["id"].Value<long>().Should().Be(InNameId);
|
||||
|
||||
//DELETE TEST USERS NO LONGER NEEDED
|
||||
a = await Util.DeleteAsync("User/" + InNameId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
a = await Util.DeleteAsync("User/" + InEmployeeNumberId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
// RESET TEMPLATE TO DEFAULT
|
||||
a = await Util.DeleteAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
//RETRIEVE (Confirm it's back to default)
|
||||
//Get one
|
||||
a = await Util.GetAsync("pick-list/template/3/", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains default template record ONLY and it's the one we set
|
||||
templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>());
|
||||
templateArray.Count.Should().Be(3);
|
||||
templateArray[0]["fld"].Value<string>().Should().Be("username");
|
||||
|
||||
|
||||
//Now test error conditions....
|
||||
//BAD FIELD NAME VALIDATION ERROR
|
||||
d = new JObject();
|
||||
d.Id = 3;//User type
|
||||
//template, simple test, nothing fancy
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "DOES_NOT_EXIST";//<-- ERROR BAD FIELD NAME
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Template", "2203");
|
||||
|
||||
//BAD AYATYPE ERROR
|
||||
d = new JObject();
|
||||
d.Id = 0;//<==ERROR NO_TYPE, INVALID
|
||||
//template, simple test, nothing fancy
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "useremployeenumber";
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
//replace the User template at the server
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "ayaType", "2203");
|
||||
|
||||
//RIGHTS ISSUE,
|
||||
//currently only bizadminfull can change a picklist template
|
||||
d = new JObject();
|
||||
d.Id = 3;//User
|
||||
//template, simple test, nothing fancy
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "useremployeenumber";
|
||||
dTemplateArray.Add(df);
|
||||
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
//ERROR NO RIGHTS USER
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("CustomerLimited"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
//"{\"error\":{\"code\":\"2004\",\"message\":\"User not authorized for this resource operation (insufficient rights)\"}}"
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
|
||||
//EMPTY TEMPLATE VALIDATION ERROR
|
||||
d = new JObject();
|
||||
d.Id = 3;//User
|
||||
d.Template = "";//<-- ERROR no template
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Template", "2201");
|
||||
|
||||
|
||||
//MALFORMED TEMPLATE JSON ERROR
|
||||
d = new JObject();
|
||||
d.Id = 3;//User type
|
||||
dTemplateArray = new JArray();
|
||||
df = new JObject();
|
||||
df.fld = "useremployeenumber";
|
||||
dTemplateArray.Add(df);
|
||||
string sTemplate = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
||||
d.Template = sTemplate.Substring(2);//<-- ERROR missing first two characters of json template array
|
||||
a = await Util.PostAsync("pick-list/template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
||||
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template is not valid JSON string: Error reading JArray from JsonReader. Current JsonReader item is not an array: String. Path '', line 1, position 5.\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Template", "2203");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test get templates list
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PickListTemplateList()
|
||||
{
|
||||
//RETRIEVE
|
||||
ApiResponse a = await Util.GetAsync("pick-list/template/list", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains at least two records (as we only have two at time of writing this test)
|
||||
var templateList = ((JArray)a.ObjectResponse["data"]);
|
||||
templateList.Count.Should().BeGreaterThan(1);
|
||||
templateList[0]["id"].Value<long>().Should().Be(2);//first one should be a widget
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist fields list for widget template
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task WidgetPickListTemplateFieldList()
|
||||
{
|
||||
//RETRIEVE WIDGET PICKLIST FIELDS
|
||||
ApiResponse a = await Util.GetAsync("pick-list/template/ListFields/2", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains at least two records (as we only have two at time of writing this test)
|
||||
var templateList = ((JArray)a.ObjectResponse["data"]);
|
||||
templateList.Count.Should().BeGreaterThan(4);
|
||||
templateList[0]["fieldKey"].Value<string>().Should().Be("widgetactive");//first one should be a widgetactive field
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist for widget without query
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task FetchWidgetPickListNoQuery()
|
||||
{
|
||||
//RETRIEVE WIDGET PICKLIST no filter
|
||||
ApiResponse a = await Util.GetAsync("pick-list/list?ayaType=2", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains 100 records (current picklist maximum count)
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(100);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist for single predefined value only
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task FetchWidgetPickListPreDefined()
|
||||
{
|
||||
//fetch the SuperUser account which always exists
|
||||
ApiResponse a = await Util.GetAsync("pick-list/list?ayaType=3&preId=1", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
//assert contains 1 record
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(1);
|
||||
pickList[0]["id"].Value<long>().Should().Be(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist for widget with basic autocomplete query only
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task FetchWidgetPickListAutoComplete()
|
||||
{
|
||||
|
||||
//make key widget
|
||||
|
||||
var WidgetNameStart = "FetchWidgetPickListAutoComplete_a1b2c3";
|
||||
long IncludedWidgetId = 0;
|
||||
//CREATE TEST WIDGETS
|
||||
//included widget
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.active = true;
|
||||
w.usertype = 1;
|
||||
w.dollarAmount = 555.55;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE WIDGET PICKLIST with name filter
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=2&query=a1b2c3", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().BeGreaterThan(0);
|
||||
pickList[0]["name"].Value<string>().Should().Contain("_a1b2c3");
|
||||
|
||||
//DELETE WIDGETS
|
||||
a = await Util.DeleteAsync("widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task FetchWidgetPickListTags()
|
||||
{
|
||||
|
||||
//make key widget
|
||||
var WidgetNameStart = "FetchWidgetPickListTags";
|
||||
long IncludedWidgetId = 0;
|
||||
//CREATE TEST WIDGETS
|
||||
//included widget
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.active = true;
|
||||
w.usertype = 1;
|
||||
w.dollarAmount = 555.55;
|
||||
//Tags
|
||||
dynamic InclusiveTagsArray = new JArray();
|
||||
InclusiveTagsArray.Add("plred");
|
||||
InclusiveTagsArray.Add("plblue");
|
||||
w.tags = InclusiveTagsArray;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE WIDGET PICKLIST with name filter
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=2&query=..lblu", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
pickList.Count.Should().Be(1);
|
||||
pickList[0]["id"].Value<long>().Should().Be(IncludedWidgetId);
|
||||
|
||||
//DELETE WIDGETS
|
||||
a = await Util.DeleteAsync("widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// test get picklist for widget with basic autocomplete query only
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task FetchWidgetPickListInactiveActive()
|
||||
{
|
||||
|
||||
//make key widget
|
||||
|
||||
var WidgetNameStart = "FetchWidgetPickListInactiveActive";
|
||||
List<long> ActiveWidgetIdList = new List<long>();
|
||||
List<long> NotActiveWidgetIdList = new List<long>();
|
||||
|
||||
//CREATE 4 TEST WIDGETS
|
||||
//two active and two non active
|
||||
|
||||
//first active widget
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.notes = "blah";
|
||||
w.active = true;
|
||||
w.usertype = 1;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//second active widget
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
|
||||
//first NON active widget
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.active = false;
|
||||
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//second NON active widget
|
||||
w.name = Util.Uniquify(WidgetNameStart);
|
||||
w.active = false;
|
||||
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
|
||||
//CONFIRM BOTH INACTIVE AND ACTIVE
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=2&query=ickListInactiveAct&inactive=true", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
var pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
//assert contains at least two records
|
||||
pickList.Count.Should().BeGreaterThan(1);
|
||||
int nActiveMatches = 0;
|
||||
int nInactiveMatches = 0;
|
||||
foreach (JObject o in pickList)
|
||||
{
|
||||
if (ActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
nActiveMatches++;
|
||||
if (NotActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
nInactiveMatches++;
|
||||
}
|
||||
nActiveMatches.Should().Be(ActiveWidgetIdList.Count);
|
||||
nInactiveMatches.Should().Be(NotActiveWidgetIdList.Count);
|
||||
|
||||
|
||||
//CONFIRM ACTIVE ONLY
|
||||
a = await Util.GetAsync("pick-list/list?ayaType=2&query=ickListInactiveAct", await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
pickList = ((JArray)a.ObjectResponse["data"]);
|
||||
//assert contains at least two records
|
||||
pickList.Count.Should().BeGreaterThan(1);
|
||||
nActiveMatches = 0;
|
||||
nInactiveMatches = 0;
|
||||
foreach (JObject o in pickList)
|
||||
{
|
||||
if (ActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
nActiveMatches++;
|
||||
if (NotActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
nInactiveMatches++;
|
||||
}
|
||||
nActiveMatches.Should().Be(ActiveWidgetIdList.Count);
|
||||
nInactiveMatches.Should().Be(0);
|
||||
|
||||
//DELETE WIDGETS
|
||||
foreach (long l in ActiveWidgetIdList)
|
||||
{
|
||||
a = await Util.DeleteAsync("widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
foreach (long l in NotActiveWidgetIdList)
|
||||
{
|
||||
a = await Util.DeleteAsync("widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Privacy
|
||||
{
|
||||
|
||||
//DEPRECATED, NOT USEFUL
|
||||
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// [Fact]
|
||||
// public async void LogShouldNotContainPrivateData()
|
||||
// {
|
||||
// ApiResponse a = await Util.GetAsync("AyaType", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT"));
|
||||
// ApiTextResponse t = await Util.GetTextResultAsync("log-file/log-ayanova.txt", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT"));
|
||||
// Util.ValidateHTTPStatusCode(t, 200);
|
||||
// t.TextResponse.Should().NotContain("TEST_PRIVACY_USER_ACCOUNT");
|
||||
|
||||
// }
|
||||
|
||||
// //==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Privacy
|
||||
{
|
||||
|
||||
//DEPRECATED, NOT USEFUL
|
||||
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// [Fact]
|
||||
// public async Task LogShouldNotContainPrivateData()
|
||||
// {
|
||||
// ApiResponse a = await Util.GetAsync("AyaType", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT"));
|
||||
// ApiTextResponse t = await Util.GetTextResultAsync("log-file/log-ayanova.txt", await Util.GetTokenAsync("TEST_PRIVACY_USER_ACCOUNT"));
|
||||
// Util.ValidateHTTPStatusCode(t, 200);
|
||||
// t.TextResponse.Should().NotContain("TEST_PRIVACY_USER_ACCOUNT");
|
||||
|
||||
// }
|
||||
|
||||
// //==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
1408
Search/SearchOps.cs
1408
Search/SearchOps.cs
File diff suppressed because it is too large
Load Diff
@@ -1,59 +1,59 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class ServerJob
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TestJobShouldSubmit()
|
||||
{
|
||||
ApiResponse a = await Util.PostAsync("job-operations/test-job", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
//Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 202);
|
||||
//should return something like this:
|
||||
/*
|
||||
{
|
||||
"testJobId": 4
|
||||
}
|
||||
*/
|
||||
|
||||
String jobId = a.ObjectResponse["jobId"].Value<String>();
|
||||
|
||||
//Get a list of operations
|
||||
a = await Util.GetAsync("job-operations", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
|
||||
|
||||
//there should be at least 1
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterOrEqualTo(1);
|
||||
|
||||
//See if our job is in there
|
||||
bool bFound=false;
|
||||
foreach(JToken t in a.ObjectResponse["data"])
|
||||
{
|
||||
if(t["gId"].Value<String>()==jobId)
|
||||
bFound=true;
|
||||
}
|
||||
bFound.Should().BeTrue();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class ServerJob
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestJobShouldSubmit()
|
||||
{
|
||||
ApiResponse a = await Util.PostAsync("job-operations/test-job", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
//Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 202);
|
||||
//should return something like this:
|
||||
/*
|
||||
{
|
||||
"testJobId": 4
|
||||
}
|
||||
*/
|
||||
|
||||
String jobId = a.ObjectResponse["jobId"].Value<String>();
|
||||
|
||||
//Get a list of operations
|
||||
a = await Util.GetAsync("job-operations", await Util.GetTokenAsync("OpsAdminFull"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
|
||||
|
||||
//there should be at least 1
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterOrEqualTo(1);
|
||||
|
||||
//See if our job is in there
|
||||
bool bFound=false;
|
||||
foreach(JToken t in a.ObjectResponse["data"])
|
||||
{
|
||||
if(t["gId"].Value<String>()==jobId)
|
||||
bFound=true;
|
||||
}
|
||||
bFound.Should().BeTrue();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
using Xunit;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class ServerStateTest
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test get state
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerStateShouldReturnOk()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("server-state");
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
|
||||
//NOTE: can't test set because it would break the other tests
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using Xunit;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class ServerStateTest
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test get state
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ServerStateShouldReturnOk()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("server-state");
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
|
||||
//NOTE: can't test set because it would break the other tests
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
330
Tags/TagOps.cs
330
Tags/TagOps.cs
@@ -1,165 +1,165 @@
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class TagOps
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TagListsWork()
|
||||
{
|
||||
|
||||
var TestName = "TagListsWork";
|
||||
var WidgetRunNameStart = Util.Uniquify(TestName);
|
||||
var TagNameStart = Util.Uniquify("crud-tag-test-") + "-";//ensure this run gets it's own unique tags
|
||||
TagNameStart = TagNameStart.Replace(" ", "");
|
||||
|
||||
List<string> InitialTagsList = new List<string>();
|
||||
InitialTagsList.Add(TagNameStart + "red");
|
||||
InitialTagsList.Add(TagNameStart + "orange");
|
||||
InitialTagsList.Add(TagNameStart + "yellow");
|
||||
InitialTagsList.Add(TagNameStart + "green");
|
||||
InitialTagsList.Add(TagNameStart + "blue");
|
||||
InitialTagsList.Add(TagNameStart + "indigo");
|
||||
InitialTagsList.Add(TagNameStart + "violet");
|
||||
|
||||
List<string> UpdateTagsList = new List<string>();
|
||||
//Newly added tags
|
||||
UpdateTagsList.Add(TagNameStart + "crimson");
|
||||
UpdateTagsList.Add(TagNameStart + "amber");
|
||||
UpdateTagsList.Add(TagNameStart + "saffron");
|
||||
UpdateTagsList.Add(TagNameStart + "emerald");
|
||||
UpdateTagsList.Add(TagNameStart + "azure");
|
||||
UpdateTagsList.Add(TagNameStart + "cobalt");
|
||||
UpdateTagsList.Add(TagNameStart + "magenta");
|
||||
|
||||
//maintains these tags
|
||||
UpdateTagsList.Add(TagNameStart + "red");
|
||||
UpdateTagsList.Add(TagNameStart + "blue");
|
||||
|
||||
//Removes these tags by omission
|
||||
//orange, yellow, green, indigo, violet
|
||||
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
w.notes = "blah";
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.usertype = 1;
|
||||
//Tags
|
||||
dynamic InitialTags = new JArray();
|
||||
foreach (string s in InitialTagsList)
|
||||
{
|
||||
InitialTags.Add(s);
|
||||
}
|
||||
w.tags = InitialTags;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long WidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint Concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
w = a.ObjectResponse["data"];
|
||||
|
||||
//validate the repository LIST ROUTE of tags contains the ones above
|
||||
a = await Util.GetAsync($"tag-list/list?query={TagNameStart}", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(7);
|
||||
|
||||
|
||||
//UPDATE Tags
|
||||
dynamic UpdateTags = new JArray();
|
||||
|
||||
//Adds these tags
|
||||
foreach (string s in UpdateTagsList)
|
||||
{
|
||||
UpdateTags.Add(s);
|
||||
}
|
||||
//update Widget and put to server
|
||||
w.concurrency = Concurrency;
|
||||
w.tags = UpdateTags;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
|
||||
//Verify the tags collection remaining
|
||||
a = await Util.GetAsync($"tag-list/list?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(9);
|
||||
|
||||
//Verify the CLOUD LIST AND REF COUNT of tags collection remaining
|
||||
a = await Util.GetAsync($"tag-list/cloudlist?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(9);
|
||||
a.ObjectResponse["data"][0]["refCount"].Value<long>().Should().Be(1);
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + WidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
//Verify the tags collection remaining
|
||||
a = await Util.GetAsync($"tag-list/list?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test bulk tag bad params
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BulkBadParamsShouldFail()
|
||||
{
|
||||
|
||||
dynamic d = new JArray();
|
||||
// d.Add(1);
|
||||
// d.Add(2);
|
||||
// d.Add(3);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("tag-list/bulk-add/33/my new tag", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Test bulk tag
|
||||
// /// </summary>
|
||||
// [Fact]
|
||||
// public async void BulkTagDriver()
|
||||
// {
|
||||
|
||||
// dynamic d = new JArray();
|
||||
// d.Add(1);
|
||||
// d.Add(2);
|
||||
|
||||
|
||||
// ApiResponse a = await Util.PostAsync("tag-list/bulk-add/2/my new tag", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-add-any/2/bulk-add-this-tag
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-remove/2/happy%20new%20tag
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-remove-any/2/red
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-replace/2/bulk-add-this-tag?toTag=bulk-update-this-tag
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-replace-any/2/bulk-update-this-tag?toTag=bulk-replace-this-tag-any
|
||||
// ;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class TagOps
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TagListsWork()
|
||||
{
|
||||
|
||||
var TestName = "TagListsWork";
|
||||
var WidgetRunNameStart = Util.Uniquify(TestName);
|
||||
var TagNameStart = Util.Uniquify("crud-tag-test-") + "-";//ensure this run gets it's own unique tags
|
||||
TagNameStart = TagNameStart.Replace(" ", "");
|
||||
|
||||
List<string> InitialTagsList = new List<string>();
|
||||
InitialTagsList.Add(TagNameStart + "red");
|
||||
InitialTagsList.Add(TagNameStart + "orange");
|
||||
InitialTagsList.Add(TagNameStart + "yellow");
|
||||
InitialTagsList.Add(TagNameStart + "green");
|
||||
InitialTagsList.Add(TagNameStart + "blue");
|
||||
InitialTagsList.Add(TagNameStart + "indigo");
|
||||
InitialTagsList.Add(TagNameStart + "violet");
|
||||
|
||||
List<string> UpdateTagsList = new List<string>();
|
||||
//Newly added tags
|
||||
UpdateTagsList.Add(TagNameStart + "crimson");
|
||||
UpdateTagsList.Add(TagNameStart + "amber");
|
||||
UpdateTagsList.Add(TagNameStart + "saffron");
|
||||
UpdateTagsList.Add(TagNameStart + "emerald");
|
||||
UpdateTagsList.Add(TagNameStart + "azure");
|
||||
UpdateTagsList.Add(TagNameStart + "cobalt");
|
||||
UpdateTagsList.Add(TagNameStart + "magenta");
|
||||
|
||||
//maintains these tags
|
||||
UpdateTagsList.Add(TagNameStart + "red");
|
||||
UpdateTagsList.Add(TagNameStart + "blue");
|
||||
|
||||
//Removes these tags by omission
|
||||
//orange, yellow, green, indigo, violet
|
||||
|
||||
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
w.notes = "blah";
|
||||
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
w.usertype = 1;
|
||||
//Tags
|
||||
dynamic InitialTags = new JArray();
|
||||
foreach (string s in InitialTagsList)
|
||||
{
|
||||
InitialTags.Add(s);
|
||||
}
|
||||
w.tags = InitialTags;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long WidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint Concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
w = a.ObjectResponse["data"];
|
||||
|
||||
//validate the repository LIST ROUTE of tags contains the ones above
|
||||
a = await Util.GetAsync($"tag-list/list?query={TagNameStart}", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(7);
|
||||
|
||||
|
||||
//UPDATE Tags
|
||||
dynamic UpdateTags = new JArray();
|
||||
|
||||
//Adds these tags
|
||||
foreach (string s in UpdateTagsList)
|
||||
{
|
||||
UpdateTags.Add(s);
|
||||
}
|
||||
//update Widget and put to server
|
||||
w.concurrency = Concurrency;
|
||||
w.tags = UpdateTags;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
|
||||
//Verify the tags collection remaining
|
||||
a = await Util.GetAsync($"tag-list/list?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(9);
|
||||
|
||||
//Verify the CLOUD LIST AND REF COUNT of tags collection remaining
|
||||
a = await Util.GetAsync($"tag-list/cloudlist?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(9);
|
||||
a.ObjectResponse["data"][0]["refCount"].Value<long>().Should().Be(1);
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + WidgetId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
//Verify the tags collection remaining
|
||||
a = await Util.GetAsync($"tag-list/list?query=" + TagNameStart, await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test bulk tag bad params
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BulkBadParamsShouldFail()
|
||||
{
|
||||
|
||||
dynamic d = new JArray();
|
||||
// d.Add(1);
|
||||
// d.Add(2);
|
||||
// d.Add(3);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("tag-list/bulk-add/33/my new tag", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Test bulk tag
|
||||
// /// </summary>
|
||||
// [Fact]
|
||||
// public async Task BulkTagDriver()
|
||||
// {
|
||||
|
||||
// dynamic d = new JArray();
|
||||
// d.Add(1);
|
||||
// d.Add(2);
|
||||
|
||||
|
||||
// ApiResponse a = await Util.PostAsync("tag-list/bulk-add/2/my new tag", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-add-any/2/bulk-add-this-tag
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-remove/2/happy%20new%20tag
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-remove-any/2/red
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-replace/2/bulk-add-this-tag?toTag=bulk-update-this-tag
|
||||
// //http://localhost:7575/api/v8/tag-list/bulk-replace-any/2/bulk-update-this-tag?toTag=bulk-replace-this-tag-any
|
||||
// ;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class RequestedLocaleKeys
|
||||
{
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void RequestedLocaleKeysWorks()
|
||||
{
|
||||
//First determine if there is a requested key route because it's debug build dependent
|
||||
//And doesn't exists if server was not debug built
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("CustomerLimited"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
BuildMode.Should().BeOneOf((new string[] { "DEBUG", "RELEASE" }));
|
||||
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
|
||||
//Make a "list" of keys to fetch the values for
|
||||
List<string> keys = new List<string>();
|
||||
keys.AddRange(new string[] { "HelpLicense", "CustomerName" });
|
||||
dynamic d = new JObject();
|
||||
|
||||
d = JToken.FromObject(keys);
|
||||
|
||||
//Fetch the values to force RAVEN to track at least these two
|
||||
a = await Util.PostAsync("translation/subset", await Util.GetTokenAsync("CustomerLimited"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(2);
|
||||
|
||||
//Now ensure there are at least two keys in the fetched keys array
|
||||
a = await Util.GetAsync("translation/TranslationKeyCoverage", await Util.GetTokenAsync("CustomerLimited"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
var RequestedKeyCount = a.ObjectResponse["data"]["requestedKeyCount"].Value<int>();
|
||||
RequestedKeyCount.Should().BeGreaterOrEqualTo(2);
|
||||
var NotRequestedKeyCount = a.ObjectResponse["data"]["notRequestedKeyCount"].Value<int>();
|
||||
NotRequestedKeyCount.Should().BeGreaterThan(1);//For now at least, once we have this dialed in it will be zero ultimately
|
||||
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["data"]["requestedKeys"]).Count.Should().Be(RequestedKeyCount);
|
||||
((JArray)a.ObjectResponse["data"]["notRequestedKeys"]).Count.Should().Be(NotRequestedKeyCount);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class RequestedLocaleKeys
|
||||
{
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task RequestedLocaleKeysWorks()
|
||||
{
|
||||
//First determine if there is a requested key route because it's debug build dependent
|
||||
//And doesn't exists if server was not debug built
|
||||
ApiResponse a = await Util.GetAsync("build-mode", await Util.GetTokenAsync("CustomerLimited"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
||||
BuildMode.Should().BeOneOf((new string[] { "DEBUG", "RELEASE" }));
|
||||
|
||||
if (BuildMode == "DEBUG")
|
||||
{
|
||||
|
||||
//Make a "list" of keys to fetch the values for
|
||||
List<string> keys = new List<string>();
|
||||
keys.AddRange(new string[] { "HelpLicense", "CustomerName" });
|
||||
dynamic d = new JObject();
|
||||
|
||||
d = JToken.FromObject(keys);
|
||||
|
||||
//Fetch the values to force RAVEN to track at least these two
|
||||
a = await Util.PostAsync("translation/subset", await Util.GetTokenAsync("CustomerLimited"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(2);
|
||||
|
||||
//Now ensure there are at least two keys in the fetched keys array
|
||||
a = await Util.GetAsync("translation/TranslationKeyCoverage", await Util.GetTokenAsync("CustomerLimited"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
var RequestedKeyCount = a.ObjectResponse["data"]["requestedKeyCount"].Value<int>();
|
||||
RequestedKeyCount.Should().BeGreaterOrEqualTo(2);
|
||||
var NotRequestedKeyCount = a.ObjectResponse["data"]["notRequestedKeyCount"].Value<int>();
|
||||
NotRequestedKeyCount.Should().BeGreaterThan(1);//For now at least, once we have this dialed in it will be zero ultimately
|
||||
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["data"]["requestedKeys"]).Count.Should().Be(RequestedKeyCount);
|
||||
((JArray)a.ObjectResponse["data"]["notRequestedKeys"]).Count.Should().Be(NotRequestedKeyCount);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,188 +1,188 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Translation
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
ImportTranslation(ct, ResourceFolderPath, "en"); - id 1
|
||||
ImportTranslation(ct, ResourceFolderPath, "es"); - id 2
|
||||
ImportTranslation(ct, ResourceFolderPath, "fr"); - id 3
|
||||
ImportTranslation(ct, ResourceFolderPath, "de"); - id 4
|
||||
*/
|
||||
|
||||
[Fact]
|
||||
public async void TranslationListWorks()
|
||||
{
|
||||
//Get all
|
||||
ApiResponse a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("CustomerLimited"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be at least 4 of them as there are 4 stock translations
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(3);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void GetFullTranslationWorks()
|
||||
{
|
||||
//Get all
|
||||
ApiResponse a = await Util.GetAsync("translation/1", await Util.GetTokenAsync("CustomerLimited"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["data"]["translationItems"]).Count.Should().BeGreaterThan(0);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void GetSubsetWorks()
|
||||
{
|
||||
|
||||
|
||||
List<string> keys = new List<string>();
|
||||
keys.AddRange(new string[] { "AddressType", "CustomerName", "RateName", "WorkOrder" });
|
||||
dynamic d = new JObject();
|
||||
|
||||
d = JToken.FromObject(keys);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("translation/subset", await Util.GetTokenAsync("CustomerLimited"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(4);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void DuplicateUpdateAndDeleteWorks()
|
||||
{
|
||||
|
||||
//DUPLICATE
|
||||
dynamic d = new JObject();
|
||||
d.id = 1;
|
||||
d.name = Util.Uniquify("INTEGRATION-TEST-LOCALE");
|
||||
|
||||
ApiResponse a = await Util.PostAsync("translation/Duplicate", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 201);
|
||||
//verify the object returned is as expected
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().Be(d.name.ToString());
|
||||
a.ObjectResponse["data"]["stock"].Value<bool>().Should().Be(false);
|
||||
a.ObjectResponse["data"]["id"].Value<long>().Should().BeGreaterThan(4);
|
||||
a.ObjectResponse["data"]["concurrency"].Value<uint>().Should().BeGreaterThan(0);
|
||||
((JArray)a.ObjectResponse["data"]["translationItems"]).Count.Should().BeGreaterThan(0);
|
||||
|
||||
long NewId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//UPDATE
|
||||
//Update translation name
|
||||
|
||||
dynamic d2 = new JObject();
|
||||
d2.id = NewId;
|
||||
d2.newText = Util.Uniquify("INTEGRATION-TEST-LOCALE NAME UPDATE");
|
||||
d2.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("translation/UpdateTranslationName", await Util.GetTokenAsync("BizAdminFull"), d2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("translation/" + NewId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(d2.newText.ToString());
|
||||
//uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//Update translation key
|
||||
var FirstTranslationKey = ((JArray)a.ObjectResponse["data"]["translationItems"])[0];
|
||||
long UpdatedTranslationKeyId = FirstTranslationKey["id"].Value<long>();
|
||||
d2.id = UpdatedTranslationKeyId;
|
||||
d2.newText = Util.Uniquify("INTEGRATION-TEST-LOCALEITEM DISPLAY UPDATE");
|
||||
d2.concurrency = FirstTranslationKey["concurrency"].Value<uint>();
|
||||
|
||||
string UpdatedTranslationKey = FirstTranslationKey["key"].Value<string>();
|
||||
|
||||
PUTTestResponse = await Util.PutAsync("translation/UpdateTranslationItemDisplayText", await Util.GetTokenAsync("BizAdminFull"), d2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//create user that is set to new translation so can use getSubset
|
||||
var Login = Util.Uniquify("LOGIN");
|
||||
var Password = Util.Uniquify("PASSWORD");
|
||||
dynamic DUSER = new JObject();
|
||||
DUSER.name = Util.Uniquify("TranslationUpdateSubsetTestUser");
|
||||
|
||||
DUSER.active = true;
|
||||
DUSER.login = Login;
|
||||
DUSER.password = Password;
|
||||
DUSER.roles = 0;//norole (any role can get a subset of translation keys)
|
||||
// DUSER.translationId = NewId;
|
||||
DUSER.userType = 3;//non scheduleable
|
||||
//Required by form custom rules
|
||||
DUSER.notes = "notes";
|
||||
DUSER.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), DUSER.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long DUSERID = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE companion USEROPTIONS object
|
||||
ApiResponse R = await Util.GetAsync("user-option/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be("#000000");
|
||||
uint concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//UPDATE
|
||||
|
||||
//PUT
|
||||
dynamic D2 = new JObject();
|
||||
D2.translationId = NewId;
|
||||
|
||||
D2.concurrency = concurrency;
|
||||
PUTTestResponse = await Util.PutAsync("user-option/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//VALIDATE
|
||||
R = await Util.GetAsync("user-option/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
|
||||
|
||||
|
||||
List<string> keys = new List<string>();
|
||||
keys.AddRange(new string[] { UpdatedTranslationKey });
|
||||
dynamic d3 = new JObject();
|
||||
|
||||
d3 = JToken.FromObject(keys);
|
||||
|
||||
checkPUTWorked = await Util.PostAsync("translation/subset", await Util.GetTokenAsync(Login, Password), d3.ToString());
|
||||
Util.ValidateDataReturnResponseOk(checkPUTWorked);
|
||||
Util.ValidateHTTPStatusCode(checkPUTWorked, 200);
|
||||
((JArray)checkPUTWorked.ObjectResponse["data"]).Count.Should().Be(1);
|
||||
var FirstTranslationKeyUpdated = ((JArray)checkPUTWorked.ObjectResponse["data"])[0];
|
||||
|
||||
FirstTranslationKeyUpdated["value"].Value<string>().Should().Be(d2.newText.ToString());
|
||||
|
||||
//DELETE TEMPORARY USER SO CAN DELETE LOCALE
|
||||
a = await Util.DeleteAsync("User/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
//DELETE TEMP LOCALE
|
||||
a = await Util.DeleteAsync("translation/" + NewId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class Translation
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
ImportTranslation(ct, ResourceFolderPath, "en"); - id 1
|
||||
ImportTranslation(ct, ResourceFolderPath, "es"); - id 2
|
||||
ImportTranslation(ct, ResourceFolderPath, "fr"); - id 3
|
||||
ImportTranslation(ct, ResourceFolderPath, "de"); - id 4
|
||||
*/
|
||||
|
||||
[Fact]
|
||||
public async Task TranslationListWorks()
|
||||
{
|
||||
//Get all
|
||||
ApiResponse a = await Util.GetAsync("translation/list", await Util.GetTokenAsync("CustomerLimited"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be at least 4 of them as there are 4 stock translations
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(3);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task GetFullTranslationWorks()
|
||||
{
|
||||
//Get all
|
||||
ApiResponse a = await Util.GetAsync("translation/1", await Util.GetTokenAsync("CustomerLimited"));//lowest level test user because there are no limits on this route except to be authenticated
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["data"]["translationItems"]).Count.Should().BeGreaterThan(0);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task GetSubsetWorks()
|
||||
{
|
||||
|
||||
|
||||
List<string> keys = new List<string>();
|
||||
keys.AddRange(new string[] { "AddressType", "CustomerName", "RateName", "WorkOrder" });
|
||||
dynamic d = new JObject();
|
||||
|
||||
d = JToken.FromObject(keys);
|
||||
|
||||
ApiResponse a = await Util.PostAsync("translation/subset", await Util.GetTokenAsync("CustomerLimited"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 200);
|
||||
//there should be dozens of keys but at times there might only be a few during development so at least verify there is more than one
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(4);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task DuplicateUpdateAndDeleteWorks()
|
||||
{
|
||||
|
||||
//DUPLICATE
|
||||
dynamic d = new JObject();
|
||||
d.id = 1;
|
||||
d.name = Util.Uniquify("INTEGRATION-TEST-LOCALE");
|
||||
|
||||
ApiResponse a = await Util.PostAsync("translation/Duplicate", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
Util.ValidateHTTPStatusCode(a, 201);
|
||||
//verify the object returned is as expected
|
||||
a.ObjectResponse["data"]["name"].Value<string>().Should().Be(d.name.ToString());
|
||||
a.ObjectResponse["data"]["stock"].Value<bool>().Should().Be(false);
|
||||
a.ObjectResponse["data"]["id"].Value<long>().Should().BeGreaterThan(4);
|
||||
a.ObjectResponse["data"]["concurrency"].Value<uint>().Should().BeGreaterThan(0);
|
||||
((JArray)a.ObjectResponse["data"]["translationItems"]).Count.Should().BeGreaterThan(0);
|
||||
|
||||
long NewId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//UPDATE
|
||||
//Update translation name
|
||||
|
||||
dynamic d2 = new JObject();
|
||||
d2.id = NewId;
|
||||
d2.newText = Util.Uniquify("INTEGRATION-TEST-LOCALE NAME UPDATE");
|
||||
d2.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("translation/UpdateTranslationName", await Util.GetTokenAsync("BizAdminFull"), d2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("translation/" + NewId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(d2.newText.ToString());
|
||||
//uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//Update translation key
|
||||
var FirstTranslationKey = ((JArray)a.ObjectResponse["data"]["translationItems"])[0];
|
||||
long UpdatedTranslationKeyId = FirstTranslationKey["id"].Value<long>();
|
||||
d2.id = UpdatedTranslationKeyId;
|
||||
d2.newText = Util.Uniquify("INTEGRATION-TEST-LOCALEITEM DISPLAY UPDATE");
|
||||
d2.concurrency = FirstTranslationKey["concurrency"].Value<uint>();
|
||||
|
||||
string UpdatedTranslationKey = FirstTranslationKey["key"].Value<string>();
|
||||
|
||||
PUTTestResponse = await Util.PutAsync("translation/UpdateTranslationItemDisplayText", await Util.GetTokenAsync("BizAdminFull"), d2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//create user that is set to new translation so can use getSubset
|
||||
var Login = Util.Uniquify("LOGIN");
|
||||
var Password = Util.Uniquify("PASSWORD");
|
||||
dynamic DUSER = new JObject();
|
||||
DUSER.name = Util.Uniquify("TranslationUpdateSubsetTestUser");
|
||||
|
||||
DUSER.active = true;
|
||||
DUSER.login = Login;
|
||||
DUSER.password = Password;
|
||||
DUSER.roles = 0;//norole (any role can get a subset of translation keys)
|
||||
// DUSER.translationId = NewId;
|
||||
DUSER.userType = 3;//non scheduleable
|
||||
//Required by form custom rules
|
||||
DUSER.notes = "notes";
|
||||
DUSER.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), DUSER.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long DUSERID = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE companion USEROPTIONS object
|
||||
ApiResponse R = await Util.GetAsync("user-option/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be("#000000");
|
||||
uint concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//UPDATE
|
||||
|
||||
//PUT
|
||||
dynamic D2 = new JObject();
|
||||
D2.translationId = NewId;
|
||||
|
||||
D2.concurrency = concurrency;
|
||||
PUTTestResponse = await Util.PutAsync("user-option/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//VALIDATE
|
||||
R = await Util.GetAsync("user-option/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
|
||||
|
||||
|
||||
List<string> keys = new List<string>();
|
||||
keys.AddRange(new string[] { UpdatedTranslationKey });
|
||||
dynamic d3 = new JObject();
|
||||
|
||||
d3 = JToken.FromObject(keys);
|
||||
|
||||
checkPUTWorked = await Util.PostAsync("translation/subset", await Util.GetTokenAsync(Login, Password), d3.ToString());
|
||||
Util.ValidateDataReturnResponseOk(checkPUTWorked);
|
||||
Util.ValidateHTTPStatusCode(checkPUTWorked, 200);
|
||||
((JArray)checkPUTWorked.ObjectResponse["data"]).Count.Should().Be(1);
|
||||
var FirstTranslationKeyUpdated = ((JArray)checkPUTWorked.ObjectResponse["data"])[0];
|
||||
|
||||
FirstTranslationKeyUpdated["value"].Value<string>().Should().Be(d2.newText.ToString());
|
||||
|
||||
//DELETE TEMPORARY USER SO CAN DELETE LOCALE
|
||||
a = await Util.DeleteAsync("User/" + DUSERID.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
//DELETE TEMP LOCALE
|
||||
a = await Util.DeleteAsync("translation/" + NewId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
526
User/UserCrud.cs
526
User/UserCrud.cs
@@ -1,263 +1,263 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a User
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void CRUD()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
dynamic D1 = new JObject();
|
||||
D1.name = Util.Uniquify("First Test User");
|
||||
|
||||
D1.active = true;
|
||||
D1.login = Util.Uniquify("LOGIN");
|
||||
D1.password = Util.Uniquify("PASSWORD");
|
||||
D1.roles = 0;//norole
|
||||
|
||||
D1.userType = 3;//non scheduleable
|
||||
|
||||
//Required by form custom rules
|
||||
D1.notes = "notes";
|
||||
D1.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse R1 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R1);
|
||||
long d1Id = R1.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
dynamic D2 = new JObject();
|
||||
D2.name = Util.Uniquify("Second Test User");
|
||||
//Required by form custom rules
|
||||
D2.notes = "notes";
|
||||
D2.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
D2.active = true;
|
||||
D2.login = Util.Uniquify("LOGIN");
|
||||
D2.password = Util.Uniquify("PASSWORD");
|
||||
D2.roles = 0;//norole
|
||||
|
||||
D2.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse R2 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R2);
|
||||
long d2Id = R2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse R3 = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R3);
|
||||
R3.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
//update w2id
|
||||
D2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User");
|
||||
D2.concurrency = R2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
D2.id=d2Id;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("User" , await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void UserWithActivityShouldNotBeDeleteable()
|
||||
{
|
||||
ApiResponse a = await Util.DeleteAsync("User/1", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
a.ObjectResponse["error"]["details"][0]["message"].Value<string>().Should().Contain("LT:ErrorDBForeignKeyViolation");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse R = await Util.GetAsync("User/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse R = await Util.GetAsync("User/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(R, "id");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PutConcurrencyViolationShouldFail()
|
||||
{
|
||||
//CREATE
|
||||
dynamic D = new JObject();
|
||||
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
|
||||
D.notes = "notes";
|
||||
D.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
D.active = true;
|
||||
D.login = Util.Uniquify("LOGIN");
|
||||
D.password = Util.Uniquify("PASSWORD");
|
||||
D.roles = 0;//norole
|
||||
|
||||
D.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
long D1Id = R.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
D.concurrency = OriginalConcurrencyToken - 1;//bad token
|
||||
D.id=D1Id;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PutPasswordShouldWork()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("PutPasswordShouldWork");
|
||||
|
||||
d.active = true;
|
||||
d.login = Util.Uniquify("LOGIN");
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
|
||||
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("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long UserId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//Test can login
|
||||
dynamic DCreds = new JObject();
|
||||
DCreds.password = d.password;
|
||||
DCreds.login = d.login;
|
||||
a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//GET user (login changed concurrency token above)
|
||||
a = await Util.GetAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
d = a.ObjectResponse["data"];
|
||||
|
||||
|
||||
//PUT
|
||||
var NewPassword = "NEW_PASSWORD";
|
||||
d.password = NewPassword;
|
||||
d.login=DCreds.login;
|
||||
a = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//Test can login with new creds
|
||||
//dynamic DCreds = new JObject();
|
||||
DCreds.password = NewPassword;
|
||||
// DCreds.login = d.login;
|
||||
a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void NonUniqueLoginShouldFail()
|
||||
{
|
||||
var UniqueLogin = Util.Uniquify("NonUniqueLoginShouldFail");
|
||||
//CREATE FIRST USER
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("NonUniqueLoginShouldFail");
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
d.active = false;
|
||||
d.login = UniqueLogin;
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
|
||||
|
||||
//Attempt create second with same login
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("2NonUniqueLoginShouldFail");
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
d.active = false;
|
||||
d.login = UniqueLogin;
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Login", "2206");
|
||||
/*
|
||||
"{\"error\":{\"code\":\"2200\",\"details\":[{\"target\":\"Login\",\"error\":\"2206\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a User
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task CRUD()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
dynamic D1 = new JObject();
|
||||
D1.name = Util.Uniquify("First Test User");
|
||||
|
||||
D1.active = true;
|
||||
D1.login = Util.Uniquify("LOGIN");
|
||||
D1.password = Util.Uniquify("PASSWORD");
|
||||
D1.roles = 0;//norole
|
||||
|
||||
D1.userType = 3;//non scheduleable
|
||||
|
||||
//Required by form custom rules
|
||||
D1.notes = "notes";
|
||||
D1.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse R1 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R1);
|
||||
long d1Id = R1.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
dynamic D2 = new JObject();
|
||||
D2.name = Util.Uniquify("Second Test User");
|
||||
//Required by form custom rules
|
||||
D2.notes = "notes";
|
||||
D2.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
D2.active = true;
|
||||
D2.login = Util.Uniquify("LOGIN");
|
||||
D2.password = Util.Uniquify("PASSWORD");
|
||||
D2.roles = 0;//norole
|
||||
|
||||
D2.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse R2 = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R2);
|
||||
long d2Id = R2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse R3 = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R3);
|
||||
R3.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
//update w2id
|
||||
D2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User");
|
||||
D2.concurrency = R2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
D2.id=d2Id;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("User" , await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(D2.name.ToString());
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task UserWithActivityShouldNotBeDeleteable()
|
||||
{
|
||||
ApiResponse a = await Util.DeleteAsync("User/1", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
a.ObjectResponse["error"]["details"][0]["message"].Value<string>().Should().Contain("LT:ErrorDBForeignKeyViolation");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse R = await Util.GetAsync("User/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse R = await Util.GetAsync("User/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(R, "id");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PutConcurrencyViolationShouldFail()
|
||||
{
|
||||
//CREATE
|
||||
dynamic D = new JObject();
|
||||
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
|
||||
D.notes = "notes";
|
||||
D.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
D.active = true;
|
||||
D.login = Util.Uniquify("LOGIN");
|
||||
D.password = Util.Uniquify("PASSWORD");
|
||||
D.roles = 0;//norole
|
||||
|
||||
D.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
long D1Id = R.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
D.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
D.concurrency = OriginalConcurrencyToken - 1;//bad token
|
||||
D.id=D1Id;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PutPasswordShouldWork()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("PutPasswordShouldWork");
|
||||
|
||||
d.active = true;
|
||||
d.login = Util.Uniquify("LOGIN");
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
|
||||
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("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
long UserId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//Test can login
|
||||
dynamic DCreds = new JObject();
|
||||
DCreds.password = d.password;
|
||||
DCreds.login = d.login;
|
||||
a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//GET user (login changed concurrency token above)
|
||||
a = await Util.GetAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
d = a.ObjectResponse["data"];
|
||||
|
||||
|
||||
//PUT
|
||||
var NewPassword = "NEW_PASSWORD";
|
||||
d.password = NewPassword;
|
||||
d.login=DCreds.login;
|
||||
a = await Util.PutAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//Test can login with new creds
|
||||
//dynamic DCreds = new JObject();
|
||||
DCreds.password = NewPassword;
|
||||
// DCreds.login = d.login;
|
||||
a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task NonUniqueLoginShouldFail()
|
||||
{
|
||||
var UniqueLogin = Util.Uniquify("NonUniqueLoginShouldFail");
|
||||
//CREATE FIRST USER
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("NonUniqueLoginShouldFail");
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
d.active = false;
|
||||
d.login = UniqueLogin;
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
|
||||
ApiResponse a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
|
||||
|
||||
//Attempt create second with same login
|
||||
d = new JObject();
|
||||
d.name = Util.Uniquify("2NonUniqueLoginShouldFail");
|
||||
d.notes = "notes";
|
||||
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
d.active = false;
|
||||
d.login = UniqueLogin;
|
||||
d.password = Util.Uniquify("PASSWORD");
|
||||
d.roles = 0;//norole
|
||||
d.userType = 3;//non scheduleable
|
||||
|
||||
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString());
|
||||
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Login", "2206");
|
||||
/*
|
||||
"{\"error\":{\"code\":\"2200\",\"details\":[{\"target\":\"Login\",\"error\":\"2206\"}],\"message\":\"Object did not pass validation\"}}"
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserInactive
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Inactive user should not be able to login
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void InactiveUserCantLogin()
|
||||
{
|
||||
dynamic DCreds = new JObject();
|
||||
DCreds.password = DCreds.login = "TEST_INACTIVE";
|
||||
ApiResponse a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateErrorCodeResponse(a,2003, 401);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserInactive
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Inactive user should not be able to login
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task InactiveUserCantLogin()
|
||||
{
|
||||
dynamic DCreds = new JObject();
|
||||
DCreds.password = DCreds.login = "TEST_INACTIVE";
|
||||
ApiResponse a = await Util.PostAsync("auth", null, DCreds.ToString());
|
||||
Util.ValidateErrorCodeResponse(a,2003, 401);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,122 +1,122 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserOptions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a UserOptions object
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void CRUD()
|
||||
{
|
||||
|
||||
//CREATE a user
|
||||
dynamic D1 = new JObject();
|
||||
D1.name = Util.Uniquify("Test UserOptions User");
|
||||
|
||||
D1.active = true;
|
||||
D1.login = Util.Uniquify("LOGIN");
|
||||
D1.password = Util.Uniquify("PASSWORD");
|
||||
D1.roles = 0;//norole
|
||||
D1.userType = 3;//non scheduleable
|
||||
D1.notes = "notes";
|
||||
D1.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
long UserId = R.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//Now there should be a user options available for this user
|
||||
|
||||
//RETRIEVE companion USEROPTIONS object
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be("#000000");
|
||||
uint concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//UPDATE
|
||||
|
||||
//PUT
|
||||
dynamic D2 = new JObject();
|
||||
D2.translationId = 1;
|
||||
D2.emailAddress = "testuseroptions@helloayanova.com";
|
||||
D2.languageOverride = "de-DE";
|
||||
D2.timeZoneOverride = "Europe/Berlin";
|
||||
D2.currencyName = "EUR";
|
||||
D2.hour12 = false;
|
||||
D2.uiColor = "#ffaaff";
|
||||
D2.concurrency = concurrency;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//VALIDATE
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
/*
|
||||
"{\"data\":{\"id\":44,\"concurrency\":7144348,\"emailAddress\":null,\"uiColor\":0,\"languageOverride\":null,\"timeZoneOverride\":null,\"currencyName\":\"USD\",\"hour12\":true,\"userId\":44}}"
|
||||
*/
|
||||
R.ObjectResponse["data"]["emailAddress"].Value<string>().Should().Be(D2.emailAddress.ToString());
|
||||
R.ObjectResponse["data"]["languageOverride"].Value<string>().Should().Be(D2.languageOverride.ToString());
|
||||
R.ObjectResponse["data"]["timeZoneOverride"].Value<string>().Should().Be(D2.timeZoneOverride.ToString());
|
||||
R.ObjectResponse["data"]["currencyName"].Value<string>().Should().Be(D2.currencyName.ToString());
|
||||
R.ObjectResponse["data"]["hour12"].Value<bool>().Should().Be((bool)D2.hour12);
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be(D2.uiColor.ToString());
|
||||
R.ObjectResponse["data"]["translationId"].Value<long>().Should().Be((long)D2.translationId);
|
||||
concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//DELETE USER
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
//CHECK DELETE USER REMOVED USEROPTIONS
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse R = await Util.GetAsync("user-option/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse R = await Util.GetAsync("user-option/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(R, "id");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class UserOptions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a UserOptions object
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task CRUD()
|
||||
{
|
||||
|
||||
//CREATE a user
|
||||
dynamic D1 = new JObject();
|
||||
D1.name = Util.Uniquify("Test UserOptions User");
|
||||
|
||||
D1.active = true;
|
||||
D1.login = Util.Uniquify("LOGIN");
|
||||
D1.password = Util.Uniquify("PASSWORD");
|
||||
D1.roles = 0;//norole
|
||||
D1.userType = 3;//non scheduleable
|
||||
D1.notes = "notes";
|
||||
D1.customFields = Util.UserRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse R = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), D1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
long UserId = R.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//Now there should be a user options available for this user
|
||||
|
||||
//RETRIEVE companion USEROPTIONS object
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be("#000000");
|
||||
uint concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//UPDATE
|
||||
|
||||
//PUT
|
||||
dynamic D2 = new JObject();
|
||||
D2.translationId = 1;
|
||||
D2.emailAddress = "testuseroptions@helloayanova.com";
|
||||
D2.languageOverride = "de-DE";
|
||||
D2.timeZoneOverride = "Europe/Berlin";
|
||||
D2.currencyName = "EUR";
|
||||
D2.hour12 = false;
|
||||
D2.uiColor = "#ffaaff";
|
||||
D2.concurrency = concurrency;
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"), D2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//VALIDATE
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(R);
|
||||
//ensure the default value is set
|
||||
/*
|
||||
"{\"data\":{\"id\":44,\"concurrency\":7144348,\"emailAddress\":null,\"uiColor\":0,\"languageOverride\":null,\"timeZoneOverride\":null,\"currencyName\":\"USD\",\"hour12\":true,\"userId\":44}}"
|
||||
*/
|
||||
R.ObjectResponse["data"]["emailAddress"].Value<string>().Should().Be(D2.emailAddress.ToString());
|
||||
R.ObjectResponse["data"]["languageOverride"].Value<string>().Should().Be(D2.languageOverride.ToString());
|
||||
R.ObjectResponse["data"]["timeZoneOverride"].Value<string>().Should().Be(D2.timeZoneOverride.ToString());
|
||||
R.ObjectResponse["data"]["currencyName"].Value<string>().Should().Be(D2.currencyName.ToString());
|
||||
R.ObjectResponse["data"]["hour12"].Value<bool>().Should().Be((bool)D2.hour12);
|
||||
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be(D2.uiColor.ToString());
|
||||
R.ObjectResponse["data"]["translationId"].Value<long>().Should().Be((long)D2.translationId);
|
||||
concurrency = R.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
|
||||
//DELETE USER
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
//CHECK DELETE USER REMOVED USEROPTIONS
|
||||
R = await Util.GetAsync("user-option/" + UserId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse R = await Util.GetAsync("user-option/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(R);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse R = await Util.GetAsync("user-option/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(R, "id");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,199 +1,199 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class WidgetCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a widget
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void CRUD()
|
||||
{
|
||||
/*
|
||||
{
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
"dollarAmount": 0,
|
||||
"active": true,
|
||||
"roles": 0
|
||||
}
|
||||
*/
|
||||
//CREATE
|
||||
dynamic w1 = new JObject();
|
||||
w1.name = Util.Uniquify("First Test WIDGET");
|
||||
w1.dollarAmount = 1.11m;
|
||||
w1.active = true;
|
||||
w1.usertype = 1;
|
||||
w1.notes = "The quick brown fox jumped over the six lazy dogs!";
|
||||
w1.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
//Tags
|
||||
dynamic dTagsArray = new JArray();
|
||||
dTagsArray.Add("Red Tag");
|
||||
dTagsArray.Add("ORANGE IS THE NEW BLACK");
|
||||
dTagsArray.Add("yellow");
|
||||
dTagsArray.Add("green");
|
||||
dTagsArray.Add("blue");
|
||||
dTagsArray.Add("indigo");
|
||||
dTagsArray.Add("VIOLET Tag");
|
||||
w1.tags = dTagsArray;
|
||||
|
||||
ApiResponse r1 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r1);
|
||||
long w1Id = r1.ObjectResponse["data"]["id"].Value<long>();
|
||||
((long)r1.ObjectResponse["data"]["serial"]).Should().NotBe(0);
|
||||
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("Second Test WIDGET");
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.usertype = 1;
|
||||
w2.notes = "What is the frequency Kenneth?";
|
||||
w2.tags = dTagsArray;
|
||||
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(r3);
|
||||
r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
r3.ObjectResponse["data"]["notes"].Value<string>().Should().Be(w2.notes.ToString());
|
||||
var returnedTags = ((JArray)r3.ObjectResponse["data"]["tags"]);
|
||||
returnedTags.Count.Should().Be(7);
|
||||
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
//update w2id
|
||||
w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET");
|
||||
w2.id = w2Id;
|
||||
w2.serial = 123456L;
|
||||
w2.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
checkPUTWorked.ObjectResponse["data"]["serial"].Value<long>().Should().Be(123456L);
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse a = await Util.GetAsync("widget/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("widget/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(a, "id");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test server exception
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerExceptionShouldErrorPropertly()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("widget/exception", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test server alt exception
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerAltExceptionShouldErrorPropertly()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("widget/altexception", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void PutConcurrencyViolationShouldFail()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.usertype = 1;
|
||||
w2.notes = "blah";
|
||||
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
uint OriginalConcurrencyToken = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
w2 = r2.ObjectResponse["data"];
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
w2.concurrency = OriginalConcurrencyToken - 1;//bad token
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget/", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
public class WidgetCrud
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a widget
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task CRUD()
|
||||
{
|
||||
/*
|
||||
{
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
"dollarAmount": 0,
|
||||
"active": true,
|
||||
"roles": 0
|
||||
}
|
||||
*/
|
||||
//CREATE
|
||||
dynamic w1 = new JObject();
|
||||
w1.name = Util.Uniquify("First Test WIDGET");
|
||||
w1.dollarAmount = 1.11m;
|
||||
w1.active = true;
|
||||
w1.usertype = 1;
|
||||
w1.notes = "The quick brown fox jumped over the six lazy dogs!";
|
||||
w1.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
//Tags
|
||||
dynamic dTagsArray = new JArray();
|
||||
dTagsArray.Add("Red Tag");
|
||||
dTagsArray.Add("ORANGE IS THE NEW BLACK");
|
||||
dTagsArray.Add("yellow");
|
||||
dTagsArray.Add("green");
|
||||
dTagsArray.Add("blue");
|
||||
dTagsArray.Add("indigo");
|
||||
dTagsArray.Add("VIOLET Tag");
|
||||
w1.tags = dTagsArray;
|
||||
|
||||
ApiResponse r1 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r1);
|
||||
long w1Id = r1.ObjectResponse["data"]["id"].Value<long>();
|
||||
((long)r1.ObjectResponse["data"]["serial"]).Should().NotBe(0);
|
||||
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("Second Test WIDGET");
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.usertype = 1;
|
||||
w2.notes = "What is the frequency Kenneth?";
|
||||
w2.tags = dTagsArray;
|
||||
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["data"]["id"].Value<long>();
|
||||
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse r3 = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(r3);
|
||||
r3.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
r3.ObjectResponse["data"]["notes"].Value<string>().Should().Be(w2.notes.ToString());
|
||||
var returnedTags = ((JArray)r3.ObjectResponse["data"]["tags"]);
|
||||
returnedTags.Count.Should().Be(7);
|
||||
|
||||
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
//update w2id
|
||||
w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET");
|
||||
w2.id = w2Id;
|
||||
w2.serial = 123456L;
|
||||
w2.concurrency = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["data"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
checkPUTWorked.ObjectResponse["data"]["serial"].Value<long>().Should().Be(123456L);
|
||||
uint concurrency = PUTTestResponse.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("widget/" + w2Id.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not found
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetNonExistentItemShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse a = await Util.GetAsync("widget/999999", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test bad modelstate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetBadModelStateShouldError()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("widget/2q2", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(a, "id");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test server exception
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ServerExceptionShouldErrorPropertly()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("widget/exception", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test server alt exception
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ServerAltExceptionShouldErrorPropertly()
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("widget/altexception", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task PutConcurrencyViolationShouldFail()
|
||||
{
|
||||
|
||||
//CREATE
|
||||
dynamic w2 = new JObject();
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail");
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.usertype = 1;
|
||||
w2.notes = "blah";
|
||||
w2.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("widget", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
uint OriginalConcurrencyToken = r2.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||
w2 = r2.ObjectResponse["data"];
|
||||
|
||||
|
||||
//UPDATE
|
||||
//PUT
|
||||
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
w2.concurrency = OriginalConcurrencyToken - 1;//bad token
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("widget/", await Util.GetTokenAsync("superuser", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
// [Collection("APICOLLECTION")]
|
||||
public class WidgetRights
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not authorized error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldNotAllowUnauthenticatedAccess()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("widget/list");
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test insufficient read rights error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldNotAllowReadUnauthorizedAccess()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("widget/listwidgets", await Util.GetTokenAsync( "OpsAdminFull"));
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test insufficient create rights error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ServerShouldNotAllowCreateUnauthorizedAccess()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldNotAllowCreateUnauthorizedAccess TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//BizAdminLimited user should not be able to create a widget, only read them
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync( "BizAdminLimited"), d.ToString());
|
||||
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
// [Collection("APICOLLECTION")]
|
||||
public class WidgetRights
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test not authorized error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ServerShouldNotAllowUnauthenticatedAccess()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("widget/list");
|
||||
Util.ValidateHTTPStatusCode(a, 401);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test insufficient read rights error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ServerShouldNotAllowReadUnauthorizedAccess()
|
||||
{
|
||||
ApiResponse a = await Util.GetAsync("widget/listwidgets", await Util.GetTokenAsync( "OpsAdminFull"));
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test insufficient create rights error return
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ServerShouldNotAllowCreateUnauthorizedAccess()
|
||||
{
|
||||
//CREATE
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("ServerShouldNotAllowCreateUnauthorizedAccess TEST WIDGET");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//BizAdminLimited user should not be able to create a widget, only read them
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync( "BizAdminLimited"), d.ToString());
|
||||
|
||||
//2004 unauthorized
|
||||
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
@@ -1,239 +1,239 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class WidgetValidationTest
|
||||
{
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Test business rule should be active on new
|
||||
// /// </summary>
|
||||
// [Fact]
|
||||
// public async void BusinessRuleNewShouldBeActiveShouldWork()
|
||||
// {
|
||||
// //CREATE attempt with broken rules
|
||||
// dynamic d = new JObject();
|
||||
// d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToDeleteNonOwned TEST WIDGET");
|
||||
// d.created = DateTime.Now.ToString();
|
||||
// d.dollarAmount = 1.11m;
|
||||
// d.active = false;//<--- BROKEN RULE new widget must be active = true!!
|
||||
// d.usertype = 1;
|
||||
|
||||
// //create via inventory full test user
|
||||
// ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
// Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
// Util.ShouldContainValidationError(a, "Active", "2203");
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test business rule name should be unique
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleNameMustBeUnique()
|
||||
{
|
||||
//CREATE attempt with broken rules
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleNameMustBeUnique TEST WIDGET");
|
||||
d.notes = "blah";
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//Now try to create again with same name
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Name", "2206");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleNameRequired()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = "";
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
//This is a modelstate error so even though it would be a 2201 in other circumstances here it's a 2203
|
||||
//Maybe a todo is to refine this a bit
|
||||
Util.ShouldContainValidationError(a, "Name", "2203");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleNameLengthExceeded()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = new string('A', 256); ;
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Name", "2202", "255 max");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleStartDateWithoutEndDateShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleStartDateWithoutEndDateShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.startDate = d.created;
|
||||
//NO END DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "EndDate", "2201");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleEndDateWithoutStartDateShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleEndDateWithoutStartDateShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.endDate = d.created;
|
||||
//NO START DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "StartDate", "2201");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleEndDateBeforeStartDateShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleEndDateBeforeStartDateShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.startDate = DateTime.Now.ToString();
|
||||
d.endDate = DateTime.Now.AddHours(-1).ToString();
|
||||
//NO START DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "StartDate", "2207");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleEnumInvalidShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleEnumInvalidShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
|
||||
//NO END DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = -1;//<---BAD VALUE
|
||||
d.Notes = "blah";
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "UserType", "2203");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
public class WidgetValidationTest
|
||||
{
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Test business rule should be active on new
|
||||
// /// </summary>
|
||||
// [Fact]
|
||||
// public async Task BusinessRuleNewShouldBeActiveShouldWork()
|
||||
// {
|
||||
// //CREATE attempt with broken rules
|
||||
// dynamic d = new JObject();
|
||||
// d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToDeleteNonOwned TEST WIDGET");
|
||||
// d.created = DateTime.Now.ToString();
|
||||
// d.dollarAmount = 1.11m;
|
||||
// d.active = false;//<--- BROKEN RULE new widget must be active = true!!
|
||||
// d.usertype = 1;
|
||||
|
||||
// //create via inventory full test user
|
||||
// ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
// Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
// Util.ShouldContainValidationError(a, "Active", "2203");
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test business rule name should be unique
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleNameMustBeUnique()
|
||||
{
|
||||
//CREATE attempt with broken rules
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleNameMustBeUnique TEST WIDGET");
|
||||
d.notes = "blah";
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
|
||||
//Now try to create again with same name
|
||||
a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Name", "2206");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleNameRequired()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = "";
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
//This is a modelstate error so even though it would be a 2201 in other circumstances here it's a 2203
|
||||
//Maybe a todo is to refine this a bit
|
||||
Util.ShouldContainValidationError(a, "Name", "2203");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleNameLengthExceeded()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = new string('A', 256); ;
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "Name", "2202", "255 max");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleStartDateWithoutEndDateShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleStartDateWithoutEndDateShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.startDate = d.created;
|
||||
//NO END DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "EndDate", "2201");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleEndDateWithoutStartDateShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleEndDateWithoutStartDateShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.endDate = d.created;
|
||||
//NO START DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "StartDate", "2201");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleEndDateBeforeStartDateShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleEndDateBeforeStartDateShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
d.startDate = DateTime.Now.ToString();
|
||||
d.endDate = DateTime.Now.AddHours(-1).ToString();
|
||||
//NO START DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = 1;
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "StartDate", "2207");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task BusinessRuleEnumInvalidShouldError()
|
||||
{
|
||||
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify("BusinessRuleEnumInvalidShouldError TEST");
|
||||
d.created = DateTime.Now.ToString();
|
||||
|
||||
//NO END DATE ERRROR
|
||||
d.dollarAmount = 1.11m;
|
||||
d.active = true;
|
||||
d.usertype = -1;//<---BAD VALUE
|
||||
d.Notes = "blah";
|
||||
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
||||
|
||||
|
||||
//create via inventory full test user
|
||||
ApiResponse a = await Util.PostAsync("widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
|
||||
|
||||
|
||||
//2002 in-valid expected
|
||||
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
||||
Util.ShouldContainValidationError(a, "UserType", "2203");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<GenerateFullPaths>true</GenerateFullPaths>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user