-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_test.js
More file actions
122 lines (110 loc) · 3.4 KB
/
api_test.js
File metadata and controls
122 lines (110 loc) · 3.4 KB
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
var jsdom = require("jsdom");
var fs = require('fs');
/* json files to be tested */
//change file path to test signup user json request
var signup_json;
fs.readFile('./static/test_files/signup.json', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
signup_json = data;
});
//change file path to test login user json request
var login_json;
fs.readFile('./static/test_files/login.json', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
login_json = data;
});
//change file path to test delete user json request
var delete_json;
fs.readFile('./static/test_files/delete.json', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
delete_json = data;
});
//change file path to test modify user json request
var modify_json;
fs.readFile('./static/test_files/modify.json', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
modify_json = data;
});
/* end file read */
//JavaScript implementation of the DOM and HTML standards
jsdom.env("", ["http://code.jquery.com/jquery.min.js"], function(err, window) {
var $ = window.$
$.support.cors = true;
var server_path = "http://localhost:5000";
/* test signup */
$.ajax({
method: "POST",
url: server_path + "/api/v1.0/users/accounts/participants/signup/",
data: signup_json,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data, status, jqXHR) {
console.log("### 1. Sign up response: ###");
console.log(data);
},
error: function(jqXHR) {
console.log("### 1. Sign up response: ###");
console.log("Status: " + jqXHR.status);
console.log("Request failed @ http://localhost:5000/api/v1.0/users/accounts/participants/signup/");
}
});
/* test login */
$.ajax({
method: "POST",
url: server_path + "/api/v1.0/users/accounts/login/",
data: login_json,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data, status, jqXHR) {
console.log("### 2. Log in response: ###");
console.log(data);
},
error: function(jqXHR) {
console.log("### 2. Log in response: ###");
console.log("Status: " + jqXHR.status);
console.log("Request failed @ http://localhost:5000/api/v1.0/users/accounts/login/");
}
});
/* test delete */
$.ajax({
method: "DELETE",
url: server_path + "/api/v1.0/users/manage/delete/",
data: delete_json,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data, status, jqXHR) {
console.log("### 3. Delete response: ###");
console.log(data);
},
error: function(jqXHR) {
console.log("### 3. Delete response: ###");
console.log("Status: " + jqXHR.status);
console.log("Request failed @ http://localhost:5000/api/v1.0/users/manage/delete/");
}
});
/* test modify */
$.ajax({
method: "PUT",
url: server_path + "/api/v1.0/users/manage/edit/",
data: modify_json,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data, status, jqXHR) {
console.log("### 4. Modify response: ###");
console.log(data);
},
error: function(jqXHR) {
console.log("### 4. Modify response: ###");
console.log("Status: " + jqXHR.status);
console.log("Request failed @ http://localhost:5000/api/v1.0/users/manage/edit/");
}
});
});