CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/api/framework.test.ts
Views: 687
1
/*
2
This file gets unit tested both in prod and dev modes. This is important to
3
ensure that in production the input validation is skipped (for now!).
4
*/
5
6
import handler from "../../pages/api/v2/guesslang";
7
import { createMocks } from "./test-framework";
8
9
describe("test that /api/v2/guesslang works in either dev or production mode", () => {
10
test("error if code param not given in dev mode; no error in production mode", async () => {
11
const { req, res } = createMocks({
12
method: "POST",
13
url: "/api/v2/guesslang",
14
body: {},
15
});
16
17
await handler(req, res);
18
if (process.env.NODE_ENV == "production") {
19
expect(res.statusCode).toBe(200);
20
} else {
21
expect(res.statusCode).toBe(400);
22
}
23
});
24
25
test("error if code is not a string in dev mode; no error in production mode", async () => {
26
const { req, res } = createMocks({
27
method: "POST",
28
url: "/api/v2/guesslang",
29
body: { code: 10 },
30
});
31
32
await handler(req, res);
33
if (process.env.NODE_ENV == "production") {
34
expect(res.statusCode).toBe(200);
35
} else {
36
expect(res.statusCode).toBe(400);
37
}
38
});
39
});
40
41