Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor tweaks #26

Merged
merged 2 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});