Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bf2de8c
Update LdapService.cs
JasonRobertFrancis Sep 8, 2025
db98b3d
Adds models for UserInfo
JasonRobertFrancis Sep 8, 2025
8c27012
Create UserInfoController.cs
JasonRobertFrancis Sep 8, 2025
96e5784
Update UserInfo.cshtml
JasonRobertFrancis Sep 8, 2025
22f6e30
Update .gitignore
JasonRobertFrancis Sep 25, 2025
25e46f4
UserInfo first draft
JasonRobertFrancis Oct 1, 2025
6a5fdfe
Updates Userinfo page
JasonRobertFrancis May 29, 2026
e11c276
Updates UserInfo page
JasonRobertFrancis Jun 16, 2026
4223666
fix: clean up unused usings and resolve nullability warnings in tests
JasonRobertFrancis Jul 28, 2026
e89991c
Addresses code-review issues
JasonRobertFrancis Jul 29, 2026
f30712c
fix: resolve S1144 and S6580 Sonar warnings in IamApi
JasonRobertFrancis Jul 29, 2026
f416e35
fix: address PR reviews and linter suggestions
JasonRobertFrancis Jul 29, 2026
fed2a98
A few directory bug fixes (trailing slashes, race condition, loading …
JasonRobertFrancis Jul 30, 2026
694ecd4
Fixes the results of the code-quality-bot's review
JasonRobertFrancis Jul 30, 2026
99eebf8
fix(directory): resolve ReSharper code quality, XML doc, and unit tes…
JasonRobertFrancis Jul 30, 2026
55a94ae
Refactors to remove clones (from adding the sidebar to the directory …
JasonRobertFrancis Jul 31, 2026
4b023bf
Fixes ReSharper redundant constructor and property initializers
JasonRobertFrancis Jul 31, 2026
a65cc7c
Merges main changes in
JasonRobertFrancis Jul 31, 2026
f32f07f
Addresses linting issues
JasonRobertFrancis Aug 1, 2026
c674c9c
Addresses ReSharper issues
JasonRobertFrancis Aug 1, 2026
fb9579e
More ReSharper issues
JasonRobertFrancis Aug 1, 2026
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -515,3 +516,9 @@ inspect-report/

# Agent folders
.claude
CLAUDE.md

# Temp Agent Files
DESIGN.md*
PRODUCT.md*
.github
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ When I ask a question or make an observation, respond with an answer - do NOT ju

## Testing & Git

- **No VMACS production calls**: Unit tests, local environments, and test environments must NEVER send requests to the VMACS production server. All external HTTP requests (e.g., VMACS, Instinct, IAM API) must be mocked using in-memory databases and mock HTTP clients/factories to prevent production spam.
- **UI**: Test UI changes with Playwright MCP (modals, forms, keyboard nav)
- **API**: Use Playwright MCP to visit endpoints — APIs require browser auth, `curl` fails
- **Git**: NEVER stage files until after code review. Workflow: changes → test → lint → summary → approval → stage
Expand Down
3 changes: 1 addition & 2 deletions test/Areas/Directory/VMACSServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void BuildSearchPath_IncludesAuthToken()

[Theory]
[InlineData("https://vmacs-qa.example.edu")]
[InlineData("http://vmacs.example.edu/")]
public void IsValidBaseUrl_True_ForAbsoluteHttpUrls(string baseUrl)
{
Assert.True(VMACSService.IsValidBaseUrl(baseUrl));
Expand All @@ -44,7 +43,7 @@ public void IsValidBaseUrl_True_ForAbsoluteHttpUrls(string baseUrl)
[InlineData("not-a-url")]
[InlineData("/relative/path")]
[InlineData("vmacs-qa.example.edu")]
[InlineData("ftp://vmacs.example.edu")]
[InlineData("ftp://vmacs-qa.example.edu")]
[InlineData("file:///etc/passwd")]
public void IsValidBaseUrl_False_ForMissingOrNonHttpUrls(string? baseUrl)
{
Expand Down
205 changes: 205 additions & 0 deletions test/Services/UserInfoServiceTests.cs
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));
}
}
}
}
Loading
Loading