Skip to content

Commit

Permalink
Merge pull request #249 from DentallApp/patch-24
Browse files Browse the repository at this point in the history
Add integration tests for CREATE operations
  • Loading branch information
MrDave1999 authored Apr 11, 2024
2 parents 3d84e78 + fb9ccda commit e0d0e69
Show file tree
Hide file tree
Showing 29 changed files with 1,613 additions and 39 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ Software engineering concepts have been applied in this project:

**Additional references:**
- [Software principles and design](https://deviq.com)
- [Plugin Architecture Pattern in C#](https://code-maze.com/csharp-plugin-architecture-pattern)
- [Plugin Architecture Design Pattern](https://www.devleader.ca/2023/09/07/plugin-architecture-design-pattern-a-beginners-guide-to-modularity)
- [Vertical Slice Architecture in ASP.NET Core](https://code-maze.com/vertical-slice-architecture-aspnet-core)
- [Plugin Architecture Pattern in C# by Alvaro Montoya](https://code-maze.com/csharp-plugin-architecture-pattern)
- [Plugin Architecture Design Pattern by Nick Cosentino](https://www.devleader.ca/2023/09/07/plugin-architecture-design-pattern-a-beginners-guide-to-modularity)
- [Plugin Architecture In C# For Improved Software Design by Nick Cosentino](https://www.devleader.ca/2024/03/12/plugin-architecture-in-c-for-improved-software-design)
- [Vertical Slice Architecture in ASP.NET Core by Swapnil Meshram](https://www.linkedin.com/pulse/vertical-slice-architecture-aspnet-core-swapnil-meshram-sitsf)
- [Vertical Slice Architecture in ASP.NET Core by Code Maze](https://code-maze.com/vertical-slice-architecture-aspnet-core)

## Installation

Expand Down
4 changes: 4 additions & 0 deletions src/Core/GeneralTreatments/UseCases/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ public class CreateGeneralTreatmentRequest
public string Name { get; init; }
public string Description { get; init; }
public IFormFile Image { get; init; }

/// <summary>
/// Expressed in minutes.
/// </summary>
public int Duration { get; init; }

public GeneralTreatment MapToGeneralTreatment() => new()
Expand Down
4 changes: 4 additions & 0 deletions src/Infrastructure/Persistence/SeedsData/UserSeedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public static class UserSeedData
private const string DentistEmail = "dentist@hotmail.com";
private const string AdminEmail = "admin@hotmail.com";
private const string SuperAdminEmail = "superadmin@hotmail.com";
/// <summary>
/// Password Text: 123456
/// </summary>
/// <remarks>This password is for test purposes only.</remarks>
private const string Password = "$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW";

public static void CreateDefaultUserAccounts(this ModelBuilder builder)
Expand Down
1 change: 1 addition & 0 deletions tests/IntegrationTests/.env.test.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# For integration tests, it is not necessary to load any plugin.
PLUGINS=
DENTAL_SERVICES_IMAGES_PATH=./DentalServices
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=root
Expand Down
60 changes: 35 additions & 25 deletions tests/IntegrationTests/Common/HttpClientCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@

public partial class TestBase
{
protected HttpClient CreateClientAsBasicUser()
protected HttpClient CreateClientAsUnverifiedUser()
=> CreateClientAsUser(new UserClaims
{
UserId = 1,
PersonId = 1,
UserName = "basic_user@hotmail.com",
FullName = "Basic User",
Roles = [RoleName.BasicUser]
UserName = "unverified_user@hotmail.com",
FullName = "David Sebastian Roman Amariles",
Roles = [RoleName.Unverified]
});

protected HttpClient CreateClientAsSuperadmin()
=> CreateClientAsEmployee(new EmployeeClaims

protected HttpClient CreateClientAsBasicUser()
=> CreateClientAsUser(new UserClaims
{
UserId = 2,
PersonId = 2,
UserName = "superadmin@hotmail.com",
FullName = "Superadmin",
Roles = [RoleName.Superadmin],
EmployeeId = 1,
OfficeId = 1
UserId = 2,
PersonId = 2,
UserName = "basic_user@hotmail.com",
FullName = "Roberto Emilio Placencio Pinto",
Roles = [RoleName.BasicUser]
});

protected HttpClient CreateClientAsAdmin()
protected HttpClient CreateClientAsSecretary()
=> CreateClientAsEmployee(new EmployeeClaims
{
UserId = 3,
PersonId = 3,
UserName = "admin@hotmail.com",
FullName = "Admin",
Roles = [RoleName.Admin],
EmployeeId = 2,
UserName = "secretary@hotmail.com",
FullName = "Guillermo Emilio Rivera Pinto",
Roles = [RoleName.Secretary],
EmployeeId = 1,
OfficeId = 1
});

Expand All @@ -42,24 +41,35 @@ protected HttpClient CreateClientAsDentist()
UserId = 4,
PersonId = 4,
UserName = "dentist@hotmail.com",
FullName = "Dentist",
FullName = "Derian Emilio Arias Pinto",
Roles = [RoleName.Dentist],
EmployeeId = 3,
EmployeeId = 2,
OfficeId = 1
});

protected HttpClient CreateClientAsSecretary()
protected HttpClient CreateClientAsAdmin()
=> CreateClientAsEmployee(new EmployeeClaims
{
UserId = 5,
PersonId = 5,
UserName = "secretary@hotmail.com",
FullName = "Secretary",
Roles = [RoleName.Secretary],
EmployeeId = 4,
UserName = "admin@hotmail.com",
FullName = "Joel Emilio Delgado Figueroa",
Roles = [RoleName.Admin],
EmployeeId = 3,
OfficeId = 1
});

protected HttpClient CreateClientAsSuperadmin()
=> CreateClientAsEmployee(new EmployeeClaims
{
UserId = 6,
PersonId = 6,
UserName = "superadmin@hotmail.com",
FullName = "Johan Elias Sanchez Pinto",
Roles = [RoleName.Superadmin],
EmployeeId = 4,
OfficeId = 1
});

protected HttpClient CreateClientAsUser(UserClaims user)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/IntegrationTests/Common/Seeds/BaseSeeds.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace IntegrationTests.Common.Seeds;

public static class BaseSeeds
public class BaseSeeds
{
public static List<AppointmentStatus> GetAppointmentStatuses()
=>
Expand Down
43 changes: 43 additions & 0 deletions tests/IntegrationTests/Common/Seeds/EmployeeSeeds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace IntegrationTests.Common.Seeds;

public class EmployeeSeeds
{
public static List<Employee> Get()
=>
[
new()
{
Id = 1,
UserId = 3,
PersonId = 3,
OfficeId = 1
},
new()
{
Id = 2,
UserId = 4,
PersonId = 4,
OfficeId = 1,
PregradeUniversity = "UG",
PostgradeUniversity = "UG"
},
new()
{
Id = 3,
UserId = 5,
PersonId = 5,
OfficeId = 1,
PregradeUniversity = "UG",
PostgradeUniversity = "UG"
},
new()
{
Id = 4,
UserId = 6,
PersonId = 6,
OfficeId = 1,
PregradeUniversity = "UG",
PostgradeUniversity = "UG"
}
];
}
33 changes: 33 additions & 0 deletions tests/IntegrationTests/Common/Seeds/GeneralTreatmentSeeds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace IntegrationTests.Common.Seeds;

public class GeneralTreatmentSeeds
{
public static List<GeneralTreatment> Get()
=>
[
new()
{
Id = 1,
Name = "Ortodoncia/brackets",
Description = "Test",
ImageUrl = "ortodoncia.png",
Duration = 40
},
new()
{
Id = 2,
Name = "Calces/resinas",
Description = "Test",
ImageUrl = "calce.png",
Duration = 40
},
new()
{
Id = 3,
Name = "Tratamiento de conductos/endodoncia",
Description = "Test",
ImageUrl = "endodoncia.png",
Duration = 180
},
];
}
30 changes: 30 additions & 0 deletions tests/IntegrationTests/Common/Seeds/OfficeSeeds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace IntegrationTests.Common.Seeds;

public class OfficeSeeds
{
public static List<Office> Get()
=>
[
new()
{
Id = 1,
Name = "Mapasingue",
Address = "None",
ContactNumber = "0980852228"
},
new()
{
Id = 2,
Name = "El Triunfo",
Address = "None",
ContactNumber = "0980852228"
},
new()
{
Id = 3,
Name = "Naranjito",
Address = "None",
ContactNumber = "0980852228"
}
];
}
34 changes: 28 additions & 6 deletions tests/IntegrationTests/Common/Seeds/PersonSeeds.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace IntegrationTests.Common.Seeds;

public static class PersonSeeds
public class PersonSeeds
{
public static List<Person> GetPersons()
public static List<Person> Get()
=>
[
new()
Expand All @@ -12,7 +12,7 @@ public static List<Person> GetPersons()
Names = "David Sebastian",
LastNames = "Roman Amariles",
CellPhone = "0953581032",
Email = "dave123@hotmail.com",
Email = "unverified_user@hotmail.com",
DateBirth = new DateTime(1997, 01, 01),
GenderId = 1
},
Expand All @@ -23,7 +23,7 @@ public static List<Person> GetPersons()
Names = "Roberto Emilio",
LastNames = "Placencio Pinto",
CellPhone = "0953581040",
Email = "roberto123@hotmail.com",
Email = "basic_user@hotmail.com",
DateBirth = new DateTime(1997, 01, 01),
GenderId = 1
},
Expand All @@ -34,7 +34,7 @@ public static List<Person> GetPersons()
Names = "Guillermo Emilio",
LastNames = "Rivera Pinto",
CellPhone = "0953581060",
Email = "guillermo123@hotmail.com",
Email = "secretary@hotmail.com",
DateBirth = new DateTime(1997, 01, 01),
GenderId = 1
},
Expand All @@ -45,9 +45,31 @@ public static List<Person> GetPersons()
Names = "Derian Emilio",
LastNames = "Arias Pinto",
CellPhone = "0953581178",
Email = "derian123@hotmail.com",
Email = "dentist@hotmail.com",
DateBirth = new DateTime(1996, 02, 01),
GenderId = 1
},
new()
{
Id = 5,
Document = "0923611901",
Names = "Joel Emilio",
LastNames = "Delgado Figueroa",
CellPhone = "0953581289",
Email = "admin@hotmail.com",
DateBirth = new DateTime(1996, 05, 02),
GenderId = 1
},
new()
{
Id = 6,
Document = "0923629901",
Names = "Johan Elias",
LastNames = "Sanchez Pinto",
CellPhone = "0953590089",
Email = "superadmin@hotmail.com",
DateBirth = new DateTime(1998, 08, 27),
GenderId = 1
}
];
}
56 changes: 56 additions & 0 deletions tests/IntegrationTests/Common/Seeds/RoleSeeds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace IntegrationTests.Common.Seeds;

public class RoleSeeds
{
public static List<Role> GetRoles()
=>
[
new() { Id = 1, Name = RoleName.Unverified },
new() { Id = 2, Name = RoleName.BasicUser },
new() { Id = 3, Name = RoleName.Secretary },
new() { Id = 4, Name = RoleName.Dentist },
new() { Id = 5, Name = RoleName.Admin },
new() { Id = 6, Name = RoleName.Superadmin }
];

public static List<UserRole> GetUserRoles()
=>
[
new()
{
Id = 1,
UserId = 1,
RoleId = (int)Role.Predefined.Unverified
},
new()
{
Id = 2,
UserId = 2,
RoleId = (int)Role.Predefined.BasicUser
},
new()
{
Id = 3,
UserId = 3,
RoleId = (int)Role.Predefined.Secretary
},
new()
{
Id = 4,
UserId = 4,
RoleId = (int)Role.Predefined.Dentist
},
new()
{
Id = 5,
UserId = 5,
RoleId = (int)Role.Predefined.Admin
},
new()
{
Id = 6,
UserId = 6,
RoleId = (int)Role.Predefined.Superadmin
}
];
}
Loading

0 comments on commit e0d0e69

Please sign in to comment.