118 lines
4.3 KiB
C#
118 lines
4.3 KiB
C#
using SGU.AuthBroker.Core.Profiles;
|
|
using Xunit;
|
|
|
|
namespace SGU.AuthBroker.Core.Tests;
|
|
|
|
public sealed class SguProfileParserTests
|
|
{
|
|
[Fact]
|
|
public void ParsesOnlyTheRequiredAdministrativeFieldsFromTheInitialResponse()
|
|
{
|
|
const string html = """
|
|
<html><body>
|
|
<span id="ctl00_contenedor_decEncabezado_lblNombre">
|
|
017045 - JESÚS ALEJANDRO ROSALES GONZÁLEZ
|
|
</span>
|
|
<span id="ctl00_contenedor_decEncabezado_lblIndicadorValue">
|
|
SINDICALIZADO QUINCENAL (ACTIVO)
|
|
</span>
|
|
<span id="ctl00_contenedor_decEncabezado_lblCorreo">
|
|
<a href="mailto:persona@lasalle.mx">persona@lasalle.mx</a>
|
|
</span>
|
|
<div style="display:none">
|
|
<span id="ctl00_contenedor_decEncabezado_lblPuesto">
|
|
ANALISTA DE PROYECTOS
|
|
</span>
|
|
<span id="ctl00_contenedor_decEncabezado_lblDependencia">
|
|
FACULTAD DE INGENIERÍA
|
|
</span>
|
|
<span id="ctl00_contenedor_decEncabezado_lblJefeNombre">
|
|
ESTE CAMPO NO DEBE EXTRAERSE
|
|
</span>
|
|
</div>
|
|
<table id="incidencias"><tr><td>DATOS NO REQUERIDOS</td></tr></table>
|
|
</body></html>
|
|
""";
|
|
|
|
InstitutionalProfile? profile = SguProfileParser.ParseAdministrative(html, "017045");
|
|
|
|
Assert.NotNull(profile);
|
|
Assert.Equal("017045", profile.EmployeeNumber);
|
|
Assert.Equal("Jesús Alejandro Rosales González", profile.DisplayName);
|
|
Assert.Equal("persona@lasalle.mx", profile.Email);
|
|
Assert.Equal("Sindicalizado quincenal (activo)", profile.EmployeeType);
|
|
Assert.Equal("Analista de Proyectos", profile.JobTitle);
|
|
Assert.Equal("Facultad de Ingeniería", profile.Department);
|
|
}
|
|
|
|
[Fact]
|
|
public void RejectsAdministrativeMetadataForADifferentEmployeeNumber()
|
|
{
|
|
const string html = """
|
|
<span id='ctl00_contenedor_decEncabezado_lblNombre'>017045 - PERSONA INCORRECTA</span>
|
|
<span id='ctl00_contenedor_decEncabezado_lblCorreo'>incorrecta@lasalle.mx</span>
|
|
""";
|
|
|
|
Assert.Null(SguProfileParser.ParseAdministrative(html, "999999"));
|
|
}
|
|
|
|
[Fact]
|
|
public void ParsesTheMenuNameAsAConservativeFallback()
|
|
{
|
|
const string html = """
|
|
<span class="usuario" id="ctl00_lblNombreUsuario">
|
|
MARÍA & JOSÉ
|
|
</span>
|
|
""";
|
|
|
|
InstitutionalProfile? profile = SguProfileParser.ParseMenu(html);
|
|
|
|
Assert.NotNull(profile);
|
|
Assert.Equal("María & José", profile.DisplayName);
|
|
Assert.Null(profile.Email);
|
|
Assert.Null(profile.JobTitle);
|
|
Assert.Null(profile.Department);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("MARÍA DEL CARMEN", "María del Carmen")]
|
|
[InlineData("MIGUEL DE CERVANTES", "Miguel de Cervantes")]
|
|
[InlineData("CARLOS DE LA FUENTE", "Carlos de la Fuente")]
|
|
[InlineData("MARÍA-JOSÉ O'CONNOR", "María-José O'Connor")]
|
|
public void PreservesSpanishNameParticlesAndAccents(string source, string expected)
|
|
{
|
|
const string marker = "ctl00_lblNombreUsuario";
|
|
|
|
InstitutionalProfile? profile = SguProfileParser.ParseMenu(
|
|
$"<span id=\"{marker}\">{source}</span>");
|
|
|
|
Assert.NotNull(profile);
|
|
Assert.Equal(expected, profile.DisplayName);
|
|
}
|
|
|
|
[Fact]
|
|
public void RejectsReplacementCharactersInsteadOfWritingCorruptMetadata()
|
|
{
|
|
const string html = """
|
|
<span id="ctl00_contenedor_decEncabezado_lblNombre">017045 - JES�S ROSALES</span>
|
|
<span id="ctl00_contenedor_decEncabezado_lblPuesto">ANALISTA DE INMERSI�N</span>
|
|
""";
|
|
|
|
InstitutionalProfile? profile = SguProfileParser.ParseAdministrative(html, "017045");
|
|
|
|
Assert.NotNull(profile);
|
|
Assert.Null(profile.DisplayName);
|
|
Assert.Null(profile.JobTitle);
|
|
Assert.Equal("017045", profile.EmployeeNumber);
|
|
}
|
|
|
|
[Fact]
|
|
public void MissingKnownFieldsProducesNoProfile()
|
|
{
|
|
Assert.Null(SguProfileParser.ParseMenu("<html><body>Portal SGU</body></html>"));
|
|
Assert.Null(SguProfileParser.ParseAdministrative(
|
|
"<html><body>Portal SGU</body></html>",
|
|
"017045"));
|
|
}
|
|
}
|