97 lines
4.5 KiB
C#
97 lines
4.5 KiB
C#
using NTP.Application.Common;
|
|
using NTP.Application.Refinery.WageClaims;
|
|
|
|
namespace NTP.Tests.Refinery;
|
|
|
|
public class WageClaimRulesTests
|
|
{
|
|
[Fact]
|
|
public void Trip_statuses_keep_only_the_claimable_ones()
|
|
{
|
|
var r = WageClaimRules.NormalizeTripStatuses(["ALL", "exchanged", "EXCHANGED,READY_TO_PAY", "RVKD", " discharged "]);
|
|
Assert.Equal(["EXCHANGED", "READY_TO_PAY", "DISCHARGED"], r);
|
|
Assert.Empty(WageClaimRules.NormalizeTripStatuses(null));
|
|
Assert.Empty(WageClaimRules.NormalizeTripStatuses(["ALL"]));
|
|
}
|
|
|
|
[Fact]
|
|
public void Create_validation_follows_the_legacy_order_and_texts()
|
|
{
|
|
var ok = new[] { "EXCHANGED" };
|
|
var from = new DateOnly(2024, 3, 1);
|
|
var to = new DateOnly(2024, 3, 31);
|
|
|
|
Assert.Equal("يجب اختيار الحالة", Assert.Throws<BusinessException>(() => WageClaimRules.ValidateCreate([], null, null)).Message);
|
|
Assert.Equal("يجب اختيار التاريخ", Assert.Throws<BusinessException>(() => WageClaimRules.ValidateCreate(ok, from, null)).Message);
|
|
Assert.Equal("يجب اختيار التاريخ", Assert.Throws<BusinessException>(() => WageClaimRules.ValidateCreate(ok, null, to)).Message);
|
|
Assert.Equal("لا يجوز ان يكون تاريخ من أكبر من تارخ الى", Assert.Throws<BusinessException>(() => WageClaimRules.ValidateCreate(ok, to, from)).Message);
|
|
WageClaimRules.ValidateCreate(ok, from, from); // same day is fine
|
|
WageClaimRules.ValidateCreate(ok, from, to);
|
|
}
|
|
|
|
[Fact]
|
|
public void Claim_closes_only_when_it_has_trips_and_all_are_exchanged()
|
|
{
|
|
Assert.True(WageClaimRules.CanCloseClaim(["EXCHANGED", "EXCHANGED"]));
|
|
Assert.False(WageClaimRules.CanCloseClaim([]));
|
|
Assert.False(WageClaimRules.CanCloseClaim(["EXCHANGED", "DISCHARGED"]));
|
|
Assert.False(WageClaimRules.CanCloseClaim(["READY_TO_PAY"]));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Status Updated successfully To 7", true)]
|
|
[InlineData("OK: status updated SUCCESSFULLY to 7 for 123", true)]
|
|
[InlineData("Status Updated successfully To 6", false)]
|
|
[InlineData("", false)]
|
|
[InlineData(null, false)]
|
|
public void Jopetrol_answer_is_matched_like_findNoCase(string? answer, bool expected) =>
|
|
Assert.Equal(expected, WageClaimRules.IsStatus7Success(answer));
|
|
|
|
[Fact]
|
|
public void Loading_date_range_ends_at_the_end_of_the_last_day()
|
|
{
|
|
// legacy: between 'yyyymmdd000000' and 'yyyymmdd235959'
|
|
Assert.Equal(new DateTime(2024, 4, 1), WageClaimRules.ExclusiveEnd(new DateOnly(2024, 3, 31)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Report_line_shows_deductions_negative_like_the_legacy_report()
|
|
{
|
|
var line = WageClaimRules.ToReportLine(new WageClaimReportRaw
|
|
{
|
|
NetLoadingWeight = 30000, NetDischargeWeight = 29900, ToleranceQuantity = 150, PenaltyQuantity = 12, WaterAmount = 0,
|
|
DriverTip = 1.5m, PermitDispatch = 2, WaybillFee = 3, DieselLiterPrice = 0.8m, AdvancePaymentForDiesel = 280, Commission = 4, NetWage = 100,
|
|
});
|
|
Assert.Equal(100m, line.WeightDifference);
|
|
Assert.Equal(0m, line.PenaltyQuantity); // difference below the tolerance: no penalty
|
|
Assert.False(line.WaterExist);
|
|
Assert.Equal([-1.5m, -2m, -3m, -0.8m, -280m, -4m], [line.DriverTip, line.PermitDispatch, line.WaybillFee, line.DieselLiterPrice, line.AdvancePaymentForDiesel, line.Commission]);
|
|
Assert.Equal(100m, line.NetWage);
|
|
}
|
|
|
|
[Fact]
|
|
public void Report_line_keeps_the_penalty_above_the_tolerance_and_a_missing_diesel_advance()
|
|
{
|
|
var line = WageClaimRules.ToReportLine(new WageClaimReportRaw
|
|
{
|
|
NetLoadingWeight = 30000, NetDischargeWeight = 29700, ToleranceQuantity = 150, PenaltyQuantity = 150, WaterAmount = 20, AdvancePaymentForDiesel = null,
|
|
});
|
|
Assert.Equal(300m, line.WeightDifference);
|
|
Assert.Equal(150m, line.PenaltyQuantity);
|
|
Assert.True(line.WaterExist);
|
|
Assert.Equal(0m, line.AdvancePaymentForDiesel);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("NEW", "جديد")]
|
|
[InlineData("CLOSE", "تم التسديد")]
|
|
[InlineData("COMPLETE", "مكتمل")]
|
|
public void Claim_status_captions(string code, string caption) => Assert.Equal(caption, WageClaimRules.ClaimStatusCaption(code));
|
|
|
|
[Fact]
|
|
public void Log_json_keeps_arabic_unescaped()
|
|
{
|
|
Assert.Equal("{\"STATUS_CODE\":\"تم التسديد\"}", ClaimLogJson.Status("تم التسديد"));
|
|
}
|
|
}
|