Skip to content
Merged
14 changes: 11 additions & 3 deletions app/controllers/matrix.js → app/controllers/matrix.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const calcDeterminant = (req, res) => {
const matrix = JSON.parse(req.query.matrix)
import { VercelRequest, VercelResponse } from "@vercel/node"

const calcDeterminant = (req: VercelRequest, res: VercelResponse) => {
let matrix
// string array
if (Array.isArray(req.query.matrix))
matrix = JSON.parse(req.query.matrix.join())
else matrix = JSON.parse(req.query.matrix)

const rows = matrix.length
const cols = matrix[0].length
Expand All @@ -18,4 +24,6 @@ const calcDeterminant = (req, res) => {
}
}

module.exports = { calcDeterminant }
export default {
calcDeterminant,
}
5 changes: 0 additions & 5 deletions app/controllers/test.js

This file was deleted.

9 changes: 9 additions & 0 deletions app/controllers/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { VercelRequest, VercelResponse } from "@vercel/node"

const test = (req: VercelRequest, res: VercelResponse) => {
res.send("API call successful")
}

export default {
test,
}
23 changes: 13 additions & 10 deletions app/tests/index.js → app/tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// standard testing modules
const chai = require("chai")
const chaiHttp = require("chai-http")
import chai from "chai"
import chaiHttp from "chai-http"

// modules that help testing serverless functions
const { createServer } = require("vercel-node-server")
const listen = require("test-listen")
import { createServer } from "vercel-node-server"
import listen from "test-listen"

// types
import { Server } from "http"

// import methods to be tested
const Test = require("../controllers/test")
const Matrix = require("../controllers/matrix")
import Test from "../controllers/test"
import Matrix from "../controllers/matrix"

// beforeEach management
let route, method, server, url
let route: string, method, server: Server, url: string

let testIndex = 0
const toTest = [
Expand Down Expand Up @@ -52,7 +55,7 @@ describe("API tests", () => {
.request(url)
.get(route)
.then((res) => {
chai.expect(res.statusCode).to.equal(200)
chai.expect(res.status).to.equal(200)
chai.expect(res.text).to.equal("API call successful")
})
})
Expand All @@ -70,7 +73,7 @@ describe("API tests", () => {
matrix: "[[1,2],[3,4]]",
})
.then((res) => {
chai.expect(res.statusCode).to.equal(200)
chai.expect(res.status).to.equal(200)
chai.expect(res.body).to.equal(-2)
})
})
Expand All @@ -82,7 +85,7 @@ describe("API tests", () => {
matrix: "[[1,2,3],[4,5,6],[7,8,9]]",
})
.then((res) => {
chai.expect(res.statusCode).to.equal(500)
chai.expect(res.status).to.equal(500)
chai.expect(res.body.message).to.equal("Unsupported")
})
})
Expand Down
3 changes: 3 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />
84 changes: 83 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "next build",
"start": "next start",
"version": "auto-changelog -p -l 0 && git add CHANGELOG.md",
"test": "mocha app/tests/index.js"
"test": "mocha -r ts-node/register app/tests/index.ts"
},
"repository": {
"type": "git",
Expand All @@ -31,14 +31,20 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"test-listen": "^1.1.0",
"typescript": "^3.9.3",
"vercel-node-server": "^2.2.1"
},
"devDependencies": {
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@types/mocha": "^9.0.0",
"@types/react": "^17.0.15",
"@types/test-listen": "^1.1.0",
"@vercel/node": "^1.11.1",
"chai": "^4.3.4",
"chai-http": "^4.3.0",
"husky": "^7.0.1",
"mocha": "^9.0.3"
"mocha": "^9.0.3",
"ts-node": "^8.9.1"
}
}
22 changes: 22 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"include": ["./app/**/*"],
"exclude": ["node_modules"],
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./build",
"baseUrl": "./",
"esModuleInterop": true,
"allowJs": true,
"noImplicitAny": true,
"lib": ["dom", "dom.iterable", "esnext"],
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
}
}