Path: blob/master/src/packages/next/lib/api/framework.test.ts
5609 views
/** @jest-environment node */12/*3This file gets unit tested both in prod and dev modes. This is important to4ensure that in production the input validation is skipped (for now!).5*/67import handler from "../../pages/api/v2/guesslang";8import { createMocks } from "./test-framework";910describe("test that /api/v2/guesslang works in either dev or production mode", () => {11test("error if code param not given in dev mode; no error in production mode", async () => {12const { req, res } = createMocks({13method: "POST",14url: "/api/v2/guesslang",15body: {},16});1718await handler(req, res);19if (process.env.NODE_ENV == "production") {20expect(res.statusCode).toBe(200);21} else {22expect(res.statusCode).toBe(400);23}24});2526test("error if code is not a string in dev mode; no error in production mode", async () => {27const { req, res } = createMocks({28method: "POST",29url: "/api/v2/guesslang",30body: { code: 10 },31});3233await handler(req, res);34if (process.env.NODE_ENV == "production") {35expect(res.statusCode).toBe(200);36} else {37expect(res.statusCode).toBe(400);38}39});40});414243