# `test.round_trip_failed`

Field's decode and encode don't round-trip a recorded value.

Area 11, [External services](../topics/external-services.md); not declinable; the next step is usually the agent's.

A field's `encode:` that doesn't give back what its `decode:` read from a
recording, so what the app sends isn't what the provider sent: here the
package reads the courier's `EVE` as the afternoon, and writes the
afternoon back as `PM`.










```jadpo
/// The courier's part of the days, which it writes as "AM" and "PM".
library dayparts {
    /// The part of the day the courier's code names.
    function read_daypart(code: DaypartCode) fails DaypartUnknown -> Daypart {
        if (code == "AM") {
            return Daypart.morning
        }
        if (code == "PM" or code == "EVE") {
            return Daypart.afternoon
        }
        reject DaypartUnknown
    }

    /// The courier's code for a part of the day.
    function write_daypart(daypart: Daypart) -> DaypartCode {
        if (daypart == Daypart.morning) {
            return "AM"
        }
        return "PM"
    }
}
```

```jadpo
{
  "data": {
    "id": "{Text}",
    "daypart": "EVE"
  }
}
```

```text
FAIL  bookings.create's recording decodes
 --> shared/providers/acme_couriers/v1/recordings/bookings.create.json:1

  decode: `dayparts.read_daypart` and `dayparts.write_daypart` don't round-trip `bookings.create`'s recording
  recorded: "EVE"
  written: "PM"
  reason: A field's `encode:` writes back what its `decode:` read, so what the app sends is what the provider sent; `dayparts.write_daypart` doesn't give back the value `dayparts.read_daypart` read from the recording.
  next: Correct `dayparts.read_daypart` or `dayparts.write_daypart` so each undoes the other (agent)

  rule: test.round_trip_failed
  rerun: jadpo test shared/providers/acme_couriers/v1/recordings/bookings.create.json:1 --seed 1

test failed: 1 failed, 1 recording test
```
