Skip to content

Add round-trip tests for the transfer code (the paste-it-across path) #55

Description

@pip-robot

Pip lets you move your progress to another device with no account: you copy a short code on one device and paste it on the other, or scan a QR. That lives in src/lib/transfer.ts, and it has no tests.

It is the path where a mistake costs someone their progress, so it deserves them.

The task

Add an AVA test file (tests/transfer.test.ts) covering encodeEnvelope() and decodeCode():

  • Round trip. Encode an envelope, decode it, and check you get the same profile back. Build the envelope by hand in the test rather than through profileCode(), which reads the live store.
  • The prefixes. A gzipped code starts pip1:, a raw one pip0:. Check the encoder produces the compressed form where CompressionStream exists, and that a pip0: code still decodes.
  • The rejection paths, which are the point. All three of these must come back { ok: false } with a message and must never throw: a string with no prefix at all, a pip1: code with the base64 truncated, and a code whose payload decodes to valid JSON that is not a Pip envelope.

Everything decodes through validateEnvelope in src/lib/backup.ts, so read that first: it tells you what shape a valid envelope is and what a rejection looks like.

Getting started

pnpm install
pnpm test          # the AVA suite

Both functions are async, so your tests will be too. tests/syncErrors.test.ts is a good one to copy the shape from.

A fair warning: this is the meatier of the two testing issues currently open (the other is #54, which is a gentler start). Nothing here is hard, but there is more to read before you write the first line.

Done when

pnpm test:all passes, a round trip is proven lossless, and all three bad-input paths are covered and return a message rather than throwing.

New here? See CONTRIBUTING.md. Merged work puts your name on playpip.io/credits.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions