feat: structured salary fields (min/max/currency/period)
Adds SalaryMin/SalaryMax/SalaryCurrency/SalaryPeriod alongside the existing free-text Salary field (kept for back-compat and display). - JobApplication model + idempotent column bridging for SQLite and MySQL - Create/Update DTOs with NormalizeSalary (clamps negatives, swaps inverted min/max, uppercases currency, whitelists period) - JobApplicationDto exposes the fields; CSV export gains 4 columns - UI: add/edit dialogs get min/max/currency/period inputs; job table renders a formatted range via shared salary.ts formatter (falls back to free-text when structured values are absent) - EN/NB translations; backend + full frontend suites green Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,115 @@ public sealed class JobApplicationsEndpointBehaviorTests
|
||||
Assert.Contains("Profile page", badRequest.Value?.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Create_normalizes_structured_salary()
|
||||
{
|
||||
await using var db = CreateDb();
|
||||
var company = new Company { Name = "Acme", OwnerUserId = "user-1" };
|
||||
db.Companies.Add(company);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var controller = CreateController(db, "user-1");
|
||||
var request = new JobApplicationsController.CreateJobApplicationRequest(
|
||||
JobTitle: "Backend Dev",
|
||||
CompanyId: company.Id,
|
||||
Status: null,
|
||||
Location: null,
|
||||
Salary: "60-70k",
|
||||
SalaryMin: 70000m, // min > max on purpose: normalization swaps them
|
||||
SalaryMax: 60000m,
|
||||
SalaryCurrency: " nok ",
|
||||
SalaryPeriod: "YEAR",
|
||||
NextAction: null,
|
||||
FollowUpAt: null,
|
||||
Notes: null,
|
||||
Description: null,
|
||||
TranslatedDescription: null,
|
||||
DescriptionLanguage: null,
|
||||
Tags: null,
|
||||
Deadline: null,
|
||||
CoverLetterText: null,
|
||||
JobUrl: null,
|
||||
DateApplied: null,
|
||||
FeedbackRequestedAt: null,
|
||||
HasResume: null,
|
||||
HasCoverLetter: null,
|
||||
HasPortfolio: null,
|
||||
HasOtherAttachment: null);
|
||||
|
||||
var result = await controller.Create(request, CancellationToken.None);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var saved = await db.JobApplications.FirstAsync();
|
||||
Assert.Equal(60000m, saved.SalaryMin);
|
||||
Assert.Equal(70000m, saved.SalaryMax);
|
||||
Assert.Equal("NOK", saved.SalaryCurrency);
|
||||
Assert.Equal("year", saved.SalaryPeriod);
|
||||
Assert.Equal("60-70k", saved.Salary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Update_drops_invalid_salary_period_and_negative_values()
|
||||
{
|
||||
await using var db = CreateDb();
|
||||
var company = new Company { Name = "Acme", OwnerUserId = "user-1" };
|
||||
db.Companies.Add(company);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var job = new JobApplication
|
||||
{
|
||||
JobTitle = "Backend Dev",
|
||||
CompanyId = company.Id,
|
||||
OwnerUserId = "user-1",
|
||||
SalaryMin = 50000m,
|
||||
SalaryMax = 60000m,
|
||||
SalaryCurrency = "NOK",
|
||||
SalaryPeriod = "year",
|
||||
};
|
||||
db.JobApplications.Add(job);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var controller = CreateController(db, "user-1");
|
||||
var request = new JobApplicationsController.UpdateJobApplicationRequest(
|
||||
JobTitle: "Backend Dev",
|
||||
CompanyId: company.Id,
|
||||
Status: "Applied",
|
||||
ResponseReceived: false,
|
||||
ResponseDate: null,
|
||||
Location: null,
|
||||
Salary: null,
|
||||
SalaryMin: -5m,
|
||||
SalaryMax: null,
|
||||
SalaryCurrency: "",
|
||||
SalaryPeriod: "fortnight",
|
||||
NextAction: null,
|
||||
FollowUpAt: null,
|
||||
HasResume: null,
|
||||
HasCoverLetter: null,
|
||||
HasPortfolio: null,
|
||||
HasOtherAttachment: null,
|
||||
Notes: null,
|
||||
Description: null,
|
||||
TranslatedDescription: null,
|
||||
DescriptionLanguage: null,
|
||||
Tags: null,
|
||||
Deadline: null,
|
||||
CoverLetterText: null,
|
||||
JobUrl: null,
|
||||
DateApplied: null,
|
||||
FeedbackRequestedAt: null,
|
||||
StatusChangedAt: null);
|
||||
|
||||
var result = await controller.Update(job.Id, request, CancellationToken.None);
|
||||
|
||||
Assert.IsType<NoContentResult>(result);
|
||||
var saved = await db.JobApplications.FirstAsync();
|
||||
Assert.Null(saved.SalaryMin);
|
||||
Assert.Null(saved.SalaryMax);
|
||||
Assert.Null(saved.SalaryCurrency);
|
||||
Assert.Null(saved.SalaryPeriod);
|
||||
}
|
||||
|
||||
private static JobApplicationsController CreateController(JobTrackerContext db, string userId)
|
||||
{
|
||||
var summarizer = new Mock<ISummarizerService>();
|
||||
|
||||
Reference in New Issue
Block a user