Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Which type of software test would you write to verify that an HTTP POST request to `/users` successfully executes the Controller logic and inserts a real row into a sandbox PostgreSQL database?
💻 Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Test Types: E2E, Unit, Integration pipeline. Include the setup and basic execution steps.
You are reviewing a Node Test Types: E2E, Unit, Integration pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Integration tests running against a shared database and leaving stale data behind, causing other tests to fail intermittently
// Wrong: no cleanup between tests, results depend on execution order
it('creates a user', async () => {
await request(app).post('/users').send({ name: 'Bob' });
});
// Correct: explicit cleanup guarantees a known starting state
afterEach(async () => {
await db.query('TRUNCATE users RESTART IDENTITY CASCADE');
});The Solution //
If Supertest-driven integration tests insert rows into a database that isn't wiped between test runs (or worse, is shared across parallel CI jobs), a test asserting 'exactly 3 users exist' can fail depending on execution order or leftover data from a previous run. Use a dedicated test database, and wrap each test (or test suite) in setup/teardown hooks that truncate tables before and after.
The Error //
Writing dozens of slow, flaky E2E (Cypress/Playwright) tests instead of pushing coverage down into unit and integration tests
// Anti-pattern: an E2E test for something a unit test could verify in milliseconds
cy.visit('/calculator');
cy.get('#a').type('2');
cy.get('#b').type('3');
cy.get('#sum').should('have.text', '5');
// Better: a unit test covers the same logic in <1ms
expect(add(2, 3)).toBe(5);The Solution //
E2E tests are the most realistic but also the slowest and most prone to flakiness (timing issues, animations, network variance) — a test suite that's mostly E2E tests turns CI runs into 20+ minute ordeals with random failures unrelated to real bugs. Follow the testing pyramid: push the bulk of coverage into fast unit tests, use integration tests to verify layers connect correctly, and reserve E2E tests for only the handful of truly critical user journeys (login, checkout).