-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/userinfo #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JasonRobertFrancis
wants to merge
22
commits into
main
Choose a base branch
from
feature/userinfo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/userinfo #273
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bf2de8c
Update LdapService.cs
JasonRobertFrancis db98b3d
Adds models for UserInfo
JasonRobertFrancis 8c27012
Create UserInfoController.cs
JasonRobertFrancis 96e5784
Update UserInfo.cshtml
JasonRobertFrancis 22f6e30
Update .gitignore
JasonRobertFrancis 25e46f4
UserInfo first draft
JasonRobertFrancis 6a5fdfe
Updates Userinfo page
JasonRobertFrancis e11c276
Updates UserInfo page
JasonRobertFrancis 4223666
fix: clean up unused usings and resolve nullability warnings in tests
JasonRobertFrancis e89991c
Addresses code-review issues
JasonRobertFrancis f30712c
fix: resolve S1144 and S6580 Sonar warnings in IamApi
JasonRobertFrancis f416e35
fix: address PR reviews and linter suggestions
JasonRobertFrancis fed2a98
A few directory bug fixes (trailing slashes, race condition, loading …
JasonRobertFrancis 694ecd4
Fixes the results of the code-quality-bot's review
JasonRobertFrancis 99eebf8
fix(directory): resolve ReSharper code quality, XML doc, and unit tes…
JasonRobertFrancis 55a94ae
Refactors to remove clones (from adding the sidebar to the directory …
JasonRobertFrancis 4b023bf
Fixes ReSharper redundant constructor and property initializers
JasonRobertFrancis a65cc7c
Merges main changes in
JasonRobertFrancis f32f07f
Addresses linting issues
JasonRobertFrancis c674c9c
Addresses ReSharper issues
JasonRobertFrancis fb9579e
More ReSharper issues
JasonRobertFrancis cfde89d
ReSharper issues
JasonRobertFrancis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -497,6 +497,7 @@ awscredentials.xml | |
| # Used to reduce unnecessary dotnet builds | ||
| .build-cache/ | ||
|
|
||
| <<<<<<< HEAD | ||
| # Precommit build artifacts (isolated from dev server) | ||
| .artifacts-precommit/ | ||
| .artifacts-lint/ | ||
|
|
@@ -515,3 +516,9 @@ inspect-report/ | |
|
|
||
| # Agent folders | ||
| .claude | ||
| CLAUDE.md | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to exclude the .md files? I think Rex committed some. |
||
|
|
||
| # Temp Agent Files | ||
| DESIGN.md* | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should not be ignored either |
||
| PRODUCT.md* | ||
| .github | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.Extensions.Caching.Memory; | ||
| using Microsoft.Extensions.Configuration; | ||
| using NSubstitute; | ||
| using System.Net; | ||
| using System.Text; | ||
| using Viper.Areas.Directory.Models; | ||
| using Viper.Areas.Directory.Services; | ||
| using Viper.Classes.SQLContext; | ||
| using Viper.Models.AAUD; | ||
| using Viper.Models.Courses; | ||
|
|
||
| namespace Viper.test.Services | ||
| { | ||
| public class UserInfoServiceTests | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public UserInfoServiceTests(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| } | ||
|
|
||
| private static DbContextOptions<TContext> CreateInMemoryOptions<TContext>() where TContext : DbContext | ||
| { | ||
| return new DbContextOptionsBuilder<TContext>() | ||
| .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) | ||
| .Options; | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task TestGetUserInfo_WithSyntheticData() | ||
| { | ||
| _output.WriteLine("[DEBUG] Starting TestGetUserInfo with fully synthetic data..."); | ||
|
|
||
| // 1. Arrange Config & Cache | ||
| var configData = new Dictionary<string, string?> | ||
| { | ||
| { "Instinct:ApiUrl", "https://synthetic.instinctvet.com/" }, | ||
| { "Credentials:InstinctApi", "synthetic-password" } | ||
| }; | ||
| var config = new ConfigurationBuilder() | ||
| .AddInMemoryCollection(configData) | ||
| .Build(); | ||
|
|
||
| var memoryCache = new MemoryCache(new MemoryCacheOptions()); | ||
|
|
||
| // 2. Mock HttpClientFactory | ||
| var mockHandler = new MockHttpMessageHandler(request => | ||
| { | ||
| var uri = request.RequestUri?.ToString() ?? ""; | ||
| if (uri.Contains("auth/token")) | ||
| { | ||
| return new HttpResponseMessage(HttpStatusCode.OK) | ||
| { | ||
| Content = new StringContent("{\"access_token\": \"synthetic-token\", \"expires_in\": 86400}", Encoding.UTF8, "application/json") | ||
| }; | ||
| } | ||
| if (uri.Contains("query=")) | ||
| { | ||
| var searchJson = @" | ||
| { | ||
| ""data"": { | ||
| ""searchUsers"": [ | ||
| { | ||
| ""id"": ""inst-synthetic-id"", | ||
| ""instinctId"": ""inst-synthetic-id"", | ||
| ""status"": ""Active"", | ||
| ""isActive"": true, | ||
| ""username"": ""jsmith"", | ||
| ""nameFirst"": ""John"", | ||
| ""nameLast"": ""Smith"", | ||
| ""roles"": [ | ||
| { ""label"": ""Staff"" } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| }"; | ||
| return new HttpResponseMessage(HttpStatusCode.OK) | ||
| { | ||
| Content = new StringContent(searchJson, Encoding.UTF8, "application/json") | ||
| }; | ||
| } | ||
| return new HttpResponseMessage(HttpStatusCode.NotFound); | ||
| }); | ||
|
|
||
| var httpClientFactory = Substitute.For<IHttpClientFactory>(); | ||
| httpClientFactory.CreateClient(Arg.Any<string>()).Returns(_ => new HttpClient(mockHandler)); | ||
|
|
||
| // 3. Setup DbContexts and Seed Synthetic Data | ||
| var aaudOptions = CreateInMemoryOptions<AAUDContext>(); | ||
| var coursesOptions = CreateInMemoryOptions<CoursesContext>(); | ||
|
|
||
| using (var aaudSetup = new AAUDContext(aaudOptions)) | ||
| { | ||
| var syntheticUser = new AaudUser | ||
| { | ||
| IamId = "99999999", | ||
| MothraId = "88888888", | ||
| MailId = "jsmith", | ||
| LoginId = "jsmith", | ||
| FirstName = "John", | ||
| LastName = "Smith", | ||
| DisplayFirstName = "John", | ||
| DisplayLastName = "Smith", | ||
| DisplayFullName = "John Smith", | ||
| Current = 1, | ||
| EmployeeId = "emp-999", | ||
| EmployeePKey = "pkey-999", | ||
| ClientId = "1" | ||
| }; | ||
| aaudSetup.AaudUsers.Add(syntheticUser); | ||
|
|
||
| aaudSetup.Employees.Add(new Employee | ||
| { | ||
| EmpPKey = "pkey-999", | ||
| EmpTermCode = "202610", | ||
| EmpPrimaryTitle = "Synthetic Analyst", | ||
| EmpSchoolDivision = "Synthetic Division", | ||
| EmpStatus = "A", | ||
| EmpHomeDept = "Synthetic Dept", | ||
| EmpClientid = "1", | ||
| EmpAltDeptCode = "", | ||
| EmpCbuc = "" | ||
| }); | ||
|
|
||
| await aaudSetup.SaveChangesAsync(TestContext.Current.CancellationToken); | ||
| } | ||
|
|
||
| using (var coursesSetup = new CoursesContext(coursesOptions)) | ||
| { | ||
| coursesSetup.Terminfos.Add(new Terminfo | ||
| { | ||
| TermCode = "202610", | ||
| TermCurrentTermMulti = true, | ||
| TermAcademicYear = "", | ||
| TermDesc = "", | ||
| TermCollCode = "01", | ||
| TermStartDate = DateTime.Today, | ||
| TermEndDate = DateTime.Today, | ||
| TermCurrentTerm = true, | ||
| TermTermType = "" | ||
| }); | ||
| await coursesSetup.SaveChangesAsync(TestContext.Current.CancellationToken); | ||
| } | ||
|
|
||
| using var aaud = new AAUDContext(aaudOptions); | ||
| using var raps = new RAPSContext(CreateInMemoryOptions<RAPSContext>()); | ||
| using var courses = new CoursesContext(coursesOptions); | ||
| using var loans = new EquipmentLoanContext(CreateInMemoryOptions<EquipmentLoanContext>()); | ||
| using var pps = new PPSContext(CreateInMemoryOptions<PPSContext>()); | ||
| using var idcards = new IDCardsContext(CreateInMemoryOptions<IDCardsContext>()); | ||
| using var keys = new KeysContext(CreateInMemoryOptions<KeysContext>()); | ||
|
|
||
| var userInfoService = new UserInfoService(aaud, raps, courses, loans, pps, idcards, keys, config, httpClientFactory, memoryCache); | ||
|
|
||
| // 4. Act | ||
| // Temporary HttpHelper configuration inside the test context | ||
| var mockEnv = Substitute.For<Microsoft.AspNetCore.Hosting.IWebHostEnvironment>(); | ||
| HttpHelper.Configure(memoryCache, config, mockEnv, null, null, null); | ||
|
|
||
| UserInfoResult? result; | ||
| try | ||
| { | ||
| result = await userInfoService.GetUserInfoAsync("99999999", "88888888"); | ||
| } | ||
| finally | ||
| { | ||
| HttpHelper.Configure(null, null, null!, null, null, null); | ||
| } | ||
|
|
||
| // 5. Assert | ||
| Assert.NotNull(result); | ||
| _output.WriteLine($"[DEBUG] Result IamId: {result.IamId}"); | ||
| _output.WriteLine($"[DEBUG] Result DisplayName: {result.DisplayFullName}"); | ||
| _output.WriteLine($"[DEBUG] Result InstinctId: {result.InstinctId}"); | ||
| _output.WriteLine($"[DEBUG] Result InstinctInfo.ErrorMessage: {result.InstinctInfo?.ErrorMessage}"); | ||
| _output.WriteLine($"[DEBUG] Result InstinctInfo.Valid: {result.InstinctInfo?.Valid}"); | ||
|
|
||
| Assert.Equal("99999999", result.IamId); | ||
| Assert.Equal("88888888", result.MothraId); | ||
| Assert.Equal("John Smith", result.DisplayFullName); | ||
| Assert.True(result.IsEmployee); | ||
| Assert.Equal("Synthetic Analyst", result.EmployeePrimaryTitle); | ||
| Assert.Equal("inst-synthetic-id", result.InstinctId); | ||
| Assert.Equal("jsmith", result.InstinctUsername); | ||
| } | ||
|
|
||
| private class MockHttpMessageHandler : HttpMessageHandler | ||
| { | ||
| private readonly Func<HttpRequestMessage, HttpResponseMessage> _handler; | ||
|
|
||
| public MockHttpMessageHandler(Func<HttpRequestMessage, HttpResponseMessage> handler) | ||
| { | ||
| _handler = handler; | ||
| } | ||
|
|
||
| protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
| { | ||
| return Task.FromResult(_handler(request)); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line created during a merge?