---
id: TST-ACC-TRX-052
title: Idempotency 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/invoices/idempotency.integration.spec.js
implements:
  - ATS-ACC-TRX-020-03
  - ATS-ACC-TRX-020-04
  - ATS-ACC-TRX-020-05
  - ATS-ACC-TRX-001-18
implements_parts:
  - scenario: ATS-ACC-TRX-020-03
    assertion: 'it replays the issue’s first answer, the same number'
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      replays the issue’s first answer, the same number
  - scenario: ATS-ACC-TRX-020-03
    assertion: it appends the issue’s facts once
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      appends the issue’s facts once
  - scenario: ATS-ACC-TRX-020-03
    assertion: it refuses the second request 409 idempotency_key_reused
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      refuses the second request 409 idempotency_key_reused
  - scenario: ATS-ACC-TRX-020-03
    assertion: 'it is free again: the retry under the same key with another batch runs'
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      is free again: the retry under the same key with another batch runs
  - scenario: ATS-ACC-TRX-020-04
    assertion: >-
      it refuses the second person 409 idempotency_key_in_use, never an
      unhandled error (DEF-ACT-0800)
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      refuses the second person 409 idempotency_key_in_use, never an unhandled
      error (DEF-ACT-0800)
  - scenario: ATS-ACC-TRX-020-05
    assertion: it answers both with the one draft
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      answers both with the one draft
  - scenario: ATS-ACC-TRX-020-05
    assertion: it issues the invoice once and refuses the other issue invoice_not_draft
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      issues the invoice once and refuses the other issue invoice_not_draft
  - scenario: ATS-ACC-TRX-020-05
    assertion: it appends one set of facts
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      appends one set of facts
  - scenario: ATS-ACC-TRX-001-18
    assertion: it issues the invoice once and refuses the other issue invoice_not_draft
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      issues the invoice once and refuses the other issue invoice_not_draft
  - scenario: ATS-ACC-TRX-001-18
    assertion: it appends one set of facts
    provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js#it
      appends one set of facts
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/invoices/idempotency.integration.spec.js
evidence:
  - provenance: test
    source: >-
      services-accounting:modules/transactions/tests/integration/services/invoices/idempotency.integration.spec.js
    assertion_titles:
      - the invoice commands under an Idempotency-Key (integration)
      - 'the same key and the same request, twice'
      - replays the create’s first answer
      - creates one invoice under the key
      - 'replays the issue’s first answer, the same number'
      - records one document event per command
      - appends the issue’s facts once
      - the same key and another request
      - refuses the second request 409 idempotency_key_reused
      - names the key and the command in the refusal
      - keeps the one invoice the first request created
      - the same key from another person
      - >-
        refuses the second person 409 idempotency_key_in_use, never an unhandled
        error (DEF-ACT-0800)
      - names the key and the command in the sentence
      - keeps the one invoice the first person created
      - a refused command’s key
      - is refused first for the closed batch (the premise)
      - 'is free again: the retry under the same key with another batch runs'
      - two concurrent creates under one key
      - answers both with the one draft
      - creates one invoice
      - two concurrent issues of one draft under different keys
      - issues the invoice once and refuses the other issue invoice_not_draft
      - records one issue document event
      - appends one set of facts
    imports:
      - 'const { stage } = require(''@rhythmsoftware/macroservice-testing/stage'');'
      - >-
        const { TEST_CLOCK } =
        require('@rhythmsoftware/macroservice-testing/execution-context');
      - >-
        const { ctxIn } =
        require('../../../../../books/tests/integration/support');
      - >-
        const { createDraft } =
        require('../../../../services/invoices/invoice-drafts');
      - >-
        const { issueInvoice } =
        require('../../../../services/invoices/invoice-issue');
      - '} = require(''../../invoices-fixtures'');'
      - "\t\t\tworld.require();"
      - "\t\t\tconst { created, createdAgain } = replaying.require();"
      - "\t\t\treplaying.require();"
      - "\t\t\tconst { issued, issuedAgain } = replaying.require();"
      - "\t\t\tconst { created } = replaying.require();"
      - "\t\t\tconst { created } = replaying.require();"
      - "\t\t\tworld.require();"
      - "\t\t\tconst refusal = reusing.require();"
      - "\t\t\texpect(reusing.require().message).to.equal("
      - "\t\t\treusing.require();"
      - "\t\t\tworld.require();"
      - "\t\t\tconst { refusal } = sharing.require();"
      - "\t\t\texpect(sharing.require().refusal.message).to.equal("
      - "\t\t\tsharing.require();"
      - "\t\t\tworld.require();"
      - "\t\t\texpect(retrying.require().refused.code).to.equal('batch_not_open');"
      - "\t\t\tconst { retried } = retrying.require();"
      - "\t\t\tworld.require();"
      - "\t\t\tconst [first, second] = racing.require();"
      - "\t\t\tracing.require();"
      - "\t\t\tworld.require();"
      - "\t\t\tconst { outcomes } = racing.require();"
      - "\t\t\tconst { target } = racing.require();"
      - "\t\t\tconst { target } = racing.require();"
    test_double_declarations: []
---

# Idempotency 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 retry identity preserves one financial execution; another actor cannot reuse a held key; concurrent requests do not duplicate billing. 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.
