|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+var request = require("request");
|
|
|
2
|
+var base_url = "http://localhost:3000";
|
|
|
3
|
+
|
|
|
4
|
+describe("User Operations", function () {
|
|
|
5
|
+
|
|
|
6
|
+ var register_user = {
|
|
|
7
|
+ url: base_url + "/user/register",
|
|
|
8
|
+ method: "POST",
|
|
|
9
|
+ json: {
|
|
|
10
|
+ user: "foo123",
|
|
|
11
|
+ password: "foofoo"
|
|
|
12
|
+ }
|
|
|
13
|
+ };
|
|
|
14
|
+
|
|
|
15
|
+ var user_ops_auth_key = "";
|
|
|
16
|
+
|
|
|
17
|
+ describe("POST /user/register/", function () {
|
|
|
18
|
+ it("can register user", function (done) {
|
|
|
19
|
+ request(register_user, function (error, response, body) {
|
|
|
20
|
+ expect(response.statusCode).toBe(200);
|
|
|
21
|
+ expect(body.registered).toBe(1);
|
|
|
22
|
+ if (body["auth-key"]) {
|
|
|
23
|
+ expect(body["auth-key"].length).toBe(60);
|
|
|
24
|
+ }
|
|
|
25
|
+ expect(body.error).toBe(0);
|
|
|
26
|
+ done();
|
|
|
27
|
+ });
|
|
|
28
|
+ });
|
|
|
29
|
+
|
|
|
30
|
+ it ("cannot register the same user twice", function (done) {
|
|
|
31
|
+ request(register_user, function (error, response, body) {
|
|
|
32
|
+ expect(response.statusCode).toBe(200);
|
|
|
33
|
+ expect(body.registered).toBe(0);
|
|
|
34
|
+ expect(body["auth-key"]).toBe(undefined);
|
|
|
35
|
+ expect(body.error).toBe(1);
|
|
|
36
|
+ done();
|
|
|
37
|
+ });
|
|
|
38
|
+ });
|
|
|
39
|
+
|
|
|
40
|
+ it ("cannot accept malformed requests", function (done) {
|
|
|
41
|
+ request({
|
|
|
42
|
+ url: base_url + "/user/register/",
|
|
|
43
|
+ method: "POST",
|
|
|
44
|
+ json: {
|
|
|
45
|
+ usr: "foo123",
|
|
|
46
|
+ password: "foofoo"
|
|
|
47
|
+ }
|
|
|
48
|
+ }, function (error, response, body) {
|
|
|
49
|
+ expect(response.statusCode).toBe(200);
|
|
|
50
|
+ expect(body.registered).toBe(0);
|
|
|
51
|
+ expect(body["auth-key"]).toBe(undefined);
|
|
|
52
|
+ expect(body.error).toBe(2);
|
|
|
53
|
+ done();
|
|
|
54
|
+ });
|
|
|
55
|
+ })
|
|
|
56
|
+ });
|
|
|
57
|
+
|
|
|
58
|
+});
|