Files
PSInfisicalAPI/src/PSInfisicalAPI.Tests/OrganizationMapperTests.cs
T
GraceSolutions 77cb03ec98 feat: add Organization/Sub-Organization CRUD cmdlets and Get-InfisicalSANList
Adds 8 cmdlets for Organization and Sub-Organization CRUD (Get/New/Update/Remove for each), targeting /api/v2/organizations and /api/v1/sub-organizations. Get cmdlets default to List parameter set and switch to Single when -OrganizationId or -SubOrganizationId is supplied. New/Update/Remove honor -WhatIf/-Confirm; Remove defaults to High ConfirmImpact and supports -PassThru. No project context required.

Adds Get-InfisicalSANList: emits a deduplicated SAN candidate set containing the local device name, the device name suffixed with each non-empty DNS suffix found across operational adapters and the system primary domain, every IPv4 unicast address falling within RFC 1918 or CGNAT, and the IPv4/IPv6 loopback addresses. Supports optional case-insensitive -InclusionExpression and -ExclusionExpression regex filters applied in fetch -> include -> exclude -> output order. Output is a single strongly-typed System.String[] array emitted non-enumerated so List<string>.AddRange consumes it directly.

Registers 10 new endpoints, adds InfisicalOrganization/InfisicalSubOrganization models with DTOs, mappers, and clients, full MAML help for all 9 new cmdlets, mapper unit tests, EndpointRegistry inline-data coverage, and docs/DesignSpec.md sections 16.7 and 16.8. build.ps1 CmdletsToExport and Test-ModuleImports expected list now contain 51 cmdlets. README updated with Organization/Sub-Organization tables, the new Get-InfisicalSANList entry, and an end-to-end certificate request example using splatted OrderedDictionary blocks.
2026-06-06 20:17:49 -04:00

73 lines
2.9 KiB
C#

using System.Reflection;
using PSInfisicalAPI.Models;
using Xunit;
namespace PSInfisicalAPI.Tests
{
public class OrganizationMapperTests
{
private static readonly System.Type MapperType = typeof(PSInfisicalAPI.Connections.InfisicalConnection).Assembly
.GetType("PSInfisicalAPI.Organizations.InfisicalOrganizationMapper", true);
private static readonly System.Type DtoType = typeof(PSInfisicalAPI.Connections.InfisicalConnection).Assembly
.GetType("PSInfisicalAPI.Organizations.InfisicalOrganizationResponseDto", true);
private static InfisicalOrganization InvokeMap(object dto)
{
MethodInfo map = MapperType.GetMethod("Map", BindingFlags.Public | BindingFlags.Static);
return (InfisicalOrganization)map.Invoke(null, new[] { dto });
}
[Fact]
public void Map_Null_Dto_Returns_Null()
{
Assert.Null(InvokeMap(null));
}
[Fact]
public void Map_Populates_Core_Fields()
{
object dto = System.Activator.CreateInstance(DtoType);
DtoType.GetProperty("Id").SetValue(dto, "org-001");
DtoType.GetProperty("Name").SetValue(dto, "Acme");
DtoType.GetProperty("Slug").SetValue(dto, "acme");
DtoType.GetProperty("CustomerId").SetValue(dto, "cust-9");
DtoType.GetProperty("AuthEnforced").SetValue(dto, true);
DtoType.GetProperty("ScimEnabled").SetValue(dto, true);
DtoType.GetProperty("CreatedAt").SetValue(dto, "2026-01-15T12:34:56Z");
DtoType.GetProperty("UpdatedAt").SetValue(dto, "2026-02-20T09:00:00Z");
InfisicalOrganization organization = InvokeMap(dto);
Assert.Equal("org-001", organization.Id);
Assert.Equal("Acme", organization.Name);
Assert.Equal("acme", organization.Slug);
Assert.Equal("cust-9", organization.CustomerId);
Assert.True(organization.AuthEnforced);
Assert.True(organization.ScimEnabled);
Assert.NotNull(organization.CreatedAtUtc);
Assert.NotNull(organization.UpdatedAtUtc);
}
[Fact]
public void Map_Falls_Back_To_InternalId()
{
object dto = System.Activator.CreateInstance(DtoType);
DtoType.GetProperty("InternalId").SetValue(dto, "internal-id-1");
InfisicalOrganization organization = InvokeMap(dto);
Assert.Equal("internal-id-1", organization.Id);
}
[Fact]
public void MapMany_Null_Returns_Empty()
{
MethodInfo mapMany = MapperType.GetMethod("MapMany", BindingFlags.Public | BindingFlags.Static);
InfisicalOrganization[] result = (InfisicalOrganization[])mapMany.Invoke(null, new object[] { null });
Assert.NotNull(result);
Assert.Empty(result);
}
}
}