diff --git a/src/Application/Auth/Commands/ForgotPasswordCommand.cs b/src/Application/Auth/Commands/ForgotPasswordCommand.cs index f11ce06..600f747 100644 --- a/src/Application/Auth/Commands/ForgotPasswordCommand.cs +++ b/src/Application/Auth/Commands/ForgotPasswordCommand.cs @@ -33,7 +33,6 @@ public async Task Handle(ForgotPasswordCommand request, CancellationToken { x.Id, x.Email, - CompanyName = x.Company.Name, Name = x.Employee != null ? x.Employee.FullName : "there", }) .FirstAsync(cancellationToken); @@ -43,7 +42,6 @@ public async Task Handle(ForgotPasswordCommand request, CancellationToken var emailText = await staticContentReader.ReadContentAsync("email-templates/forgot-password.html"); emailText = emailText.Replace("[User Name]", user.Name); - emailText = emailText.Replace("[Company Name]", user.CompanyName); emailText = emailText.Replace("[Year]", DateTime.Now.Year.ToString()); emailText = emailText.Replace("[Reset Password Link]", link); emailService.Send(user.Email!.ToValueObject(), "Reset Your Password", emailText); diff --git a/src/Application/Common/Abstract/IIdentityService.cs b/src/Application/Common/Abstract/IIdentityService.cs index f3fb96d..aa1c5d0 100644 --- a/src/Application/Common/Abstract/IIdentityService.cs +++ b/src/Application/Common/Abstract/IIdentityService.cs @@ -35,5 +35,5 @@ public interface IIdentityService Task IsEmailConfirmedAsync(int userId); - Task AddSeedDataAsync(Company company); + Task AddSeedDataAsync(); } diff --git a/src/Application/Users/Commands/AddUserCommand.cs b/src/Application/Users/Commands/AddUserCommand.cs index 1c396ec..e46a639 100644 --- a/src/Application/Users/Commands/AddUserCommand.cs +++ b/src/Application/Users/Commands/AddUserCommand.cs @@ -57,7 +57,7 @@ private async Task CreateUserAsync(AddUserCommand request, CancellationToke private async Task CreateIdentity(Company company, AddUserCommand request) { var role = await identityService.GetRoleAsync(request.Role.AsEnum()); - var user = User.Create(request.Email.ToValueObject(), request.PhoneNumber.ToValueObject(), company.Id); + var user = User.Create(request.Email.ToValueObject(), request.PhoneNumber.ToValueObject()); var claims = new Dictionary { @@ -71,6 +71,7 @@ private async Task CreateIdentity(Company company, AddUserCommand request) { UserId = user.Id, }); + return user; } } diff --git a/src/Application/Users/Events/UserCreatedEvent.cs b/src/Application/Users/Events/UserCreatedEvent.cs index 2597ab1..a76b2fd 100644 --- a/src/Application/Users/Events/UserCreatedEvent.cs +++ b/src/Application/Users/Events/UserCreatedEvent.cs @@ -24,7 +24,7 @@ public async Task Handle(UserCreatedEvent notification, CancellationToken cancel { x.Id, x.Email, - CompanyName = x.Company.Name, + CompanyName = x.Employee != null ? x.Employee.Company.Name : "", Name = x.Employee != null ? x.Employee.FullName : "there", }) .FirstAsync(cancellationToken); diff --git a/src/Database/Scripts/20240407.sql b/src/Database/Scripts/20240407.sql index 81b99be..19e8797 100644 --- a/src/Database/Scripts/20240407.sql +++ b/src/Database/Scripts/20240407.sql @@ -30,7 +30,6 @@ CREATE TABLE domain_events ( -- users CREATE TABLE public.users ( id int4 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL, - company_id int NOT NULL, user_name text NULL, normalized_user_name text NULL, email text NULL, @@ -49,8 +48,7 @@ CREATE TABLE public.users ( created_on timestamptz NOT NULL, modified_by int NULL, modified_on timestamptz NULL, - CONSTRAINT pk_users PRIMARY KEY (id), - CONSTRAINT fk_users_company_id FOREIGN KEY (company_id) REFERENCES companies (id) MATCH SIMPLE + CONSTRAINT pk_users PRIMARY KEY (id) ); CREATE UNIQUE INDEX uk_users_email ON public.users USING btree (email); CREATE UNIQUE INDEX uk_users_phone_number ON public.users USING btree (phone_number); diff --git a/src/Domain/Identity/User.cs b/src/Domain/Identity/User.cs index 10a90e0..63caaaa 100644 --- a/src/Domain/Identity/User.cs +++ b/src/Domain/Identity/User.cs @@ -1,4 +1,3 @@ -using Domain.Companies; using Domain.Employees; using Microsoft.AspNetCore.Identity; @@ -11,22 +10,17 @@ private User() Claims = []; } - public int CompanyId { get; private set; } - - public Company Company { get; private set; } = null!; - public Employee? Employee { get; private set; } = null!; public ICollection> Claims { get; private set; } - public static User Create(Email email, PhoneNumber phoneNumber, int companyId) + public static User Create(Email email, PhoneNumber phoneNumber) { var user = new User { UserName = email.Value, Email = email.Value, PhoneNumber = phoneNumber.Value, - CompanyId = companyId }; return user; diff --git a/src/Infrastructure/BackgroundJobs/SeedDataJob.cs b/src/Infrastructure/BackgroundJobs/SeedDataJob.cs index edf9098..a5ccf4c 100644 --- a/src/Infrastructure/BackgroundJobs/SeedDataJob.cs +++ b/src/Infrastructure/BackgroundJobs/SeedDataJob.cs @@ -8,7 +8,7 @@ public async Task Run() { if (!await dbContext.Companies.AnyAsync()) { - var company = Company.Create("Acme", "admin@example.com".ToValueObject(), "9876543210".ToValueObject(), "Acme Admin", 3.ToValueObject()); + var company = Company.Create("Example Company", "admin@example.com".ToValueObject(), "9876543210".ToValueObject(), "Super Admin", 3.ToValueObject()); await dbContext.Companies.AddAsync(company); await dbContext.SaveChangesAsync(default); } @@ -18,8 +18,7 @@ public async Task Run() using var transaction = await dbContext.Database.BeginTransactionAsync(); try { - var company = await dbContext.Companies.FirstAsync(); - await identityService.AddSeedDataAsync(company); + await identityService.AddSeedDataAsync(); await transaction.CommitAsync(); } catch (Exception) diff --git a/src/Infrastructure/EntityFramework/Configuration/IdentityConfig.cs b/src/Infrastructure/EntityFramework/Configuration/IdentityConfig.cs index cca794b..71d181e 100644 --- a/src/Infrastructure/EntityFramework/Configuration/IdentityConfig.cs +++ b/src/Infrastructure/EntityFramework/Configuration/IdentityConfig.cs @@ -70,10 +70,6 @@ public void Configure(EntityTypeBuilder builder) .WithOne() .HasForeignKey(uc => uc.UserId) .IsRequired(); - - builder - .Property(x => x.CompanyId) - .HasColumnName("company_id"); } } diff --git a/src/Infrastructure/Services/CustomClaimsTransformation.cs b/src/Infrastructure/Services/CustomClaimsTransformation.cs deleted file mode 100644 index e5dd336..0000000 --- a/src/Infrastructure/Services/CustomClaimsTransformation.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Security.Claims; -using Microsoft.AspNetCore.Authentication; - -namespace Infrastructure.Services -{ - internal class CustomClaimsTransformation(IDbContext dbContext) : IClaimsTransformation - { - public const string CompanyClaim = "companyId"; - - public async Task TransformAsync(ClaimsPrincipal principal) - { - if (!principal.HasClaim(claim => claim.Type == CompanyClaim)) - { - var userId = int.Parse(principal.FindFirstValue(ClaimTypes.NameIdentifier) ?? "0"); - - if (userId > 0) - { - var user = await dbContext - .Users - .IgnoreQueryFilters() - .FirstAsync(x => x.Id == userId); - - ClaimsIdentity claimsIdentity = new(); - claimsIdentity.AddClaim(new Claim(CompanyClaim, user!.CompanyId.ToString())); - } - } - - return principal; - } - } -} diff --git a/src/Infrastructure/Services/IdentityService.cs b/src/Infrastructure/Services/IdentityService.cs index a680f26..b71a8e6 100644 --- a/src/Infrastructure/Services/IdentityService.cs +++ b/src/Infrastructure/Services/IdentityService.cs @@ -109,7 +109,7 @@ public async Task IsEmailConfirmedAsync(int userId) return await userManager.IsEmailConfirmedAsync(user!); } - public async Task AddSeedDataAsync(Company company) + public async Task AddSeedDataAsync() { foreach (var roleName in (RoleName[])Enum.GetValues(typeof(RoleName))) { @@ -118,7 +118,7 @@ public async Task AddSeedDataAsync(Company company) VerifyResult(result); } - User user = User.Create("admin@example.com".ToValueObject(), "9876543210".ToValueObject(), company.Id); + User user = User.Create("admin@example.com".ToValueObject(), "9876543210".ToValueObject()); var role = await GetRoleAsync(RoleName.SuperAdmin); await CreateUserAsync(user, role); var token = await GenerateAccountVerificationTokenAsync(user.Id); diff --git a/src/Infrastructure/Services/JwtService.cs b/src/Infrastructure/Services/JwtService.cs index 84f768b..d2c5f3e 100644 --- a/src/Infrastructure/Services/JwtService.cs +++ b/src/Infrastructure/Services/JwtService.cs @@ -3,6 +3,7 @@ using System.Security.Cryptography; using System.Text; using Application.Auth.Commands; +using Domain.Identity; using Microsoft.AspNetCore.Http; using Microsoft.IdentityModel.Tokens; @@ -123,31 +124,24 @@ private async Task GenerateRefreshTokenAsync(User user, CancellationToke private async Task AddCustomClaimsAsync(List claims, CancellationToken cancellationToken) { var userId = int.Parse(claims.Find(x => x.Type == ClaimTypes.NameIdentifier)!.Value); - var user = await dbContext - .Users - .Select(x => new - { - x.Id, - x.CompanyId, - }) - .FirstAsync(x => x.Id == userId); var employee = await dbContext .Employees .IgnoreQueryFilters() - .Where(x => x.UserId == userId && x.CompanyId == user.CompanyId) + .Where(x => x.UserId == userId) .Select(x => new { x.Id, - x.FullName + x.FullName, + x.CompanyId }) .FirstOrDefaultAsync(cancellationToken); - claims.Add(new Claim("companyId", user.CompanyId.ToString())); if (employee != null) { claims.Add(new Claim("employeeId", employee.Id.ToString()!)); claims.Add(new Claim("name", employee.FullName.ToString()!)); + claims.Add(new Claim("companyId", employee.CompanyId.ToString())); } } } diff --git a/src/Presentation.Server/DependencyRegistration/AuthPolicy.cs b/src/Presentation.Server/DependencyRegistration/AuthPolicy.cs index 658798d..d206045 100644 --- a/src/Presentation.Server/DependencyRegistration/AuthPolicy.cs +++ b/src/Presentation.Server/DependencyRegistration/AuthPolicy.cs @@ -1,6 +1,8 @@ +using static Domain.Common.Enums; + namespace Presentation.DependencyRegistration { - public static class AuthPolicy + internal static class AuthPolicy { public const string AllRoles = "ALL-ROLES-CAN-ACCESS"; public const string SuperAdmin = "ONLY-SUPER-ADMIN-CAN-ACCESS"; @@ -8,5 +10,35 @@ public static class AuthPolicy public const string CompanyAdminOrEmployee = "COMPANY-ADMIN-AND-EMPLOYEE-CAN-ACCESS"; public const string Employee = "ONLY-EMPLOYEE-CAN-ACCESS"; public const string AllowAnonymous = "ALLOW-ANONYMOUS"; + + internal static IServiceCollection AddAuthPolicy(this IServiceCollection services) + { + services.AddAuthorizationBuilder() + .AddPolicy(AllRoles, policy => policy.RequireAssertion(context => + { + return context.User.IsInRole(RoleName.SuperAdmin.ToString()) || + context.User.IsInRole(RoleName.CompanyAdmin.ToString()) || + context.User.IsInRole(RoleName.Employee.ToString()); + })) + .AddPolicy(SuperAdmin, policy => policy.RequireAssertion(context => + { + return context.User.IsInRole(RoleName.SuperAdmin.ToString()); + })) + .AddPolicy(CompanyAdmin, policy => policy.RequireAssertion(context => + { + return context.User.IsInRole(RoleName.CompanyAdmin.ToString()); + })) + .AddPolicy(CompanyAdminOrEmployee, policy => policy.RequireAssertion(context => + { + return context.User.IsInRole(RoleName.CompanyAdmin.ToString()) || + context.User.IsInRole(RoleName.Employee.ToString()); + })) + .AddPolicy(Employee, policy => policy.RequireAssertion(context => + { + return context.User.IsInRole(RoleName.Employee.ToString()); + })); + + return services; + } } } diff --git a/src/Presentation.Server/DependencyRegistration/DependencyRegistration.cs b/src/Presentation.Server/DependencyRegistration/DependencyRegistration.cs index fd5db6a..2823f58 100644 --- a/src/Presentation.Server/DependencyRegistration/DependencyRegistration.cs +++ b/src/Presentation.Server/DependencyRegistration/DependencyRegistration.cs @@ -1,3 +1,5 @@ +using Microsoft.AspNetCore.Mvc.Authorization; + namespace Presentation.DependencyRegistration { public static class DependencyRegistration @@ -9,7 +11,7 @@ public static IServiceCollection AddPresentationServices(this IServiceCollection builder.Services.AddSwagger(); services.AddHttpContextAccessor(); services.AddSerilogUI(builder.Configuration); - services.AddMvcWithAuthPolicy(); + services.AddAuthPolicy(); services.AddHealthChecks(); services.AddCors(options => options.AddPolicy("CORS", @@ -23,6 +25,11 @@ public static IServiceCollection AddPresentationServices(this IServiceCollection } })); + services.AddMvc(options => + { + options.Filters.Add(new AuthorizeFilter()); + }); + return services; } } diff --git a/src/Presentation.Server/DependencyRegistration/Mvc.cs b/src/Presentation.Server/DependencyRegistration/Mvc.cs deleted file mode 100644 index e45289a..0000000 --- a/src/Presentation.Server/DependencyRegistration/Mvc.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.AspNetCore.Mvc.Authorization; -using static Domain.Common.Enums; - -namespace Presentation.DependencyRegistration -{ - internal static class Mvc - { - internal static void AddMvcWithAuthPolicy(this IServiceCollection services) - { - services.AddAuthorizationBuilder() - .AddPolicy(AuthPolicy.AllRoles, policy => policy.RequireAssertion(context => - { - return context.User.IsInRole(RoleName.SuperAdmin.ToString()) || - context.User.IsInRole(RoleName.CompanyAdmin.ToString()) || - context.User.IsInRole(RoleName.Employee.ToString()); - })) - .AddPolicy(AuthPolicy.SuperAdmin, policy => policy.RequireAssertion(context => - { - return context.User.IsInRole(RoleName.SuperAdmin.ToString()); - })) - .AddPolicy(AuthPolicy.CompanyAdmin, policy => policy.RequireAssertion(context => - { - return context.User.IsInRole(RoleName.CompanyAdmin.ToString()); - })) - .AddPolicy(AuthPolicy.CompanyAdminOrEmployee, policy => policy.RequireAssertion(context => - { - return context.User.IsInRole(RoleName.CompanyAdmin.ToString()) || - context.User.IsInRole(RoleName.Employee.ToString()); - })) - .AddPolicy(AuthPolicy.Employee, policy => policy.RequireAssertion(context => - { - return context.User.IsInRole(RoleName.Employee.ToString()); - })); - - services.AddMvc(options => - { - options.Filters.Add(new AuthorizeFilter()); - }); - } - } -} diff --git a/src/Presentation.Server/DependencyRegistration/SerilogUI.cs b/src/Presentation.Server/DependencyRegistration/SerilogUI.cs index 59b5f1a..4762876 100644 --- a/src/Presentation.Server/DependencyRegistration/SerilogUI.cs +++ b/src/Presentation.Server/DependencyRegistration/SerilogUI.cs @@ -1,4 +1,3 @@ -using Serilog; using Serilog.Ui.Core.Extensions; using Serilog.Ui.PostgreSqlProvider.Extensions; using Serilog.Ui.Web.Extensions; @@ -11,11 +10,16 @@ internal static void AddSerilogUI(this IServiceCollection services, IConfigurati { services.AddSerilog(); - var logTable = configuration.GetValue("Serilog:WriteTo:0:Args:tableName")!; - var connectionString = configuration.GetValue("Serilog:WriteTo:0:Args:connectionString")!; - services.AddSerilogUi(options => - options.UseNpgSql(options => options.WithConnectionString(connectionString).WithTable(logTable))); + { + var logTable = configuration.GetValue("Serilog:WriteTo:0:Args:tableName")!; + var connectionString = configuration.GetValue("Serilog:WriteTo:0:Args:connectionString")!; + + options.UseNpgSql(options => options.WithConnectionString(connectionString) + .WithTable(logTable)) + .AddScopedBasicAuthFilter(); + }) + .AddControllersWithViews(); } } } diff --git a/src/Presentation.Server/DependencyRegistration/Swagger.cs b/src/Presentation.Server/DependencyRegistration/Swagger.cs index 13a9b80..7c5cdaa 100644 --- a/src/Presentation.Server/DependencyRegistration/Swagger.cs +++ b/src/Presentation.Server/DependencyRegistration/Swagger.cs @@ -27,12 +27,12 @@ public static void AddSwagger(this IServiceCollection services) options.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", - Title = "Bit Xplorer HR", - Description = "Rest API for accessing CAB Portal data", + Title = "BIT-HRMS", + Description = "Rest API for accessing BIT-HRMS data", TermsOfService = new Uri(EXAMPLE_DOT_COM), Contact = new OpenApiContact { - Name = "Rawae API", + Name = "BIT-HRMS API", Url = new Uri(EXAMPLE_DOT_COM) }, }); diff --git a/src/Presentation.Server/Middleware/Middleware.cs b/src/Presentation.Server/Middleware/Middleware.cs index fe9a261..2edb455 100644 --- a/src/Presentation.Server/Middleware/Middleware.cs +++ b/src/Presentation.Server/Middleware/Middleware.cs @@ -19,14 +19,15 @@ public static void ConfigureMiddleware(this WebApplication app) app.UseSwaggerUI(); } - if (!app.Environment.IsDevelopment()) - { - app.UseHttpsRedirection(); - } - + app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); - app.UseSerilogUi(); + + app.UseSerilogUi(options => + { + options.WithAuthenticationType(Serilog.Ui.Web.Models.AuthenticationType.Basic) + .WithExpandedDropdownsByDefault(); + }); app.MapControllers(); app.MapFallbackToFile("/index.html"); app.UseHealthChecks("/health"); diff --git a/src/Presentation.Server/Presentation.csproj b/src/Presentation.Server/Presentation.csproj index 3afc1ae..1b63a86 100644 --- a/src/Presentation.Server/Presentation.csproj +++ b/src/Presentation.Server/Presentation.csproj @@ -46,4 +46,8 @@ + + + + diff --git a/src/presentation.client/react.client.esproj b/src/presentation.client/react.client.esproj index b0a4ed1..822d70f 100644 --- a/src/presentation.client/react.client.esproj +++ b/src/presentation.client/react.client.esproj @@ -1,11 +1,15 @@ - - - npm run dev - src\ - Jest - - false - - $(MSBuildProjectDirectory)\dist - + + + npm run dev + src\ + Jest + + false + + $(MSBuildProjectDirectory)\dist + + + + win;linux;osx + \ No newline at end of file diff --git a/tests/Tests.Integration/Fixture/Setup.sql b/tests/Tests.Integration/Fixture/Setup.sql index 9641aa3..5744738 100644 --- a/tests/Tests.Integration/Fixture/Setup.sql +++ b/tests/Tests.Integration/Fixture/Setup.sql @@ -11,9 +11,9 @@ INSERT INTO public.roles VALUES (3, 'Employee', 'EMPLOYEE', NULL, 0, '20 INSERT INTO public.users VALUES -(100, 999, 'super-admin@example.com', 'SUPER-ADMIN@EXAMPLE.COM', 'super-admin@example.com', 'SUPER-ADMIN@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '9876543210', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL), -(200, 999, 'company-admin@example.com', 'COMPANY-ADMIN@EXAMPLE.COM', 'company-admin@example.com', 'COMPANY-ADMIN@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '9876543211', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL), -(300, 999, 'employee@example.com', 'EMPLOYEE@EXAMPLE.COM', 'employee@example.com', 'EMPLOYEE@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '9876543212', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL); +(100, 'super-admin@example.com', 'SUPER-ADMIN@EXAMPLE.COM', 'super-admin@example.com', 'SUPER-ADMIN@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '9876543210', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL), +(200, 'company-admin@example.com', 'COMPANY-ADMIN@EXAMPLE.COM', 'company-admin@example.com', 'COMPANY-ADMIN@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '9876543211', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL), +(300, 'employee@example.com', 'EMPLOYEE@EXAMPLE.COM', 'employee@example.com', 'EMPLOYEE@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '9876543212', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL); INSERT INTO public.user_roles VALUES (100, 1, 0, '2024-05-03 03:31:32.227954-07', NULL, NULL); diff --git a/tests/Tests.Integration/Tests/Users/GetUser.sql b/tests/Tests.Integration/Tests/Users/GetUser.sql index e57411c..f91b3d0 100644 --- a/tests/Tests.Integration/Tests/Users/GetUser.sql +++ b/tests/Tests.Integration/Tests/Users/GetUser.sql @@ -1,4 +1,4 @@ INSERT INTO public.users VALUES -(101, 999, 'super-admin1@example.com', 'SUPER-ADMIN1@EXAMPLE.COM', 'super-admin1@example.com', 'SUPER-ADMIN1@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '7876543210', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL), -(201, 999, 'company-admin1@example.com', 'COMPANY-ADMIN1@EXAMPLE.COM', 'company-admin1@example.com', 'COMPANY-ADMIN1@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '7876543211', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL), -(301, 999, 'employee1@example.com', 'EMPLOYEE1@EXAMPLE.COM', 'employee1@example.com', 'EMPLOYEE1@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '7876543212', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL); \ No newline at end of file +(101, 'super-admin1@example.com', 'SUPER-ADMIN1@EXAMPLE.COM', 'super-admin1@example.com', 'SUPER-ADMIN1@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '7876543210', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL), +(201, 'company-admin1@example.com', 'COMPANY-ADMIN1@EXAMPLE.COM', 'company-admin1@example.com', 'COMPANY-ADMIN1@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '7876543211', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL), +(301, 'employee1@example.com', 'EMPLOYEE1@EXAMPLE.COM', 'employee1@example.com', 'EMPLOYEE1@EXAMPLE.COM', true, 'AQAAAAIAAYagAAAAEIDoeTRLrGQvn8FRF2EXGdQ5GtreAkKzZcbl1BTD6xNNzUXrGkn6BCPp05RxjIH2lQ==', '2XTX6Z5RVMLHRXNWIMW3UJ2USO524VVU', '283d4f58-3a75-47ad-bf9c-de04c9e9a80a', '7876543212', false, false, NULL, true, 0, 0, '2024-05-03 03:51:44.770234-07', NULL, NULL); \ No newline at end of file diff --git a/tests/Tests.Unit.Application/Auth/Commands/RefreshTokenCommandTests.cs b/tests/Tests.Unit.Application/Auth/Commands/RefreshTokenCommandTests.cs index f047a9d..9ad70db 100644 --- a/tests/Tests.Unit.Application/Auth/Commands/RefreshTokenCommandTests.cs +++ b/tests/Tests.Unit.Application/Auth/Commands/RefreshTokenCommandTests.cs @@ -16,7 +16,7 @@ public RefreshTokenCommandTests() var email = new Faker().Person.Email.ToValueObject(); jwtService.ExtractEmailFromToken(Arg.Any()).Returns(email); - identityService.GetUserAsync(Arg.Any()).Returns(User.Create(email, "9876543210".ToValueObject(), new Faker().Random.Int(0))); + identityService.GetUserAsync(Arg.Any()).Returns(User.Create(email, "9876543210".ToValueObject())); jwtService.ValidateRefreshTokenAsync(Arg.Any(), Arg.Any(), Arg.Any()).Returns(true); } diff --git a/tests/Tests.Unit.Application/Employees/Commands/AddEmployeeCommandTests.cs b/tests/Tests.Unit.Application/Employees/Commands/AddEmployeeCommandTests.cs index 34d588b..d96a956 100644 --- a/tests/Tests.Unit.Application/Employees/Commands/AddEmployeeCommandTests.cs +++ b/tests/Tests.Unit.Application/Employees/Commands/AddEmployeeCommandTests.cs @@ -1,9 +1,7 @@ -using System.Threading.Channels; using Application.Common.Abstract; using Application.Employees.Commands; using Domain.Common.ValueObjects; using Domain.Identity; -using Microsoft.EntityFrameworkCore; using MockQueryable.NSubstitute; using NSubstitute; @@ -384,9 +382,9 @@ public async Task Should_Not_Have_Error_When_Request_Is_Valid() private void SetupUserData() { var user = new List - { - User.Create(Email.From("Test@example.com"), PhoneNumber.From("9906121212"), 1) - }.AsQueryable(); + { + User.Create(Email.From("Test@example.com"), PhoneNumber.From("9906121212")) + }.AsQueryable(); var dbSetData = user.BuildMockDbSet(); dbContext.Users.Returns(dbSetData);