-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
124 lines (111 loc) · 3.81 KB
/
client.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var Client = require('node-rest-client').Client;
// direct way
var client = new Client();
var authorization;
var current_data;
var login_args = {
data: {username: "kenzan", password: "kenzan" },
headers: { "Content-Type": "application/json" }
};
function test8()
{
}
function test7() {
console.log("test7");
client.post("http://localhost:8080/Kenzan/rest/get_all", {headers: {"Authorization": authorization, "Content-Type": "application/json" } },
function (data, response) {
if(data.length + 1 != current_data.length)
console.log("test7 error 1");
current_data = data;
test8();
});
}
function test6() {
console.log("test6");
record = current_data[2];
record.bStatus = 'INACTIVE';
client.post("http://localhost:8080/Kenzan/rest/update_emp", {data: record, headers: {"Authorization": authorization, "Content-Type": "application/json" } },
function (data, response) {
if(data.error != "ok") {
console.log("test6 error 1");
console.log(data);
}
test7();
});
}
function test5() {
console.log("test5");
client.post("http://localhost:8080/Kenzan/rest/get_all", {headers: {"Authorization": authorization, "Content-Type": "application/json" } },
function (data, response) {
if(data.error != null)
console.log("test5 error 1");
data.forEach(function(record) {
if(record.bStatus != 'ACTIVE')
console.log("test5 error 2");
});
current_data = data;
test6();
});
}
function test4() {
console.log("test4");
client.post("http://localhost:8080/Kenzan/rest/login", {data: {username: "kenzan", password: "kenzan"}, headers: {"Content-Type": "application/json" } },
function (data, response) {
if(data.jwt == null) {
console.log("We should have gotten a valid jwt");
process.exit();
}
if(data.error != null) {
console.log("Invalid error message: " + data.error);
process.exit();
};
authorization = data.jwt;
test5();
});
}
function test3() {
console.log("test3");
client.post("http://localhost:8080/Kenzan/rest/login", {data: {username: "kenzan", password: "kenzan"}, headers: {"Content-Type": "application/json" } },
function (data, response) {
if(data.jwt == null)
console.log("We should have gotten a valid jwt");
if(data.error != null)
console.log("Invalid error message: " + data.error);
console.log(data.jwt);
test4();
});
}
function test2() {
console.log("test2");
client.post("http://localhost:8080/Kenzan/rest/login", {data: {username: "kenzan", password: "invalid"}, headers: {"Content-Type": "application/json" } },
function (data, response) {
if(data.jwt != null)
console.log("jwt not null when it should be");
if(data.error != 'Unable to validate user/password combination')
console.log("Invalid error message");
test3();
});
}
function test1() {
console.log("test1");
client.post("http://localhost:8080/Kenzan/rest/login", {data: {username: "invalid", password: "invalid"}, headers: {"Content-Type": "application/json" } },
function (data, response) {
if(data.jwt != null)
console.log("jwt not null when it should be");
if(data.error != 'Unable to validate user/password combination')
console.log("Invalid error message");
test2();
});
};
test1();
var record = {
firstName: "John",
lastName: "Doe",
dateOfBirth: "1990-12-25",
dateOfEmployment: "2000-01-01",
bStatus: "ACTIVE"
};
var args = {
data: record, // data passed to REST method (only useful in POST, PUT or PATCH methods)
headers: { "Authorization": "abc", "Content-Type": "application/json" } // request headers
};