Skip to content
↑↓ move↵ openesc close

Tutorials

Prove your API rejects bad data

Run the rejection cases Luvin generates, choose which status each one must return, add a case with your own data and share the results as an HTML report.

5 min read

A good API accepts what is valid and rejects what is not. You will run the cases that check the second half in the Pokédex example, decide what “rejected” means for your API, add a case of your own and export a report. You need about 20 minutes and an internet connection. No credentials are needed.

Luvin generates these cases from the contract and the workflow. They are in the Cases tab, in the groups Data validation and Security.

Case What it sends When it exists
Without the required input “…” Leaves out one required input. An input that is required, and not in the path of the URL.
“…” with … A wrong value: outside the allowed options, text instead of a number, or a value that breaks the pattern. An input with allowed options, a number or yes/no type, or a pattern.
Without credentials No credentials. The first protected step must answer 401 or 403. A contract protects at least one step.

All of them need the Real API: in Simulation Luvin does not validate what you send, so they show Will not run. See Cases.

The Pokédex has no credentials, and its inputs go in the URL path, so it only generates the second kind. The PayPal example generates the three: Create order has a required amount in the body and a protected API. See Test a payment flow with OAuth 2.0.

  1. Open the Pokédex example. See the Quick start.
  2. Click Type explorer in the sidebar and open the Cases tab.

Its input type only allows 18 type names. Luvin generated the case “type” with a value outside the enum in the group Data validation. Next to it you see Rejection expected, and Real API.

The Cases tab with the generated cases in their groups

Under the case, the line Status «getType» must respond: lists the statuses that count as a rejection.

  1. Look at the statuses. A dot marks the ones the contract documents for that step. For getType it documents 404, so Luvin suggests it.
  2. Read the line next to it: If it responds otherwise: warning. Luvin suggested the status, so a different answer does not fail the case.
  3. Click 404. The line changes to If it responds otherwise: error.

Now you decided: it is what you state about your API. If you choose nothing, any 4xx counts. A status that is not in the list goes in Other (Enter). Back to the suggestion undoes your choice. See Adjust a case.

Who chose the status If the API answers something else
Luvin, in a Data validation case Warning: the workflow still works, but review it.
You Failed
Without credentials Failed
  1. Click None, at the top right, to untick every case.
  2. Tick “type” with a value outside the enum.
  3. In the run bar, choose Real API and click Run.

The results open at the bottom and the case ends as Passed.

  1. Click the case in the list. The row What it checks says what the case does differently: it sends an invalid value in type.
  2. Click Show values sent to see the value that was sent.
  3. Under the detail, open the card getType.

The card shows the badge Responded 404 (expected) and a note, This is what the case tests, with the message of the API after The API said:. The step is shown as passed because the error is what the case wants. The steps after it say they did not run, and why. See Read a step result.

The generated cases do not know your business rules. Add one for a situation of your own.

  1. Open Pokemon card and its Cases tab.
  2. In the group Custom data cases, click + New data case.
  3. In Case name, type Unknown Pokémon.
  4. In Step to check, choose getPokemon.
  5. In Expected action (optional), choose pokemonNotFound (end), and in Expected status, type 404.
  6. Under Case inputs, type QA-{{number:6}} in pokemon.
  7. Click Add case.

{{number:6}} is a generator: Luvin replaces it with six random digits on every run, so the name never repeats. The same works for {{uuid}} and {{$randomEmail}}. See Custom data cases.

Untick the other cases and click Run. A custom data case always runs against the real API. It ends as Passed when getPokemon answers 404 and the action pokemonNotFound fires. Click Show values sent to see the value the generator produced.

  1. In the header of the results, click Report.
  2. Your browser or the desktop app downloads a file named report-<title>-<date>.html.

The exported HTML report open in a browser

The file has a summary in plain words, the counters, the environment, a table of cases and the detail of each one. It is a single file: whoever receives it opens it in any browser, with no Luvin. Secrets and sensitive fields appear as ••••, but other data in the requests and responses is in the report as it was sent. Read it before you send it outside your team. See Reports.

  • The rejection cases check that the API refuses a missing input, an invalid value and a request with no credentials.
  • They need the Real API.
  • A status suggested by Luvin gives a Warning when the API differs. A status you choose gives Failed.
  • A step that answers the expected error is shown as passed.
  • Custom data cases and generators cover your own rules.
  • Report exports everything as one HTML file.