Path: blob/master/src/packages/next/lib/api/framework.test.ts
1447 views
/*1This file gets unit tested both in prod and dev modes. This is important to2ensure that in production the input validation is skipped (for now!).3*/45import handler from "../../pages/api/v2/guesslang";6import { createMocks } from "./test-framework";78describe("test that /api/v2/guesslang works in either dev or production mode", () => {9test("error if code param not given in dev mode; no error in production mode", async () => {10const { req, res } = createMocks({11method: "POST",12url: "/api/v2/guesslang",13body: {},14});1516await handler(req, res);17if (process.env.NODE_ENV == "production") {18expect(res.statusCode).toBe(200);19} else {20expect(res.statusCode).toBe(400);21}22});2324test("error if code is not a string in dev mode; no error in production mode", async () => {25const { req, res } = createMocks({26method: "POST",27url: "/api/v2/guesslang",28body: { code: 10 },29});3031await handler(req, res);32if (process.env.NODE_ENV == "production") {33expect(res.statusCode).toBe(200);34} else {35expect(res.statusCode).toBe(400);36}37});38});394041