-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalildation.test.js
64 lines (56 loc) · 1.75 KB
/
valildation.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const validation = require("./validation")
const { isValidTable, isValidColumn, isComputedColumn } = require("./validation")
var schema = {
mytable: {
columns: [
{ name: "mycolumn" },
{ name: "my_column2" },
{ name: "computedCol", isComputed: 1 }
]
},
customer: {
columns: [
{ name: 'ID'},
{ name: 'address'},
{ name: 'name'}
]
},
myuser: {
columns: [
{ name: 'ID'},
{ name: 'name'},
{ name: 'customerid'},
]
}, job: {
columns: [
{ name: 'ID'},
{ name: 'name'},
{ name: 'customerid'},
]
}, timeentry: {
columns: [
{ name: 'ID'},
{ name: 'starttime'},
{ name: 'stoptime'},
]
}
}
validation.setSchema(schema)
test("test validation utils", () => {
expect(isValidTable("mytable")).toBeTruthy()
expect(isValidColumn("mytable", "mycolumn")).toBeTruthy()
expect(isValidColumn("mytable", "my_column2")).toBeTruthy()
expect(isValidColumn("mytable", "dbo.mycolumn")).toBeFalsy()
expect(isValidColumn("mytable", "mycolumn--")).toBeFalsy()
expect(isValidColumn("mytable", "my column")).toBeFalsy()
expect(isValidColumn("mytable", "mycolumn'")).toBeFalsy()
expect(isValidColumn("mytable", "mycolumn;")).toBeFalsy()
expect(isComputedColumn("mytable", "computedCol")).toBeTruthy()
expect(isComputedColumn("mytable", "mycolumn")).toBeFalsy()
//test names with .
expect(isValidColumn("mytable", "mytable.mycolumn")).toBeTruthy()
expect(isValidColumn("mytable", "mytable.mytable.mycolumn")).toBeFalsy()
//test joins
expect(isValidColumn("myuser", "customername", ['customer'])).toBeTruthy()
expect(isValidColumn("timeentry", "customerid", [{model:'job', fields:"customerid"}])).toBeTruthy()
})