Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/recruiting/economics_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/recruiting/economics_test.go |
| Original SHA-256 | e48b8b790a38afcefa15fe6879370647e9bcbfd4c435f55be37fcd0b0c0c85fa |
| Git blob SHA | 5cce959215d41b6c343241551e30344434f80d48 |
| Reading-copy SHA-256 | e48b8b790a38afcefa15fe6879370647e9bcbfd4c435f55be37fcd0b0c0c85fa |
Recovered source transcript
Download complete source text ↓143 lines · 6.3 KB
package recruiting
import "testing"
// THE ARITHMETIC OF A SPREAD AND A MARGIN, pinned.
//
// These are the numbers from the migration comment, and they are here rather than only there because a
// comment cannot fail. The whole defect this closes was a plausible number nobody checked against a worked
// example.
func TestSpreadAndMarginOnAWorkedExample(t *testing.T) {
// Pay 110, bill 170, a 35 percent wrap. The spread is 60.00 an hour and 35.2941 percent of bill. The
// cost is 148.50 and the margin is 21.50 an hour, 12.6471 percent of bill.
e := economicsOf("contract", amt("170"), amt("110"), nil, nil, nil, amt("0.35"), nil)
if got := e.SpreadPerHour.String(); got != "60" {
t.Fatalf("spread per hour = %s, want 60", got)
}
if got := e.SpreadPct.String(); got != "35.2941" {
t.Fatalf("spread pct = %s, want 35.2941", got)
}
if got := e.CostPerHour.String(); got != "148.5" {
t.Fatalf("cost per hour = %s, want 148.5", got)
}
if got := e.MarginPerHour.String(); got != "21.5" {
t.Fatalf("margin per hour = %s, want 21.5", got)
}
if got := e.MarginPct.String(); got != "12.6471" {
t.Fatalf("margin pct = %s, want 12.6471", got)
}
// THE POINT OF THE WHOLE CHANGE, asserted as an inequality rather than trusted: the two numbers are
// different, and the old code reported the first one as the second.
if e.SpreadPct.Equal(*e.MarginPct) {
t.Fatal("spread and margin came out equal, which means the burden was not applied")
}
if e.Unburdened {
t.Fatal("a line with a wrap reported itself unburdened")
}
}
// CLAUSE A of migration 0086, which is the rule that was written down and never implemented: no wrap means no
// margin may be reported at all.
func TestNoWrapReportsSpreadAndRefusesMargin(t *testing.T) {
e := economicsOf("contract", amt("170"), amt("110"), nil, nil, nil, nil, nil)
if e.SpreadPerHour == nil || e.SpreadPerHour.String() != "60" {
t.Fatal("the spread must still be reported, it needs nothing but the two rates")
}
if e.MarginPerHour != nil || e.MarginPct != nil || e.CostPerHour != nil {
t.Fatalf("a margin was reported with no wrap: %+v", e)
}
if !e.Unburdened {
t.Fatal("the line must SAY it is unburdened, or a missing margin reads as a broken screen")
}
if e.BurdenPct != nil || e.BurdenSource != "" {
t.Fatal("a burden was reported that nobody set")
}
}
// The record wins over the organization default, and the answer says which one it used. Two placements on
// identical rates showing different margins is correct when one carries its own wrap, and inexplicable
// without the source.
func TestRecordBurdenBeatsTheOrgDefaultAndSaysSo(t *testing.T) {
withRecord := economicsOf("contract", amt("170"), amt("110"), nil, nil, nil, amt("0.50"), amt("0.35"))
if withRecord.BurdenSource != BurdenFromRecord {
t.Fatalf("source = %q, want %q", withRecord.BurdenSource, BurdenFromRecord)
}
if got := withRecord.CostPerHour.String(); got != "165" {
t.Fatalf("cost = %s, want 165, the record wrap of 0.50 was not the one applied", got)
}
fromOrg := economicsOf("contract", amt("170"), amt("110"), nil, nil, nil, nil, amt("0.35"))
if fromOrg.BurdenSource != BurdenFromOrg {
t.Fatalf("source = %q, want %q", fromOrg.BurdenSource, BurdenFromOrg)
}
if got := fromOrg.CostPerHour.String(); got != "148.5" {
t.Fatalf("cost = %s, want 148.5", got)
}
}
// A placement sold below its loaded cost is a real and important fact. Clamping it at zero would hide the one
// number an owner most needs to see, so the margin goes negative and is reported that way.
func TestSellingBelowLoadedCostReportsANegativeMargin(t *testing.T) {
// Bill 140 against a pay of 110 at a 35 percent wrap. The spread looks healthy at 30 an hour and the
// placement actually loses 8.50 an hour. This is the exact case the old number concealed.
e := economicsOf("contract", amt("140"), amt("110"), nil, nil, nil, amt("0.35"), nil)
if got := e.SpreadPerHour.String(); got != "30" {
t.Fatalf("spread = %s, want 30", got)
}
if e.MarginPerHour == nil || !e.MarginPerHour.IsNegative() {
t.Fatalf("margin = %v, want a negative number, the loss must not be clamped", e.MarginPerHour)
}
if got := e.MarginPerHour.String(); got != "-8.5" {
t.Fatalf("margin = %s, want -8.5", got)
}
// The database CHECK on placements only refuses bill below PAY. It cannot refuse bill below loaded COST,
// because the cost depends on a wrap the row does not have to carry, so this is the only place the loss
// becomes visible.
}
// A direct hire has no hourly margin because it is not priced by the hour. That is a different fact from a
// contract line whose wrap nobody entered, and the two must not render the same.
func TestDirectHireIsNotMarkedUnburdened(t *testing.T) {
e := economicsOf("direct_hire", nil, nil, amt("150000"), amt("0.20"), nil, nil, nil)
if e.Fee == nil || e.Fee.String() != "30000" {
t.Fatalf("fee = %v, want 30000", e.Fee)
}
if e.Unburdened {
t.Fatal("a direct hire was marked unburdened, which would prompt for a wrap that changes nothing")
}
if e.SpreadPerHour != nil || e.MarginPerHour != nil {
t.Fatal("a direct hire reported hourly numbers")
}
}
// A zero bill rate makes every share of it undefined rather than zero. Rendering 0.00 percent would read as a
// real margin of nothing rather than as an unanswerable question.
func TestZeroBillLeavesEveryPercentageAbsent(t *testing.T) {
e := economicsOf("contract", amt("0"), amt("0"), nil, nil, nil, amt("0.35"), nil)
if e.SpreadPct != nil || e.MarginPct != nil {
t.Fatalf("a percentage of a zero bill rate was reported: %+v", e)
}
// The per hour figures are still real: a zero bill against a zero pay is a zero spread, which is true.
if e.SpreadPerHour == nil {
t.Fatal("the per hour spread should still be present")
}
}
// A wrap of zero is a REAL answer and is not the same as no wrap. A firm that genuinely carries no burden,
// or one that has decided to report on direct labour alone, has told us something, and the margin then equals
// the spread legitimately.
func TestAZeroWrapIsAnAnswerNotAnAbsence(t *testing.T) {
e := economicsOf("contract", amt("170"), amt("110"), nil, nil, nil, amt("0"), nil)
if e.Unburdened {
t.Fatal("a wrap of zero was treated as no wrap at all")
}
if e.MarginPerHour == nil || !e.MarginPerHour.Equal(*e.SpreadPerHour) {
t.Fatal("at a zero wrap the margin should equal the spread")
}
}