Skip to content

Commit

Permalink
check object UT
Browse files Browse the repository at this point in the history
  • Loading branch information
sbcgua committed Apr 18, 2020
1 parent 633ff88 commit d7a1bc6
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 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"
}
]
});
});

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 d7a1bc6

Please sign in to comment.