Files
raven-test-integration/Translation/Translation.cs
2020-05-08 16:55:46 +00:00

189 lines
8.6 KiB
C#

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"]["concurrencyToken"].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.concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].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 concurrencyToken = PUTTestResponse.ObjectResponse["data"]["concurrencyToken"].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.concurrencyToken = FirstTranslationKey["concurrencyToken"].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("manager", "l3tm3in"), DUSER.ToString());
Util.ValidateDataReturnResponseOk(a);
long DUSERID = a.ObjectResponse["data"]["id"].Value<long>();
//RETRIEVE companion USEROPTIONS object
ApiResponse R = await Util.GetAsync("UserOptions/" + DUSERID.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
Util.ValidateDataReturnResponseOk(R);
//ensure the default value is set
R.ObjectResponse["data"]["uiColor"].Value<string>().Should().Be("#000000");
uint concurrencyToken = R.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
//UPDATE
//PUT
dynamic D2 = new JObject();
D2.translationId = NewId;
D2.concurrencyToken = concurrencyToken;
PUTTestResponse = await Util.PutAsync("UserOptions/" + DUSERID.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), D2.ToString());
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
//VALIDATE
R = await Util.GetAsync("UserOptions/" + DUSERID.ToString(), await Util.GetTokenAsync("manager", "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("manager", "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