---
id: TST-COM-ORD-129
title: CreditForUnits
kind: unit
product_area: commerce
module: orders
revision: 1
status: draft
source_sha:
  services-commerce: c8b66a98e2490617aec38ba5c8165dd9bd0a8f9b
repository: services-commerce
files:
  - modules/orders/tests/unit/billing/line-credits.spec.js
implements: []
environment: mock
implementation_state: implemented
latest_result: not-run
latest_run_at: null
latest_run_ref: null
conformance: not-verified
estimated_minutes: 1
isolation: 'The suite owns its in-memory inputs, scripted responses and rendered component state.'
evidence:
  - provenance: test
    source: 'services-commerce:modules/orders/tests/unit/billing/line-credits.spec.js'
    test_cases:
      - roundTax
      - 'credits the net 42500, not the list price, with a tax share of 0 while the line carries none'
      - credits 42500 + 3188 when the line carries J1’s 7.5% tax
      - credits 9000 for line 2
      - 'credits 18000 for the rest, 27000 in all, what was paid'
      - credits 675 then 1350 of the 7.5% tax
      - 'credits 2000, 4000 and 2000, summing to the net 8000'
      - leaves the line and its allocations untouched
      - 'A: the full memo after a $20 goodwill refund is still 8000 + 600; the refund’s cap is Accounting’s'
      - >-
        B: cancelling one of three $100 lines with $30 off and 7.5% tax credits 9000 + 675 = 9675, leaving
        19350 of 29025
      - 'C: quantity 2 at $100 with $10 off each unit credits 9000, then the residual 9000'
      - 'D: quantity 4 at $25 with 20% off credits 2000, 4000, then the residual 2000'
      - 'E: a $200 line after two stacked promotions (2000, 2700) credits 15300 in full'
      - 'F: lines of $100, $50 and $25 with 1714/857/429 off credit 2071, 4143 and 8286, summing to 14500'
      - 'rounds a half up: one of two units of a net of 5 credits 3, the last 2'
      - >-
        rounds the tax share by the same fraction and leaves the last unit the residual: 7 over 3 units is 2,
        2, 3
      - >-
        never credits more than the net when the halves round up one unit at a time: 100 units of a net of 50
        sum to 50
      - says which credit takes the last unit
      - throws for a credit of no unit
      - throws for more units than are left to credit
      - throws for more already credited than the line’s net
      - throws for more tax already credited than the line’s tax
      - 'answers Accounting’s memo line for J6: the invoice line, quantity 1, 42500 + 3188 in USD'
      - 'answers J8’s second credit: two units, 4000'
      - 'refuses a line not yet invoiced, 409 line_not_invoiced'
      - 'reads the net 9000 for original_price, what the customer agreed to pay'
      - 'takes the current standard price 12000 for standard_price, though it is more than was paid'
      - 'takes what was funded for paid_amount: 4000 paid and 1000 credited is 5000'
      - 'never takes more than the net for paid_amount: 9000 paid and 2000 credited is 9000'
      - throws for a negative standard price
      - >-
        carries the original tax × unused ÷ the line’s value: half of $300.00 at 8.25 % is $12.38, the half
        rounded away from zero
      - 'rounds a share below the half down, and takes the whole tax for the whole value'
      - >-
        carries nothing for an untaxed line, a line of no value or nothing unused, and never more than the
        line’s tax
      - 'throws for an unused value that is not a whole, non-negative amount'
      - holds a memo to what Accounting invoiced on the line when Commerce’s share is more
      - holds a memo to what the line still owes after earlier memos
      - leaves a memo within the invoiced line as it was
      - answers nothing to credit for a line already credited in full
      - leaves the share as it was for a line Accounting’s view does not know
      - finds the order’s tax line when it is billed
      - finds none for an order without a tax line (the accounting-tax provider)
      - finds none for a tax line not billed yet
      - gives a whole seat’s tax back when its only unit goes
      - 'gives the three seats’ tax back, 2025, when every seat goes'
      - gives the proportional tax of a partial cancellation of one line of three units
      - gives the rest of the tax when the last unit goes after one was cancelled
      - holds the tax memo to what the tax line still owes
scenario_coverage: []
dependency_evidence:
  provenance: test
  source: 'services-commerce:modules/orders/tests/unit/billing/line-credits.spec.js'
  declared_by_test: 'the functions, the shared money rounding. Doubled: nothing (the inputs are literals).'
---

# CreditForUnits

## Verification Boundary

The unit suite checks the named contract or helper with controlled inputs.

## What This Suite Proves

The registered cases check creditForUnits with their fixture records and assertions. Scenario bindings name only the examples those cases exercise.

## What It Does Not Prove

A registered file supplies no run result or verified conformance by itself. Local fixtures do not establish deployed cross-service behavior or complete browser journeys.

## Real Dependencies and Test Doubles

Inputs and external responses are controlled in process; this suite establishes no deployed service behavior.

## Must Not Be Doubled

The named contract validation or component behavior under assertion must use its actual implementation.
