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
8 changes: 4 additions & 4 deletions WardrobeManager.Api.Tests/Endpoints/IdentityEndpointsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public async Task DoesAdminUserExist_WhenAdminDoesNotExist_ReturnsFalseResult()
public async Task CreateAdminIfMissing_WhenCreatedSuccessfully_ReturnsCreated()
{
// Arrange
var credentials = new AdminUserCredentials { email = "admin@test.com", password = "SecurePass1!" };
var credentials = new AuthenticationCredentialsModel { Email = "admin@test.com", Password = "SecurePass1!" };
_mockUserService
.Setup(s => s.CreateAdminIfMissing("admin@test.com", "SecurePass1!"))
.Setup(s => s.CreateAdminIfMissing(credentials))
.ReturnsAsync((true, "Admin user created!"));

// Act
Expand All @@ -84,9 +84,9 @@ public async Task CreateAdminIfMissing_WhenCreatedSuccessfully_ReturnsCreated()
public async Task CreateAdminIfMissing_WhenAdminAlreadyExists_ReturnsConflict()
{
// Arrange
var credentials = new AdminUserCredentials { email = "admin@test.com", password = "SecurePass1!" };
var credentials = new AuthenticationCredentialsModel { Email = "admin@test.com", Password = "SecurePass1!" };
_mockUserService
.Setup(s => s.CreateAdminIfMissing("admin@test.com", "SecurePass1!"))
.Setup(s => s.CreateAdminIfMissing(credentials))
.ReturnsAsync((false, "Admin user already exists!"));

// Act
Expand Down
1 change: 1 addition & 0 deletions WardrobeManager.Api.Tests/Services/ClothingServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using WardrobeManager.Api.Services.Interfaces;
using WardrobeManager.Shared.DTOs;
using WardrobeManager.Shared.Enums;
using WardrobeManager.Shared.Services;
using WardrobeManager.Shared.StaticResources;

namespace WardrobeManager.Api.Tests.Services;
Expand Down
15 changes: 13 additions & 2 deletions WardrobeManager.Api.Tests/Services/UserServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using WardrobeManager.Api.Services.Implementation;
using WardrobeManager.Api.Tests.Helpers;
using WardrobeManager.Shared.DTOs;
using WardrobeManager.Shared.Models;

namespace WardrobeManager.Api.Tests.Services;

Expand Down Expand Up @@ -196,9 +197,14 @@ public async Task CreateAdminIfMissing_WhenAdminAlreadyExists_ReturnsFalseWithMe
_mockUserManager.Setup(m => m.Users).Returns(users);
_mockRoleManager.Setup(m => m.RoleExistsAsync("Admin")).ReturnsAsync(true);
_mockUserManager.Setup(m => m.IsInRoleAsync(adminUser, "Admin")).ReturnsAsync(true);
var credentials = new AuthenticationCredentialsModel
{
Email = "admin@test.com",
Password = "password"
};

// Act
var result = await _service.CreateAdminIfMissing("admin@test.com", "password");
var result = await _service.CreateAdminIfMissing(credentials);

// Assert
using (new AssertionScope())
Expand All @@ -221,9 +227,14 @@ public async Task CreateAdminIfMissing_WhenAdminDoesNotExist_CreatesAdminAndRetu
_mockUserManager
.Setup(m => m.AddToRoleAsync(It.IsAny<User>(), "Admin"))
.ReturnsAsync(IdentityResult.Success);
var credentials = new AuthenticationCredentialsModel
{
Email = "admin@test.com",
Password = "SecurePass1!"
};

// Act
var result = await _service.CreateAdminIfMissing("admin@test.com", "SecurePass1!");
var result = await _service.CreateAdminIfMissing(credentials);

// Assert
using (new AssertionScope())
Expand Down
15 changes: 11 additions & 4 deletions WardrobeManager.Api/Endpoints/IdentityEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using WardrobeManager.Api.Services.Implementation;
using WardrobeManager.Api.Services.Interfaces;
using WardrobeManager.Shared.Models;
using WardrobeManager.Shared.StaticResources;

#endregion

Expand Down Expand Up @@ -68,17 +69,23 @@ public static async Task<IResult> DoesAdminUserExist(IUserService userService)
}

public static async Task<IResult> CreateAdminIfMissing(IUserService userService,
[FromBody] AdminUserCredentials credentials)
[FromBody] AuthenticationCredentialsModel credentials)
{
var res = await userService.CreateAdminIfMissing(credentials.email, credentials.password);
var res = StaticValidators.Validate(credentials);
if (!res.Success)
{
return Results.BadRequest(res.Message);
}

var result = await userService.CreateAdminIfMissing(credentials);

if (res.Item1)
if (result.Item1)
{
return Results.Created();
}
else
{
return Results.Conflict(res.Item2);
return Results.Conflict(result.Item2);
}
}
}
1 change: 1 addition & 0 deletions WardrobeManager.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using WardrobeManager.Api.Services.Implementation;
using WardrobeManager.Api.Services.Interfaces;
using WardrobeManager.Shared.DTOs;
using WardrobeManager.Shared.Services;
using WardrobeManager.Shared.StaticResources;

#endregion
Expand Down
3 changes: 2 additions & 1 deletion WardrobeManager.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"launchBrowser": false,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_WATCH_RESTART_ON_RUDE_EDIT": "1"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7026;http://localhost:5054"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using WardrobeManager.Shared.DTOs;
using WardrobeManager.Shared.Enums;
using WardrobeManager.Shared.Models;
using WardrobeManager.Shared.Services;
using WardrobeManager.Shared.StaticResources;

#endregion
Expand Down
13 changes: 7 additions & 6 deletions WardrobeManager.Api/Services/Implementation/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using WardrobeManager.Shared.DTOs;
using WardrobeManager.Shared.Enums;
using WardrobeManager.Shared.Models;
using WardrobeManager.Shared.StaticResources;

#endregion

Expand Down Expand Up @@ -103,7 +104,7 @@ public async Task<bool> DoesAdminUserExist()
return false;
}

public async Task<(bool, string)> CreateAdminIfMissing(string email, string password)
public async Task<(bool, string)> CreateAdminIfMissing(AuthenticationCredentialsModel credentials)
{
if (await DoesAdminUserExist())
{
Expand All @@ -115,13 +116,13 @@ public async Task<bool> DoesAdminUserExist()

var user = new User
{
Email = email,
NormalizedEmail = email.ToUpper(),
UserName = email.ToUpper(),
NormalizedUserName = email.ToUpper(),
Email = credentials.Email,
NormalizedEmail = credentials.Email.ToUpper(ProjectConstants.DefaultCultureInfo),
UserName = credentials.Email.ToUpper(ProjectConstants.DefaultCultureInfo),
NormalizedUserName = credentials.Email.ToUpper(ProjectConstants.DefaultCultureInfo),
};

var createResult = await _userManager.CreateAsync(user, password);
var createResult = await _userManager.CreateAsync(user, credentials.Password);

if (createResult.Succeeded is false)
{
Expand Down
2 changes: 1 addition & 1 deletion WardrobeManager.Api/Services/Interfaces/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface IUserService
Task UpdateUser(string userId, EditedUserDTO editedUser);
Task DeleteUser(string userId);
Task<bool> DoesAdminUserExist();
Task<(bool, string)> CreateAdminIfMissing(string email, string password);
Task<(bool, string)> CreateAdminIfMissing(AuthenticationCredentialsModel credentials);
}
21 changes: 11 additions & 10 deletions WardrobeManager.Presentation.Tests/ApiServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Moq.Protected;
using WardrobeManager.Presentation.Services.Implementation;
using WardrobeManager.Presentation.Services.Interfaces;
using WardrobeManager.Shared.Models;

namespace WardrobeManager.Presentation.Tests;

Expand Down Expand Up @@ -178,10 +179,10 @@ public async Task AddLog_WhenCalled_PostsToAddLogEndpoint()
public async Task CreateAdminUserIfMissing_WhenSuccessful_ReturnsTrueWithMessage()
{
// Arrange
var credentials = new WardrobeManager.Shared.Models.AdminUserCredentials
var credentials = new AuthenticationCredentialsModel()
{
email = "admin@test.com",
password = "SecurePass1!"
Email = "admin@test.com",
Password = "SecurePass1!"
};
var mockResponse = new HttpResponseMessage
{
Expand All @@ -206,19 +207,19 @@ public async Task CreateAdminUserIfMissing_WhenSuccessful_ReturnsTrueWithMessage
// Assert
using (new FluentAssertions.Execution.AssertionScope())
{
result.Item1.Should().BeTrue();
result.Item2.Should().Be("Admin user created!");
result.Success.Should().BeTrue();
result.Message.Should().Be("Admin user created!");
}
}

[Test]
public async Task CreateAdminUserIfMissing_WhenAdminAlreadyExists_ReturnsFalseWithMessage()
{
// Arrange
var credentials = new WardrobeManager.Shared.Models.AdminUserCredentials
var credentials = new AuthenticationCredentialsModel
{
email = "admin@test.com",
password = "SecurePass1!"
Email = "admin@test.com",
Password = "SecurePass1!"
};
var mockResponse = new HttpResponseMessage
{
Expand All @@ -243,8 +244,8 @@ public async Task CreateAdminUserIfMissing_WhenAdminAlreadyExists_ReturnsFalseWi
// Assert
using (new FluentAssertions.Execution.AssertionScope())
{
result.Item1.Should().BeFalse();
result.Item2.Should().Be("Admin user already exists!");
result.Success.Should().BeFalse();
result.Message.Should().Be("Admin user already exists!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using WardrobeManager.Shared.StaticResources;
using Blazing.Mvvm.Components;
using Microsoft.Extensions.Configuration;
using WardrobeManager.Presentation.ViewModels.Pages;
using WardrobeManager.Shared.Services;

namespace WardrobeManager.Presentation.Tests.ViewModels;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentAssertions;
using WardrobeManager.Presentation.ViewModels;
using WardrobeManager.Presentation.ViewModels.Pages;

namespace WardrobeManager.Presentation.Tests.ViewModels;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentAssertions;
using WardrobeManager.Presentation.ViewModels;
using WardrobeManager.Presentation.ViewModels.Pages;

namespace WardrobeManager.Presentation.Tests.ViewModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using WardrobeManager.Shared.Models;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
using WardrobeManager.Presentation.ViewModels.Pages;

namespace WardrobeManager.Presentation.Tests.ViewModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using WardrobeManager.Presentation.ViewModels;
using WardrobeManager.Presentation.Tests.Helpers;
using Microsoft.AspNetCore.Components.Authorization;
using WardrobeManager.Presentation.ViewModels.Components;
using WardrobeManager.Presentation.ViewModels.Pages;

namespace WardrobeManager.Presentation.Tests.ViewModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using WardrobeManager.Presentation.Identity.Models;
using WardrobeManager.Presentation.Services.Interfaces;
using WardrobeManager.Presentation.ViewModels;
using WardrobeManager.Presentation.ViewModels.Pages;
using WardrobeManager.Shared.Enums;
using WardrobeManager.Shared.Models;

Expand Down Expand Up @@ -108,6 +109,7 @@ public async Task SignupAsync_WhenSignupFails_DoesNotAttemptLogin()
public async Task SignupAsync_WhenSignupSucceedsButLoginFails_AddsErrorNotification()
{
// Arrange
_viewModel.AuthenticationCredentialsModel = new AuthenticationCredentialsModel { Email = "test@gmail.com", Password = "SecurePassword1!" };
_mockIdentityService
.Setup(s => s.SignupAsync(It.IsAny<AuthenticationCredentialsModel>()))
.ReturnsAsync(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using WardrobeManager.Presentation.Tests.Helpers;
using WardrobeManager.Shared.DTOs;
using Blazing.Mvvm.Components;
using WardrobeManager.Presentation.ViewModels.Pages;

namespace WardrobeManager.Presentation.Tests.ViewModels;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
@namespace WardrobeManager.Presentation.Components.Onboarding

<div class="grow w-full flex flex-col items-center gap-5 justify-evenly">
<h3 class="subheading-text text-primary">@Title</h3>
@ChildContent
<button @onclick="ButtonClickCallback" class="btn btn-accent btn-wide subtitle-text">@ButtonText</button>
<div class="grow w-full flex flex-col items-center gap-3 smj:gap-5 py-4 sm:py-12 px-4 sm:px-0">
<div class="grow flex flex-col items-center gap-5 justify-evenly min-h-[15rem] h-full sm:h-[30rem] w-full xl:w-[70rem]">
<h3 class="text-xl sm:text-4xl text-primary text-center">@Title</h3>
@ChildContent
</div>
<div class="flex gap-6 w-full justify-center">
<Button Type="ButtonType.Secondary" Size="ButtonSize.Large" Text="Back" OnClick="PreviousButtonClickCallback"/>
<Button Type="ButtonType.Primary" Size="ButtonSize.Large" Text="Next" OnClick="NextButtonClickCallback"/>
@if (SkipTutorialButtonClickCallback.HasDelegate)
{
<Button Type="ButtonType.Outline" Size="ButtonSize.Large" Text="Skip Tutorial" class="sm:ml-auto"
OnClick="() => ShowSkipTutorialDialog = true"/>
<Dialog Show="@ShowSkipTutorialDialog" Width="500px" OnClose="() => ShowSkipTutorialDialog = false">
<Header>
<div class="flex-col g4">
<p class="large">Are you sure you want to skip the tutorial?</p>
<p class="muted">The tutorial has important information that helps you start using the app.</p>
</div>
</Header>
<Content>
<span></span>
</Content>
<Footer>
<div style="width: 100%; display: flex">
<Button Text="Skip Tutorial" Type="ButtonType.Secondary" OnClick="SkipTutorialButtonClickCallback" />
</div>
</Footer>
</Dialog>
}
</div>
</div>

@code {
[Parameter] public required string Title { get; set; }
[Parameter] public required RenderFragment ChildContent { get; set; }
[Parameter] public required string ButtonText { get; set; }
[Parameter] public required EventCallback ButtonClickCallback { get; set; }
[Parameter] public required EventCallback NextButtonClickCallback { get; set; }
[Parameter] public required EventCallback PreviousButtonClickCallback { get; set; }
[Parameter] public EventCallback SkipTutorialButtonClickCallback { get; set; }
private bool ShowSkipTutorialDialog { get; set; }
}
Loading