CtrlK
BlogDocsLog inGet started
Tessl Logo

simon/skills

Auto-generated tile from GitHub (10 skills)

92

1.16x
Quality

94%

Does it follow best practices?

Impact

92%

1.16x

Average score across 44 eval scenarios

SecuritybySnyk

Advisory

Suggest reviewing before use

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-3/

Writing a Test Suite for an Inventory API

Problem/Feature Description

A logistics company has an existing Fastify inventory API that has never had automated tests. A junior developer recently introduced a regression that went unnoticed for two days because testing was done manually. The engineering lead wants a proper test suite added before the next release.

The API has three endpoints: one to list all inventory items with optional filtering by warehouse, one to create a new inventory item, and one to look up a single item by its SKU. The team uses Node.js 22 and does not want to introduce additional testing frameworks — they want to use whatever ships with Node.js directly.

Your task is to write a test suite for the provided API. The tests should cover: successful responses for all three endpoints, validation error responses (e.g., missing required fields, invalid data types), a 404 response for a SKU that does not exist, and filtering by warehouse.

The test suite must be runnable with a single command without installing any third-party testing frameworks (no jest, mocha, tap, vitest, or similar).

Input Files

The following files are provided as inputs. Extract them before beginning.

=============== FILE: src/app.ts =============== import Fastify from 'fastify' import { Type, type Static } from '@sinclair/typebox' import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'

const ItemSchema = Type.Object({ sku: Type.String({ minLength: 1 }), name: Type.String({ minLength: 1 }), warehouse: Type.String(), quantity: Type.Integer({ minimum: 0 }), })

const CreateItemSchema = Type.Object({ sku: Type.String({ minLength: 1 }), name: Type.String({ minLength: 1 }), warehouse: Type.String({ minLength: 1 }), quantity: Type.Integer({ minimum: 0 }), })

type Item = Static<typeof ItemSchema>

const items: Item[] = [ { sku: 'WIDGET-001', name: 'Blue Widget', warehouse: 'WH-A', quantity: 50 }, { sku: 'GADGET-002', name: 'Red Gadget', warehouse: 'WH-B', quantity: 10 }, { sku: 'THING-003', name: 'Green Thing', warehouse: 'WH-A', quantity: 200 }, ]

export function buildApp () { const app = Fastify({ logger: false }).withTypeProvider<TypeBoxTypeProvider>()

app.get('/', { schema: { querystring: Type.Object({ warehouse: Type.Optional(Type.String()), }), response: { 200: Type.Array(ItemSchema), }, }, }, async (request) => { const { warehouse } = request.query if (warehouse) { return items.filter(i => i.warehouse === warehouse) } return items })

app.get('/:sku', { schema: { params: Type.Object({ sku: Type.String() }), response: { 200: ItemSchema, 404: Type.Object({ error: Type.String() }), }, }, }, async (request, reply) => { const item = items.find(i => i.sku === request.params.sku) if (!item) { return reply.code(404).send({ error: 'Item not found' }) } return item })

app.post('/', { schema: { body: CreateItemSchema, response: { 201: ItemSchema, }, }, }, async (request, reply) => { const item = request.body items.push(item) return reply.code(201).send(item) })

return app } =============== END FILE ===============

Output Specification

Produce:

  • package.json with type: "module" and a test script
  • src/app.ts (copy the provided file above, unchanged)
  • test/inventory.test.ts (or .js) — the test suite

The test script in package.json must run tests without any third-party test runner (no jest, mocha, tap, vitest, or similar packages).

evals

README.md

tile.json