Software Testing Engineering / API & CONTRACT TESTING / TST-024

Suggested study path · Step 2 of 2 · G1

Service Boundary Suite

Explore concept graph

Materi

Masalah: unit tests lulus, tetapi service sungguhan dapat gagal menyimpan transfer di database atau keliru menganggap provider timeout sebagai REJECTED.

Mulai: pisahkan apa yang perlu dijalankan nyata dan apa yang harus tetap diisolasi sebagai fake bank.

Peta konsep statis. Ikuti alur teks dari atas ke bawah.
      Internal Docker network
          Test driver
              |
         Node HTTP API
          /        \
    PostgreSQL    Fake Bank
       ^             |
       |         success/timeout
       +--- UPDATE providerOutcome
            ACCEPTED / UNKNOWN
          transfer stays PENDING

Dua jalur uji

Scenario HTTP PostgreSQL Bank requests
Fake bank accepts 201 Created PENDING / ACCEPTED, provider reference 1
Fake bank replies after deadline 201 Created PENDING / UNKNOWN, no reference 1

Provider ACCEPTED tidak membuktikan settlement. Saat timeout, bank dapat sudah menerima request, sehingga UNKNOWN harus direkonsiliasi sebelum retry.

Konsep 1 / 3

Run a real HTTP service and PostgreSQL database with a fake external bank on an internal Docker network.

In-memory tests cannot prove SQL connectivity or HTTP calls between independent services.

Mulai dari sini

Identify the four network roles.

Intuisi utama

Test driver -> real transfer service -> PostgreSQL + HTTP fake bank.

A Docker internal bridge connects three separate processes and a test driver, with no published host ports. PostgreSQL 16 is initialized with transfer schema; a Node HTTP service uses pg 8.16.3 to query the DB and calls a local bank stub. A trap tears down containers and network on exit. The Astro course application gains no database binding.

Contoh bertahap

In-memory tests pass although the real service cannot insert a DB record.

  1. Start PostgreSQL 16 on an internal Docker bridge.

    Mengapa: Exercise the real database driver.

    Hasil yang diharapkan: Database becomes query-ready with no published ports.

  2. Start service and bank stub on the same bridge.

    Mengapa: Verify real cross-container HTTP and SQL.

    Hasil yang diharapkan: Test driver reaches service health and no production URL is configured.

Konsep 2 / 3

Prove the real bank stub acknowledgement is committed to PostgreSQL without claiming settlement.

An HTTP 201 response alone cannot prove database persistence.

Mulai dari sini

Write expected persisted PENDING and ACCEPTED fields.

Intuisi utama

INSERT PENDING -> bank POST ACCEPTED -> UPDATE providerOutcome ACCEPTED -> GET and psql.

The Node service validates a five-field transfer, INSERTs PENDING via SQL, calls the fake bank and updates providerOutcome ACCEPTED with providerReference. The transfer status remains PENDING because acceptance is not settlement. A test driver checks HTTP 201 and GET, while the shell independently SELECTs the stored SQL row.

Contoh bertahap

The service returns 201 but the provider reference was never saved in PostgreSQL.

  1. POST client-success-001 through the service.

    Mengapa: Cross the actual HTTP, database and bank boundaries.

    Hasil yang diharapkan: HTTP 201, status PENDING and providerOutcome ACCEPTED.

  2. GET the resource and SELECT the row directly.

    Mengapa: Confirm persistence independent from the POST response.

    Hasil yang diharapkan: Same provider reference and ACCEPTED outcome stored in PostgreSQL.

Konsep 3 / 3

Persist UNKNOWN for a provider timeout and prove only one outbound bank attempt.

A provider may apply a payment before its reply is lost; retrying can duplicate effects.

Mulai dari sini

Write expected PENDING/UNKNOWN before running the timeout case.

Intuisi utama

A single bank request times out -> SQL stores PENDING/UNKNOWN -> no automatic replay.

For client-timeout-001 the bank stub records the request but waits 1100ms; the service aborts after 400ms and persists providerOutcome UNKNOWN with transfer status PENDING and no provider reference. Both HTTP GET and psql confirm the result, while stub tracking proves exactly two total bank requests, one for each scenario.

Contoh bertahap

The fake bank receives a debit request but its reply exceeds the client deadline.

  1. POST the timeout transfer through the same service.

    Mengapa: Exercise real HTTP dispatch before response loss.

    Hasil yang diharapkan: The stub receives one request, but the caller times out.

  2. Read the API, SQL row and stub call list.

    Mengapa: Ensure UNKNOWN survives persistence without blind retry.

    Hasil yang diharapkan: PENDING/UNKNOWN, null reference, exactly one request for the timeout scenario.

Sumber primer

Sumber

Cross-domain connections

Curated relationships for this unit at G1. Proposed edges are suggestions, not prerequisites.

Concept connectionsG1 · 4 visible concepts · 4 curated links
100%

Dashed = proposed relationship; solid = reviewed connection. Only reviewed prerequisites constrain a learning path. Keyboard and text links remain available.