Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 77 additions & 78 deletions EstateManagementUI.BusinessLogic/Clients/ApiClient.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace EstateManagementUI.BusinessLogic.PermissionService.Constants;

[ExcludeFromCodeCoverage]
public class ApplicationSections
public record ApplicationSections
{
public static readonly string Dashboard = "Dashboard";
public static readonly string Estate = "Estate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace EstateManagementUI.BusinessLogic.PermissionService.Constants;

[ExcludeFromCodeCoverage]
public class DashboardFunctions
public record DashboardFunctions
{

public static readonly string Dashboard = "Dashboard";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace EstateManagementUI.BusinessLogic.PermissionService.Constants;

[ExcludeFromCodeCoverage]
public class MerchantFunctions
public record MerchantFunctions
{
public static readonly string ViewList = "View Merchant List";
public static readonly string View = "View Single Merchant";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace EstateManagementUI.BusinessLogic.PermissionService.Constants;

[ExcludeFromCodeCoverage]
public class OperatorFunctions
public record OperatorFunctions
{
public static readonly string ViewList = "View Operators List";
public static readonly string View = "View Single Operator";
Expand Down
3 changes: 3 additions & 0 deletions EstateManagementUI.IntegrationTests/Common/DockerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ private async Task<IContainerService> StartEstateManagementUiContainer(List<INet
if (response.IsSuccessStatusCode == false) {
TraceX($"createRolesRequest failed [{response.StatusCode}]");
}
TraceX($"Create Role Response is [{response.StatusCode}]");

HttpRequestMessage addUserToRoleRequest = new(HttpMethod.Post,
$"https://localhost:{this.EstateManagementUiPort}/api/Permissions/addUserToRole");
List<AddUserToRole> userRolesList = new List<AddUserToRole> {
Expand All @@ -266,6 +268,7 @@ private async Task<IContainerService> StartEstateManagementUiContainer(List<INet
TraceX($"addUserToRoleRequest failed [{response.StatusCode}]");
}

TraceX($"Add User to Role Response is [{response.StatusCode}]");

HttpRequestMessage getRolePermissionsRequest = new(HttpMethod.Get,
$"https://localhost:{this.EstateManagementUiPort}/api/Permissions/getRolePermissions?roleName=Administrator");
Expand Down
19 changes: 11 additions & 8 deletions EstateManagementUI.UITests/AddContractDialogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ public async Task Save_AssignsContractToMerchant_WhenContractIdIsNotEmpty()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.AssignContractToMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._addContractDialog.Events.Count.ShouldBe(2);
this._addContractDialog.Events[0].ShouldBeOfType<MerchantPageEvents.ContractAssignedToMerchantEvent>();
this._addContractDialog.Events[1].ShouldBeOfType<MerchantPageEvents.HideAddContractDialog>();
var events = this._addContractDialog.GetDispatchedEvents();
events.Count.ShouldBe(2);
events[0].ShouldBeOfType<MerchantPageEvents.ContractAssignedToMerchantEvent>();
events[1].ShouldBeOfType<MerchantPageEvents.HideAddContractDialog>();
}

[Fact]
Expand All @@ -76,9 +77,10 @@ public async Task Save_ShowsErrorMessage_WhenAssignContractFails()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.AssignContractToMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._addContractDialog.Events.Count.ShouldBe(2);
this._addContractDialog.Events[0].ShouldBeOfType<ShowMessage>();
this._addContractDialog.Events[1].ShouldBeOfType<MerchantPageEvents.HideAddContractDialog>();
var events = this._addContractDialog.GetDispatchedEvents();
events.Count.ShouldBe(2);
events[0].ShouldBeOfType<ShowMessage>();
events[1].ShouldBeOfType<MerchantPageEvents.HideAddContractDialog>();
}

[Fact]
Expand All @@ -88,7 +90,8 @@ public async Task Close_DispatchesHideAddContractDialogEvent()
await this._addContractDialog.Close();

// Assert
this._addContractDialog.Events.Count.ShouldBe(1);
this._addContractDialog.Events[0].ShouldBeOfType<MerchantPageEvents.HideAddContractDialog>();
var events = this._addContractDialog.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType<MerchantPageEvents.HideAddContractDialog>();
}
}
21 changes: 12 additions & 9 deletions EstateManagementUI.UITests/AddDeviceDialogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ public async Task Save_AssignsDeviceToMerchant()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.AssignDeviceToMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._addDeviceDialog.Events.Count.ShouldBe(2);
this._addDeviceDialog.Events[0].ShouldBeOfType<MerchantPageEvents.DeviceAssignedToMerchantEvent>();
this._addDeviceDialog.Events[1].ShouldBeOfType<MerchantPageEvents.HideAddDeviceDialog>();
var events = this._addDeviceDialog.GetDispatchedEvents();
events.Count.ShouldBe(2);
events[0].ShouldBeOfType<MerchantPageEvents.DeviceAssignedToMerchantEvent>();
events[1].ShouldBeOfType<MerchantPageEvents.HideAddDeviceDialog>();
}

[Fact]
Expand All @@ -73,10 +74,11 @@ public async Task Save_AssignsDeviceToMerchant_Fails()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.AssignDeviceToMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);

this._addDeviceDialog.Events.Count.ShouldBe(2);
this._addDeviceDialog.Events[0].ShouldBeOfType<ShowMessage>();
this._addDeviceDialog.Events[1].ShouldBeOfType<MerchantPageEvents.HideAddDeviceDialog>();

var events = this._addDeviceDialog.GetDispatchedEvents();
events.Count.ShouldBe(2);
events[0].ShouldBeOfType<ShowMessage>();
events[1].ShouldBeOfType<MerchantPageEvents.HideAddDeviceDialog>();
}

[Fact]
Expand All @@ -86,7 +88,8 @@ public async Task Close_DispatchesHideAddContractDialogEvent()
await this._addDeviceDialog.Close();

// Assert
this._addDeviceDialog.Events.Count.ShouldBe(1);
this._addDeviceDialog.Events[0].ShouldBeOfType<MerchantPageEvents.HideAddDeviceDialog>();
var events = this._addDeviceDialog.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType<MerchantPageEvents.HideAddDeviceDialog>();
}
}
9 changes: 6 additions & 3 deletions EstateManagementUI.UITests/AddOperatorDialogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public async Task Save_ShouldAssignOperatorToMerchant()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.AssignOperatorToMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._addOperatorDialog.Events.ShouldContain(e => e is MerchantPageEvents.OperatorAssignedToMerchantEvent);
var events = this._addOperatorDialog.GetDispatchedEvents();
events.ShouldContain(e => e is MerchantPageEvents.OperatorAssignedToMerchantEvent);
}

[Fact]
Expand All @@ -81,7 +82,8 @@ public async Task Save_ShouldShowErrorMessageOnFailure()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.AssignOperatorToMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._addOperatorDialog.Events.ShouldContain(e => e is ShowMessage && ((ShowMessage)e).Message == "Error assigning operator to Merchant");
var events = this._addOperatorDialog.GetDispatchedEvents();
events.ShouldContain(e => e is ShowMessage && ((ShowMessage)e).Message == "Error assigning operator to Merchant");
}

[Fact]
Expand All @@ -91,6 +93,7 @@ public async Task Close_ShouldDispatchHideAddOperatorDialogEvent()
await this._addOperatorDialog.Close();

// Assert
this._addOperatorDialog.Events.ShouldContain(e => e is MerchantPageEvents.HideAddOperatorDialog);
var events = this._addOperatorDialog.GetDispatchedEvents();
events.ShouldContain(e => e is MerchantPageEvents.HideAddOperatorDialog);
}
}
15 changes: 10 additions & 5 deletions EstateManagementUI.UITests/EditMerchantTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void AddOperator_ShouldDispatchShowAddOperatorDialogEvent()
this._editMerchant.AddOperator();

// Assert
this._editMerchant.Events.ShouldContain(e => e is MerchantPageEvents.ShowAddOperatorDialog);
var events = this._editMerchant.GetDispatchedEvents();
events.ShouldContain(e => e is MerchantPageEvents.ShowAddOperatorDialog);
}

[Fact]
Expand All @@ -51,7 +52,8 @@ public void AddContract_ShouldDispatchShowAddContractDialogEvent() {
this._editMerchant.AddContract();

// Assert
this._editMerchant.Events.ShouldContain(e => e is MerchantPageEvents.ShowAddContractDialog);
var events = this._editMerchant.GetDispatchedEvents();
events.ShouldContain(e => e is MerchantPageEvents.ShowAddContractDialog);
}

[Fact]
Expand All @@ -61,7 +63,8 @@ public void AddDevice_ShouldDispatchShowAddDeviceDialogEvent()
this._editMerchant.AddDevice();

// Assert
this._editMerchant.Events.ShouldContain(e => e is MerchantPageEvents.ShowAddDeviceDialog);
var events = this._editMerchant.GetDispatchedEvents();
events.ShouldContain(e => e is MerchantPageEvents.ShowAddDeviceDialog);
}


Expand Down Expand Up @@ -127,7 +130,8 @@ public async Task Save_MerchantDepositIsMade()

await this._makeDeposit.Save();

this._makeDeposit.Events.ShouldContain(e => e is MerchantPageEvents.DepositMadeEvent);
var events = this._makeDeposit.GetDispatchedEvents();
events.ShouldContain(e => e is MerchantPageEvents.DepositMadeEvent);
}

[Fact]
Expand All @@ -143,6 +147,7 @@ public async Task Save_SaveFailed_MerchantDepositIsNotMade()

await this._makeDeposit.Save();

this._makeDeposit.Events.ShouldContain(e => e is ShowMessage);
var events = this._makeDeposit.GetDispatchedEvents();
events.ShouldContain(e => e is ShowMessage);
}
}
20 changes: 12 additions & 8 deletions EstateManagementUI.UITests/MerchantDetailsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ public async Task Save_CreateFails()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.AddMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._merchant.Events.Count.ShouldBe(1);
this._merchant.Events[0].ShouldBeOfType(typeof(ShowMessage));
var events = this._merchant.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType(typeof(ShowMessage));
}

[Fact]
Expand Down Expand Up @@ -218,8 +219,9 @@ public async Task Save_UpdateMerchantFails()
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateMerchantAddressCommand>(), It.IsAny<CancellationToken>()), Times.Never);
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateMerchantContactCommand>(), It.IsAny<CancellationToken>()), Times.Never);
this._merchant.Events.Count.ShouldBe(1);
this._merchant.Events[0].ShouldBeOfType<ShowMessage>();
var events = this._merchant.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType<ShowMessage>();
}

[Fact]
Expand Down Expand Up @@ -260,8 +262,9 @@ public async Task Save_UpdateMerchantAddressFails()
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateMerchantAddressCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateMerchantContactCommand>(), It.IsAny<CancellationToken>()), Times.Never);
this._merchant.Events.Count.ShouldBe(1);
this._merchant.Events[0].ShouldBeOfType<ShowMessage>();
var events = this._merchant.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType<ShowMessage>();
}

[Fact]
Expand Down Expand Up @@ -302,8 +305,9 @@ public async Task Save_UpdateMerchantContactFails()
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateMerchantCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateMerchantAddressCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateMerchantContactCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._merchant.Events.Count.ShouldBe(1);
this._merchant.Events[0].ShouldBeOfType<ShowMessage>();
var events = this._merchant.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType<ShowMessage>();
}

[Fact]
Expand Down
20 changes: 12 additions & 8 deletions EstateManagementUI.UITests/OperatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public async Task Save_AddsNewOperator_WhenOperatorIdIsEmpty()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.AddNewOperatorCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._operator.Events.Count.ShouldBe(1);
this._operator.Events[0].ShouldBeOfType<OperatorPageEvents.OperatorCreatedEvent>();
var events = this._operator.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType<OperatorPageEvents.OperatorCreatedEvent>();
}

[Fact]
Expand All @@ -94,8 +95,9 @@ public async Task Save_AddOperatorFailed_MessageShow()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.AddNewOperatorCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._operator.Events.Count.ShouldBe(1);
this._operator.Events[0].ShouldBeOfType<ShowMessage>();
var events = this._operator.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType<ShowMessage>();
}

[Fact]
Expand All @@ -114,8 +116,9 @@ public async Task Save_UpdatesOperator_WhenOperatorIdIsNotEmpty()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateOperatorCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._operator.Events.Count.ShouldBe(1);
this._operator.Events[0].ShouldBeOfType<OperatorPageEvents.OperatorUpdatedEvent>();
var events = this._operator.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType<OperatorPageEvents.OperatorUpdatedEvent>();
}

[Fact]
Expand All @@ -134,7 +137,8 @@ public async Task Save_UpdateOperatorFailed_MessageShow()

// Assert
this._mediatorMock.Verify(m => m.Send(It.IsAny<Commands.UpdateOperatorCommand>(), It.IsAny<CancellationToken>()), Times.Once);
this._operator.Events.Count.ShouldBe(1);
this._operator.Events[0].ShouldBeOfType<ShowMessage>();
var events = this._operator.GetDispatchedEvents();
events.Count.ShouldBe(1);
events[0].ShouldBeOfType<ShowMessage>();
}
}
3 changes: 1 addition & 2 deletions EstateManagementUI/Common/ChartBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ public static String BuildBarChartOptions<T>(List<String> categories,
Converters = new List<JsonConverter> { new JavaScriptFunctionConverter() },
};

var x = JsonConvert.SerializeObject(chartOptions, settings);
return JsonConvert.SerializeObject(chartOptions, settings);
}

Expand All @@ -293,7 +292,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
public override bool CanConvert(Type objectType) => objectType == typeof(JavaScriptFunction);
}

public class StandardJavascriptFunctions {
public record StandardJavascriptFunctions {
public static JavaScriptFunction CurrencyFormatter =>
new JavaScriptFunction("function (value) {\r\n return \"KES \" + value;\r\n }");
public static JavaScriptFunction EmptyFunction =>
Expand Down
8 changes: 5 additions & 3 deletions EstateManagementUI/Common/SecureHydroComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ private static string GetFullTypeName(Type type) =>
Dispatch(GetFullTypeName(typeof(TEvent)), data, scope, asynchronous);
}

public List<Object> Events = new List<Object>();
public String LocationUrl;
public object Payload;
private List<Object> Events = new List<Object>();

public List<Object> GetDispatchedEvents() => this.Events;
public String LocationUrl { get; private set; }
public object Payload { get; private set; }


public new void Dispatch<TEvent>(string name,
Expand Down
2 changes: 1 addition & 1 deletion EstateManagementUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static async Task Main(String[] args) {
Program.CreateHostBuilder(args).Build().Run();
}

private static async Task<IPermissionsRepository> CreatePermissionsRepository(String dbConnString, CancellationToken cancellationToken)
private static IPermissionsRepository CreatePermissionsRepository(String dbConnString)
{
var optionsBuilder = new DbContextOptionsBuilder<PermissionsContext>();
optionsBuilder.UseSqlite(dbConnString); // Configure for your database provider
Expand Down
Loading