---
id: TST-COM-ORD-156
title: 'The purchasing and cost tables (integration, table)'
kind: integration
product_area: commerce
module: orders
revision: 1
status: draft
source_sha:
  services-commerce: c8b66a98e2490617aec38ba5c8165dd9bd0a8f9b
repository: services-commerce
files:
  - modules/purchasing/tests/integration/db/purchasing-tables.table.integration.spec.js
implements: []
environment: local
implementation_state: implemented
latest_result: not-run
latest_run_at: null
latest_run_ref: null
conformance: not-verified
estimated_minutes: 2
isolation: The suite creates its own test workspace records and removes them using the fixture cleanup.
evidence:
  - provenance: test
    source: 'services-commerce:modules/purchasing/tests/integration/db/purchasing-tables.table.integration.spec.js'
    test_cases:
      - 'holds the vendor, its padded name trimmed by the text-normalization trigger (premise)'
      - >-
        refuses an id that is not a configuration id, by vendors_id_configuration_id_check, and an e-mail
        address with a capital or a space, by vendors_email_address_check
      - 'refuses a second vendor with one id, by vendors_pk'
      - >-
        holds an issued order with its line (premise), and refuses a second order with one number, by
        purchase_orders_number_uq
      - >-
        refuses an issued order without its instant and a cancelled one without, by
        purchase_orders_issued_check and purchase_orders_cancelled_check
      - >-
        refuses an order of a vendor the tenant does not have, by purchase_orders_vendor_fk, and a status
        outside the six, by purchase_orders_status_check
      - >-
        refuses more received and cancelled than ordered, by purchase_order_lines_quantities_check, and two
        lines with one number, by purchase_order_lines_number_uq
      - holds received + cancelled = ordered (the line closed in full)
      - 'refuses deleting the vendor the order names (RESTRICT), by purchase_orders_vendor_fk'
      - >-
        holds a receipt with its line (premise), and refuses a second receipt under one key, by
        inventory_receipts_idempotency_key_uq
      - 'refuses a landed cost shared by no method, by inventory_receipts_landed_cost_check'
      - >-
        refuses a line of no units and a condition outside the three, by
        inventory_receipt_lines_quantity_check and inventory_receipt_lines_condition_check
      - >-
        holds a receipt layer naming its line (premise), and refuses a receipt layer without one and a
        movement layer with one, by inventory_cost_layers_receipt_line_check
      - >-
        refuses a remaining quantity outside 0..quantity, by inventory_cost_layers_remaining_check, and a
        negative cost, by inventory_cost_layers_unit_cost_check
      - 'refuses deleting the receipt line a layer names (RESTRICT), by inventory_cost_layers_receipt_line_fk'
      - >-
        holds a relief of two at the layer’s cost (premise), and refuses a total that is not quantity × cost,
        by cost_relief_total_check
      - >-
        refuses a restore that names no reversal or no restored layer, and a relief that names one, by
        cost_relief_reversal_check
      - 'is append-only: the application role cannot update or delete a relief (42501)'
      - >-
        refuses a relief of a layer the tenant does not have, by cost_relief_layer_fk, another tenant’s
        included
      - >-
        holds a capitalize_receipt fact (premise), and refuses the same source and kind twice, by
        inventory_postings_source_uq
      - >-
        refuses a kind with the wrong purposes, by inventory_postings_purposes_check, and a zero amount, by
        inventory_postings_amount_check
      - 'refuses a reference without its instant, by inventory_postings_posted_check'
      - >-
        lets the application role stamp the two posting columns and refuses it the amount, the kind and a
        delete (42501)
      - >-
        holds a business unit’s LIFO setting, its padded id trimmed by the text-normalization trigger
        (premise), and refuses a second row for it, by business_unit_settings_pk
      - >-
        refuses a method that is neither fifo nor lifo, by business_unit_settings_costing_method_check, and a
        blank business unit, trimmed to null and refused not-null (23502)
      - >-
        records lifo on a layer and a relief, and refuses another method, by
        inventory_cost_layers_costing_method_check and cost_relief_costing_method_check
      - hides another tenant’s settings and refuses a setting written into another tenant
      - >-
        hide another tenant’s vendors, orders, receipts, layers, reliefs and postings, and refuse a row
        written into another tenant
scenario_coverage: []
dependency_evidence:
  provenance: test
  source: 'services-commerce:modules/purchasing/tests/integration/db/purchasing-tables.table.integration.spec.js'
  declared_by_test: >-
    PostgreSQL built from the migrations, both roles as the bootstrap makes them, the execution context's
    transaction and its session settings. Doubled: nothing. Never doubled: the role switch, the tenant
    setting, the triggers or the grants.
---

# The purchasing and cost tables (integration, table)

## Verification Boundary

The suite exercises persistence or workflow operations against the local integration database.

## What This Suite Proves

The registered cases check the purchasing and cost tables (integration, table) 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

PostgreSQL and the exercised Commerce persistence or workflow code are real. Remote service records, clocks and transports follow the suite’s fixtures.

## Must Not Be Doubled

The database constraints, role restrictions, locks and transactions exercised by this suite must use PostgreSQL.
