-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move front page from root * check object UT
- Loading branch information
Showing
4 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |