workbuddy 0.1.41: a package with no cycle total reads as a wallet balance (#450)
A WorkBuddy package with no CycleTotalCapacity is a prepaid wallet: it is sent as a balance window ("Prepaid credits", magpie#3950), beside the share of packages that have a total. A literal "0" total stays on the old path, so a lapsed package adds nothing; an account with no packages keeps its unknown allowance (no TotalCredits fallback).
Reviewed at 5bdfa9048d66095d35af5e7955d0945db02dc3b5 over four rounds. Run on mote at that head: HOME=$(mktemp -d) bun test packages/workbuddy, 185 pass / 0 fail; bun scripts/check.mjs workbuddy ok. npm had 0.1.40, so 0.1.41 is free.
Co-authored-by: MYCF711 <MYCF711@users.noreply.github.com>
This commit is contained in:
@@ -78,6 +78,36 @@ test("counts and plans as Go says them", () => {
|
||||
expect(() => _internal.usageOf({ Packages: [{ CycleTotalCapacity: "lots" }] })).toThrow('strconv.ParseFloat: parsing "lots": invalid syntax')
|
||||
})
|
||||
|
||||
test("a prepaid credit package with no total is a balance reading (#3950)", () => {
|
||||
expect(_internal.usageOf({ IsPaidUser: false, Packages: [{ CycleTotalCapacity: "", CycleUsedCapacity: "", CycleRemainCapacity: "750" }] }, ""))
|
||||
.toEqual({ plan: "Free plan", windows: [{ name: "Prepaid credits", balance: 750, display: "750 credits", unit: "credits" }] })
|
||||
// a literal "0" is a reading of nothing left, not an absent field
|
||||
expect(_internal.usageOf({ Packages: [{ CycleTotalCapacity: "", CycleRemainCapacity: "0" }] }, ""))
|
||||
.toEqual({ plan: "Free plan", windows: [{ name: "Prepaid credits", balance: 0, display: "0 credits", unit: "credits" }] })
|
||||
// no remainder field at all: unknown, not a balance
|
||||
expect(_internal.usageOf({ Packages: [{ CycleTotalCapacity: "", CycleRemainCapacity: "" }] }, ""))
|
||||
.toEqual({ plan: "Free plan", windows: [] })
|
||||
// a "0" total is still a total (a lapsed or placeholder package): old path,
|
||||
// no balance reading, so the account stays unknown as on main
|
||||
expect(_internal.usageOf({ Packages: [{ CycleTotalCapacity: "0", CycleRemainCapacity: "0" }] }, ""))
|
||||
.toEqual({ plan: "Free plan", windows: [] })
|
||||
// one package with a total and one without: the latter keeps its own reading
|
||||
expect(_internal.usageOf({ Packages: [
|
||||
{ CycleTotalCapacity: "1000", CycleUsedCapacity: "100" },
|
||||
{ CycleTotalCapacity: "", CycleRemainCapacity: "750" },
|
||||
] }, ""))
|
||||
.toEqual({ plan: "Free plan", windows: [
|
||||
{ name: "Credits", used: 10, display: "100 / 1000", amount: 100, limit: 1000, unit: "credits" },
|
||||
{ name: "Prepaid credits", balance: 750, display: "750 credits", unit: "credits" },
|
||||
] })
|
||||
// TotalCredits alone is not a reading: an account with no packages stays
|
||||
// unknown, so its free models are not skipped
|
||||
expect(_internal.usageOf({ Packages: [], TotalCredits: "120" }, ""))
|
||||
.toEqual({ plan: "Free plan", windows: [] })
|
||||
expect(_internal.usageOf({ Packages: [], TotalCredits: "0" }, ""))
|
||||
.toEqual({ plan: "Free plan", windows: [] })
|
||||
})
|
||||
|
||||
test("WorkBuddy's refusals are the card's error", async () => {
|
||||
const auth = { type: "oauth", access: "a", expires: later(), uid: "u" }
|
||||
// a bare 401 (no invalid_token) with nothing to renew with: said, not marked
|
||||
|
||||
Reference in New Issue
Block a user