price fix for app

This commit is contained in:
2026-09-03 15:08:22 +05:30
parent 350eb8f29c
commit 5345809951
5 changed files with 90 additions and 9 deletions

View File

@@ -41,7 +41,10 @@ may carry only the master. `effectivePrice` already resolves that, and publish
has to use the same resolution or it would "fill in" a price that exists.
*/
test('the master price counts as having a price', () => {
const plan = planPublish([product(1, 0, 175)], { price: 99, taxpercent: 0 });
// Two products, because this is the BATCH rule: with one, the typed figure
// is an edit of that product and wins by design. The behaviour under test —
// that retailprice counts as "has a price" — is unchanged.
const plan = planPublish([product(1, 0, 175), product(2, 0)], { price: 99, taxpercent: 0 });
assert.equal(plan[0]?.price, 175);
});
@@ -53,10 +56,49 @@ test('tax follows the same rule as price', () => {
// Zero is a real tax rate and must survive, not fall through to the fallback.
test('a tax rate of zero is kept, not treated as missing', () => {
const plan = planPublish([product(1, 100, 0, 0)], { price: 0, taxpercent: 18 });
// Zero-rated goods are real — unpackaged staples are 0% GST — so 0 must not
// be read as "no tax set". Batch context, as above.
const plan = planPublish([product(1, 100, 0, 0), product(2, 100)], { price: 0, taxpercent: 18 });
assert.equal(plan[0]?.taxpercent, 0);
});
test('only the unpriced products are counted as needing one', () => {
assert.equal(needingPrice([product(1, 395), product(2, 0), product(3, 0, 88)]).length, 1);
});
/*
Changing a price that already exists.
`own > 0 ? own : typed` protected a bulk release — seventeen imported products
must not all take one typed figure — but it also made "Change price" impossible:
the dialog sent the product's existing price straight back, so a price could be
set once and never corrected.
One product is an edit of that product. Several is a release of a batch. The two
need opposite defaults, and these tests pin both.
*/
test('one product takes the typed price, even when it already has one', () => {
const [line] = planPublish([product(7, 395)], { price: 250, taxpercent: 5 });
assert.equal(line?.price, 250);
});
test('one product takes the typed tax too', () => {
const [line] = planPublish([product(7, 395)], { price: 250, taxpercent: 12 });
assert.equal(line?.taxpercent, 12);
});
test('a batch still protects the prices it already has', () => {
// The failure this guards: ₹395 rice, ₹30 crisps and ₹105 cleaner released
// together, all set to whichever figure prefilled from the first.
const lines = planPublish(
[product(1, 395), product(2, 30), product(3, 105)],
{ price: 999, taxpercent: 5 },
);
assert.deepEqual(lines.map((line) => line.price), [395, 30, 105]);
});
test('a batch still fills in the ones with no price', () => {
const lines = planPublish([product(1, 395), product(2, 0)], { price: 60, taxpercent: 5 });
assert.deepEqual(lines.map((line) => line.price), [395, 60]);
});