Skip to content

Commit

Permalink
Minor tweaks (#26)
Browse files Browse the repository at this point in the history
* move front page from root

* check object UT
  • Loading branch information
sbcgua authored Apr 19, 2020
1 parent 649ed16 commit a8a2828
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 4 deletions.
66 changes: 66 additions & 0 deletions src/api/check_object.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { checkObject } from "./check_object";

test("should happily check object", () => {
const config = {
"syntax": { "version": "v702" },
"rules": {
"indentation": true,
"keyword_case": { "style": "upper" }
}
};
const file = `
REPORT zxxx.
DATA lvstr TYPE string.
write 'Hello world'.`;

const checkObjectInput = {
configuration: Buffer.from(JSON.stringify(config)).toString("base64"),
object: {
objectName: "ZXXX",
objectType: "PROG",
},
files: [
{
name: "zxxx.prog.abap",
contents: Buffer.from(file).toString("base64"),
}
]
};

const output = checkObject(checkObjectInput);
expect(output).toEqual({
object: {
objectName: "ZXXX",
objectType: "PROG"
},
issues: [
{
message: "Keyword should be upper case: \"write\"",
key: "keyword_case",
start: {
row: 4,
col: 1
},
end: {
row: 4,
col: 6
},
"filename": "zxxx.prog.abap"
},
{
message: "Indentation problem, expected 0 spaces",
key: "indentation",
start: {
row: 3,
col: 3
},
end: {
row: 3,
col: 26
},
filename: "zxxx.prog.abap"
}
]
});
});

4 changes: 2 additions & 2 deletions src/front_page.ts → src/api/front_page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as abaplint from "@abaplint/core";
import * as os from "os";
import { getLogTail } from "./lib/log-tail";
import { getLogTail } from "../lib/log-tail";

function osInfo(): string {
return "load: " + os.loadavg() + "<br>" +
Expand All @@ -20,7 +20,7 @@ function renderLogTail(): string {
}
}

export function frontPage(): string {
export function renderFrontPage(): string {
return `<!DOCTYPE html>
<html>
<head>
Expand Down
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from "express";
import * as morgan from "morgan";
import * as helmet from "helmet";
import { frontPage } from "./front_page";
import { renderFrontPage } from "./api/front_page";
import api from "./api";
import { addInfoEx } from "./lib/log-tail";

Expand All @@ -13,7 +13,7 @@ if (process.env.NODE_ENV !== "test") {
app.use(morgan("common"));
}

app.get("/", (_req, res) => res.send(frontPage()));
app.get("/", (_req, res) => res.send(renderFrontPage()));
app.get("/healthz", (_req, res) => res.send("OK"));
app.use("/api/v1", api);
app.use("*", (req, res) => {
Expand Down
41 changes: 41 additions & 0 deletions test/check-object.api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import app from "../src/app";
import * as request from "supertest";

test("should check file", async () => {
const config = {
"syntax": { "version": "v702" },
"rules": {
"indentation": true,
"keyword_case": { "style": "upper" }
}
};
const file = `
REPORT zxxx.
DATA lvstr TYPE string.
write 'Hello world'.`;

const checkObjectInput = {
configuration: Buffer.from(JSON.stringify(config)).toString("base64"),
object: {
objectName: "ZXXX",
objectType: "PROG",
},
files: [
{
name: "zxxx.prog.abap",
contents: Buffer.from(file).toString("base64"),
}
]
};

// maybe use https://github.com/Dean177/jest-to-match-shape-of
const res = await request(app).post("/api/v1/check_file").send(checkObjectInput);
expect(res.status).toBe(200);
expect(typeof res.body).toBe("object");
expect(res.body.object).toEqual({
objectName: "ZXXX",
objectType: "PROG",
});
expect(Array.isArray(res.body.issues)).toBeTruthy();
expect(res.body.issues.length).toBe(2);
});

0 comments on commit a8a2828

Please sign in to comment.