API Maker

The backend engine for the AI era

Test casesEpisode 37 6:32 12 chapters November 2026

Test Cases with Mocks and Code Coverage for Your Custom APIs

A custom API that works today can break tomorrow with one character. Give Cart Quote four tests with mocks instead of a database, watch one run find a real bug before a customer does, fix it, run them all, see every line the tests ran, and run the same tests with npm run test in your CI.

In the playlists The complete course Testing & debugging

Chapters

What you will learn

  • The Test Cases page, and a new test case
  • Mocks of g.sys, written as sentences
  • Four tests, and a run that finds a bug
  • Expected next to actual, and the fix
  • Run all, and the lines that ran
  • npm run test from a terminal and CI, in every language
In the docsTest cases
Transcript926 words · click a time to play from there

Intro

A custom API that works today can break tomorrow, because of one character. In this video, Cart Quote gets four tests, with mocks in place of a database. One run finds a real bug. And the coverage shows every line the tests ran.

Tests, the usual way

Testing a backend usually takes a lot of setup. You need a test database, with fixtures to keep up to date. You need a mocking library for each framework. You set up a runner in CI. And you need a coverage tool for each language. With API Maker, tests run on the server, in the sandbox of the account, with the same g as the code. Any call of g dot sys can be mocked, from a dialog or in the code.

One button, or npm run test, runs them. And every run tells which lines ran, in eight languages. In this video: the Test Cases page, a test case and its mocks, four tests, a run that finds a bug, the fix and Run all, the coverage, the same run in a terminal, and tests in every language.

The Test Cases page

Test Cases is on the dashboard. On the left, you see every test case of the account. In the middle, the code of one. On the right, the run. There are none yet.

A test case and its mocks

Click New. Name the test case Cart Quote. Pick its kind, a custom API, and pick the custom API, Cart Quote. It gives the price of a cart at checkout. We met it in video thirty eight. Cart Quote reads the prices of products from MongoDB, and coupons from MariaDB. A test should not depend on that data. The Mocks tab starts with the calls that tests fake most often.

A blank mock reads like a sentence. When the test calls db dot query, and only when its query is for the collection products, answer with these three products. The same mock, written as code, is right below. Here is a second one. db dot query again, this time for the coupons, answered with WELCOME5, five percent. Save it. Now the test case has its code. It is TypeScript by default, or any language of the picker.

Its two mocks sit next to the button that opens them.

Four tests

Here are four tests. runCustomApi runs the code of Cart Quote inside the test, and its calls of g dot sys meet the mocks. A cart of exactly one hundred and fifty ships for free. A small cart pays for shipping. WELCOME5 takes five percent off, and g dot sys dot test dot calls says the mocks answered twice. The last test brings its own mock. No coupon is found, so the API must refuse.

Save it.

A run that finds a bug

Click Run. Three tests pass, and one fails: a cart of one hundred and fifty ships for free. You see what came, next to what was expected. Shipping is nine point nine, and the total is one hundred and fifty nine point nine. The rule in Cart Quote says that shipping is free when the subtotal is more than one hundred and fifty. But the promise was: from one hundred and fifty.

In video thirty eight, a customer found this bug. Here, a test found it first, in a few milliseconds, without a database.

The fix and Run all

Open the code of Cart Quote. Click Test API, then Code. Go to line twenty two. Change it to greater or equal. Save it. Open the menu, then Test Cases. The test case is still red, from the last run. Run all runs every test case of the account. Now four of four pass.

The coverage

Here is the coverage of the run. Every line ran, in two files: Cart Quote, and its test case. Every line of Cart Quote ran. The four tests reach every branch, the coupon and the shipping rule. A line that no test reaches is red. Back in the list, the test case shows its result and its coverage, above its code.

npm run test

On a laptop, the folder of the local client runs the same tests, with npm run test. The tests run on the server, and every step prints as it happens, with the coverage of each file. The exit code is zero when everything passed, one when a test failed, and two when the run did not finish. A CI job needs nothing more. And coverage slash lcov dot info marks the lines in VS Code and WebStorm.

Every language

You can write a test case in TypeScript, Python, PHP, C sharp, Go, Rust, Java, or Kotlin. Each one names tests the way its own test tools do. A test in one language can run a custom API written in another, and the mocks answer it there too. And every language counts its own lines.

Built on standards

Test cases are files in Git, next to the code they test. So a person or an AI assistant writes them like any other file. A mock is a plain value that anyone can read, or a function of the test. It can make a call fail, or answer only a few calls. And the same command runs on a laptop and in CI.

Recap

To sum up. Tests run on the server, with the same g as the code. Every call of g dot sys can be mocked. A run shows what was expected, next to what came. Coverage marks every line that ran. And npm run test runs them from a terminal, and in CI. Next: debugging, from a failing call to the line that broke. API Maker. Build faster, spend smarter, deliver better.