Merge branch 'dev' into feat/board-week-only-pagination

This commit is contained in:
Arthur Bassi 2026-08-25 12:01:19 -03:00 • committed by GitHub
commit 12dc3d51d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 123 additions and 3 deletions

View file

@ -364,6 +364,114 @@ public class VendorDataServiceTests
items.Should().Contain(i => i.ContactName == "No Company Tech" && i.VendorId != null);
}
[Fact]
public async Task GetDirectoryPagedAsync_UsesCanonicalCompanyLocationAndEmailFallback()
{
await using var context = NewContext();
var company = new VendorCompany
{
Name = "Canonical Co",
NormalizedName = "canonical co",
Email = "dispatch@canonical.example",
City = "Chicago",
State = "IL"
};
context.VendorCompanies.Add(company);
context.Vendors.AddRange(
new Vendor
{
CompanyName = "Canonical Co",
ContactName = "Company Fallback",
Email = " ",
City = "Stale City",
State = "TX",
IsActive = true,
IsDeleted = false,
Company = company
},
new Vendor
{
CompanyName = "Canonical Co",
ContactName = "Technician Email",
Email = "technician@canonical.example",
IsActive = true,
IsDeleted = false,
Company = company
},
new Vendor
{
CompanyName = "Legacy Co",
ContactName = "Unlinked Technician",
Email = "legacy@example.com",
City = "Austin",
State = "TX",
IsActive = true,
IsDeleted = false,
CompanyId = null
});
await context.SaveChangesAsync();
var service = new VendorDataService(context);
var (items, totalCount) = await service.GetDirectoryPagedAsync(1, 50, isActive: true);
totalCount.Should().Be(3);
var companyFallback = items.Single(i => i.ContactName == "Company Fallback");
companyFallback.Email.Should().Be("dispatch@canonical.example");
companyFallback.City.Should().Be("Chicago");
companyFallback.State.Should().Be("IL");
var technicianEmail = items.Single(i => i.ContactName == "Technician Email");
technicianEmail.Email.Should().Be("technician@canonical.example");
technicianEmail.City.Should().Be("Chicago");
technicianEmail.State.Should().Be("IL");
var legacy = items.Single(i => i.ContactName == "Unlinked Technician");
legacy.Email.Should().Be("legacy@example.com");
legacy.City.Should().Be("Austin");
legacy.State.Should().Be("TX");
}
[Fact]
public async Task GetDirectoryPagedAsync_SearchAndLocationFilterUseCanonicalCompanyLocation()
{
await using var context = NewContext();
var company = new VendorCompany
{
Name = "Searchable Co",
NormalizedName = "searchable co",
City = "Chicago",
State = null
};
context.VendorCompanies.Add(company);
context.Vendors.Add(new Vendor
{
CompanyName = "Searchable Co",
ContactName = "Pat",
City = "Stale City",
State = "TX",
IsActive = true,
IsDeleted = false,
Company = company
});
await context.SaveChangesAsync();
var service = new VendorDataService(context);
var search = await service.GetDirectoryPagedAsync(1, 50, search: "chicago", isActive: true);
var location = await service.GetDirectoryPagedAsync(
1,
50,
isActive: true,
locations: new[] { "Chicago" });
var searchRow = search.Items.Should().ContainSingle(i => i.ContactName == "Pat").Subject;
searchRow.City.Should().Be("Chicago");
searchRow.State.Should().BeNull();
var locationRow = location.Items.Should().ContainSingle(i => i.ContactName == "Pat").Subject;
locationRow.City.Should().Be("Chicago");
locationRow.State.Should().BeNull();
}
[Theory]
[InlineData("trade")]
[InlineData("location")]

View file

@ -191,13 +191,25 @@ namespace SeaHaven.DataServices.Implementation
CompanyId = v.CompanyId ?? 0,
CompanyName = v.CompanyName,
ContactName = v.ContactName,
Email = v.Email,
Email = v.Email != null && v.Email.Trim() != ""
? v.Email
: v.Company != null
? v.Company.Email
: v.Email,
Phone = v.Phone,
CompanyPhone = v.CompanyPhone,
PreferredContact = v.PreferredContact,
Address = v.Address,
City = v.City,
State = v.State,
City = v.Company != null &&
((v.Company.City != null && v.Company.City.Trim() != "") ||
(v.Company.State != null && v.Company.State.Trim() != ""))
? v.Company.City
: v.City,
State = v.Company != null &&
((v.Company.City != null && v.Company.City.Trim() != "") ||
(v.Company.State != null && v.Company.State.Trim() != ""))
? v.Company.State
: v.State,
Zip = v.Zip,
TradeSpecialties = v.TradeSpecialties,
GoogleMapsUrl = v.GoogleMapsUrl,