---
id: TST-ACC-TRX-131
title: Write offs suite
kind: integration
product_area: accounting
module: transactions
revision: 1
status: draft
source_sha:
  services-accounting: f47cb263875bbc0c5640fba7dae6785ec32695f8
repository: services-accounting
files:
  - >-
    modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js
implements:
  - ATS-ACC-TRX-004-01
  - ATS-ACC-TRX-004-02
  - ATS-ACC-TRX-004-03
  - ATS-ACC-TRX-004-04
implements_parts:
  - scenario: ATS-ACC-TRX-004-01
    assertion: it is refused 409 invoice_not_draft
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      is refused 409 invoice_not_draft
  - scenario: ATS-ACC-TRX-004-01
    assertion: it is refused 400 over_application
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      is refused 400 over_application
  - scenario: ATS-ACC-TRX-004-01
    assertion: 'it writes nothing: no write-off, no ledger line, no fact, no event'
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      writes nothing: no write-off, no ledger line, no fact, no event
  - scenario: ATS-ACC-TRX-004-02
    assertion: >-
      it makes the whole line written_off and keeps the partly written-off line
      and the invoice open
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      makes the whole line written_off and keeps the partly written-off line and
      the invoice open
  - scenario: ATS-ACC-TRX-004-02
    assertion: it makes the header written_off once the rest is written off
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      makes the header written_off once the rest is written off
  - scenario: ATS-ACC-TRX-004-03
    assertion: >-
      it takes the unit’s default_write_off_method (direct) when the request
      names none
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      takes the unit’s default_write_off_method (direct) when the request names
      none
  - scenario: ATS-ACC-TRX-004-03
    assertion: >-
      it accepts an allowance write-off naming no account: the unit’s allowance
      default serves when it posts (gl-at-posting)
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      accepts an allowance write-off naming no account: the unit’s allowance
      default serves when it posts (gl-at-posting)
  - scenario: ATS-ACC-TRX-004-03
    assertion: it refuses another unit’s account 400 business_unit_mismatch
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      refuses another unit’s account 400 business_unit_mismatch
  - scenario: ATS-ACC-TRX-004-03
    assertion: it refuses a direct write-off naming an allowance account 400
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      refuses a direct write-off naming an allowance account 400
  - scenario: ATS-ACC-TRX-004-04
    assertion: >-
      it answers the reversal: a second write-off, numbered next, its lines
      negating the first’s
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      answers the reversal: a second write-off, numbered next, its lines
      negating the first’s
  - scenario: ATS-ACC-TRX-004-04
    assertion: it restores the invoice exactly
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      restores the invoice exactly
  - scenario: ATS-ACC-TRX-004-04
    assertion: it refuses reversing the first again 409 stale
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      refuses reversing the first again 409 stale
  - scenario: ATS-ACC-TRX-004-04
    assertion: it refuses reversing the reversal 409
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js#it
      refuses reversing the reversal 409
environment: local
implementation_state: implemented
latest_result: not-run
latest_run_at: null
latest_run_ref: null
conformance: not-verified
estimated_minutes: 3
isolation: >-
  Suite-marked records in the prepared local test database; fixture teardown
  removes owned records.
provenance: test
source: >-
  services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js
evidence:
  - provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/write-offs/write-offs.integration.spec.js
    assertion_titles:
      - write-offs (integration)
      - on a draft invoice
      - is refused 409 invoice_not_draft
      - 'writing off a line’s whole balance, and part of the other'
      - >-
        answers the write-off whole: issued, numbered from 1,000,000, direct,
        its lines and total
      - >-
        makes the whole line written_off and keeps the partly written-off line
        and the invoice open
      - >-
        writes a write_off fact of minus each line’s amount, dated the
        accounting date
      - records the create as the write-off’s document event
      - leaves the as-of read of the facts equal to the live balance
      - makes the header written_off once the rest is written off
      - writing off more than a line owes
      - is refused 400 over_application
      - 'writes nothing: no write-off, no ledger line, no fact, no event'
      - leaves the invoice as issued
      - the allowance method
      - keeps the allowance account it names
      - refuses another unit’s account 400 business_unit_mismatch
      - >-
        accepts an allowance write-off naming no account: the unit’s allowance
        default serves when it posts (gl-at-posting)
      - refuses a direct write-off naming an allowance account 400
      - >-
        takes the unit’s default_write_off_method (direct) when the request
        names none
      - reversing a write-off
      - read the as-of balance equal to the live one while the write-off stood
      - >-
        answers the reversal: a second write-off, numbered next, its lines
        negating the first’s
      - restores the invoice exactly
      - 'marks the first reversed, with the instant and the caller'
      - >-
        writes a write_off_reversed fact of plus each line’s amount, on the
        reversal
      - records the reverse on the first and the create on the reversal
      - leaves the as-of read of the facts equal to the live balance
      - refuses reversing the first again 409 stale
      - refuses reversing the reversal 409
      - a replay
      - answers the first write-off
      - 'answers the first reversal to the same reverse again, writing nothing'
      - wrote only the reversal between the replayed create and the reverse
    imports:
      - 'const { expect } = require(''chai'');'
      - 'const { stage } = require(''@rhythmsoftware/macroservice-testing/stage'');'
      - >-
        const { ready, testId } =
        require('../../../../../books/tests/integration/support');
      - >-
        const { createWriteOff, reverseWriteOff } =
        require('../../../../services/write-offs/write-off-commands');
      - >-
        const { getWriteOff } =
        require('../../../../services/write-offs/write-off-reads');
      - '} = require(''../../memos-fixtures'');'
      - "\t\t\tworld.require();"
      - "\t\t\tworld.require();"
      - "\t\t\tconst { invoice, answer } = written.require();"
      - "\t\t\texpect(await balancesOf(TENANT, written.require().invoice.id)).to.deep.equal({"
      - "\t\t\tconst { invoice, answer } = written.require();"
      - "\t\t\t\t(await eventsOf(TENANT, written.require().answer.id)).map((event) => ["
      - "\t\t\texpect(await asOfAndLive(TENANT, written.require().invoice.id)).to.deep.equal({ as_of: 5000, live: 5000 });"
      - "\t\t\tconst { invoice } = written.require();"
      - "\t\t\tworld.require();"
      - "\t\t\texpect(refusalShapeOf(attempt.require().refusal)).to.include({ name: 'InvalidRequestError', code: 'over_application' });"
      - "\t\t\tconst { before, after } = attempt.require();"
      - "\t\t\texpect(await balancesOf(TENANT, attempt.require().invoice.id)).to.deep.equal(OPEN_INVOICE);"
      - "\t\t\tworld.require();"
      - "\t\t\t\twriteOffRequest(invoice.require(), 'wo-allowance-1', [[0, 1000]], {"
      - "\t\t\t\t\twriteOffRequest(invoice.require(), 'wo-allowance-2', [[0, 1000]], {"
      - "\t\t\tconst answer = await writeOff(writeOffRequest(invoice.require(), 'wo-allowance-3', [[0, 1000]], { method: 'allowance' }));"
      - "\t\t\t\t\twriteOffRequest(invoice.require(), 'wo-allowance-4', [[0, 1000]], {"
      - "\t\t\tconst answer = await writeOff(writeOffRequest(invoice.require(), 'wo-allowance-5', [[0, 1000]], { method: null }));"
      - "\t\t\tworld.require();"
      - "\t\t\texpect(reversed.require().written).to.deep.equal({ as_of: 5000, live: 5000 });"
      - "\t\t\tconst { original, reversal, invoice } = reversed.require();"
      - "\t\t\texpect(await balancesOf(TENANT, reversed.require().invoice.id)).to.deep.equal(OPEN_INVOICE);"
      - "\t\t\tconst first = await getWriteOff(ctxFor(TENANT), reversed.require().original.id);"
      - "\t\t\tconst { reversal } = reversed.require();"
      - "\t\t\tconst { original, reversal } = reversed.require();"
      - "\t\t\texpect(await asOfAndLive(TENANT, reversed.require().invoice.id)).to.deep.equal({ as_of: 20000, live: 20000 });"
      - "\t\t\tconst refusal = await refusalOf(reverse(reversed.require().original.id, 'wo-reverse-3'));"
      - "\t\t\tconst { original, reversal } = reversed.require();"
      - "\t\t\tworld.require();"
      - "\t\t\tconst { first, again } = replay.require();"
      - "\t\t\tconst { reversal, reversalAgain, after, afterSecond } = replay.require();"
      - "\t\t\tconst { before, after } = replay.require();"
    test_double_declarations: []
---

# Write offs suite

## Verification Boundary

The suite exercises transaction commands and database protections in the local prepared test environment. Registration records the existing executable file; it does not report a run or establish product approval.

## What This Suite Proves

Its cited assertions contribute evidence for write-off cannot exceed eligible debt; partial abandonment retains remaining debt; write-off policy controls method and account; an opposing write-off restores debt once. The structured assertion bindings identify which parts of combined scenarios it executes.

## What It Does Not Prove

Local commands and route invocations do not establish deployed routing, live processor guarantees or the complete staff browser experience. An unbound feature chain remains proposed, and this registration carries no execution result.

## Real Dependencies and Test Doubles

The suite uses the imported commands, route handlers or persistence code against the local test database. Fixture helpers supply accounting context; any stepped clock, dummy processor or substituted external client is retained in the evidence declarations.

## Must Not Be Doubled

The command or persistence behavior under assertion and its relevant database protections must remain real. Substituting the final financial result removes evidence of transactional effects.
