|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+var request = require("request");
|
|
|
2
|
+var base_url = "http://localhost:3000";
|
|
|
3
|
+
|
|
|
4
|
+describe("Society Operations", function () {
|
|
|
5
|
+
|
|
|
6
|
+ var create_society = function (soc_name, auth_key) {
|
|
|
7
|
+ return {
|
|
|
8
|
+ url: base_url + "/society/create/",
|
|
|
9
|
+ method: "POST",
|
|
|
10
|
+ json: {
|
|
|
11
|
+ society: soc_name,
|
|
|
12
|
+ admins: JSON.stringify([]),
|
|
|
13
|
+ description: "A test society.",
|
|
|
14
|
+ auth: auth_key
|
|
|
15
|
+ }
|
|
|
16
|
+ };
|
|
|
17
|
+ };
|
|
|
18
|
+
|
|
|
19
|
+ var foo123auth;
|
|
|
20
|
+ var foo456auth;
|
|
|
21
|
+ var foo789auth;
|
|
|
22
|
+
|
|
|
23
|
+ describe("POST /society/create/", function() {
|
|
|
24
|
+ it("can create a new society", function(done) {
|
|
|
25
|
+ request({
|
|
|
26
|
+ url: base_url + "/user/auth/",
|
|
|
27
|
+ method: "POST",
|
|
|
28
|
+ json: {
|
|
|
29
|
+ user: "foo123",
|
|
|
30
|
+ password: "foofoo"
|
|
|
31
|
+ }
|
|
|
32
|
+ }, function (error, response, body) {
|
|
|
33
|
+ foo123auth = body["auth-key"];
|
|
|
34
|
+ request(create_society("foo123soc", foo123auth), function (error, response, body) {
|
|
|
35
|
+ expect(response.statusCode).toBe(200);
|
|
|
36
|
+ expect(body.success).toBe(1);
|
|
|
37
|
+ expect(body.society).not.toBe(null);
|
|
|
38
|
+ expect(typeof body.society).toBe("object");
|
|
|
39
|
+ expect(body.society.name).toBe("foo123soc");
|
|
|
40
|
+ expect(body.society.admins[0]).toBe("foo123");
|
|
|
41
|
+ expect(body.society.description).toBe("A test society.");
|
|
|
42
|
+ expect(body.society.users[0]).toBe("foo123");
|
|
|
43
|
+ expect(body.error).toBe(0);
|
|
|
44
|
+ done();
|
|
|
45
|
+ });
|
|
|
46
|
+ });
|
|
|
47
|
+ });
|
|
|
48
|
+
|
|
|
49
|
+ it("cannot create the same society as already exists", function(done) {
|
|
|
50
|
+ request(create_society("foo123soc", foo123auth), function (error, response, body) {
|
|
|
51
|
+ expect(response.statusCode).toBe(200);
|
|
|
52
|
+ expect(body.success).toBe(0);
|
|
|
53
|
+ expect(body.society).toBe(undefined);
|
|
|
54
|
+ expect(body.error).toBe(2);
|
|
|
55
|
+ done();
|
|
|
56
|
+ })
|
|
|
57
|
+ });
|
|
|
58
|
+
|
|
|
59
|
+ it("cannot create a society without valid authentication", function (done) {
|
|
|
60
|
+ request(create_society("foo12soc", "foo12soc"), function (error, response, body) {
|
|
|
61
|
+ expect(response.statusCode).toBe(200);
|
|
|
62
|
+ expect(body.success).toBe(0);
|
|
|
63
|
+ expect(body.society).toBe(undefined);
|
|
|
64
|
+ expect(body.error).toBe(3);
|
|
|
65
|
+ done();
|
|
|
66
|
+ });
|
|
|
67
|
+ });
|
|
|
68
|
+
|
|
|
69
|
+ it("cannot accept malformed requests", function (done) {
|
|
|
70
|
+ request({
|
|
|
71
|
+ url: base_url + "/society/create/",
|
|
|
72
|
+ method: "POST",
|
|
|
73
|
+ json: {
|
|
|
74
|
+ yeah: "no"
|
|
|
75
|
+ }
|
|
|
76
|
+ }, function (error, response, body) {
|
|
|
77
|
+ expect(response.statusCode).toBe(200);
|
|
|
78
|
+ expect(body.success).toBe(0);
|
|
|
79
|
+ expect(body.society).toBe(undefined);
|
|
|
80
|
+ expect(body.error).toBe(1);
|
|
|
81
|
+ done();
|
|
|
82
|
+ });
|
|
|
83
|
+ });
|
|
|
84
|
+ }); //end POST /society/create/
|
|
|
85
|
+
|
|
|
86
|
+ describe("GET /society/view/:societyid", function () {
|
|
|
87
|
+ it("shows the full list of societies without an id", function (done) {
|
|
|
88
|
+ request(base_url + "/society/view/", function (error, response, body) {
|
|
|
89
|
+ expect(response.statusCode).toBe(200);
|
|
|
90
|
+ body = JSON.parse(body);
|
|
|
91
|
+ expect(Array.isArray(body.societies)).toBe(true);
|
|
|
92
|
+ expect(body.societies.length).toBe(1);
|
|
|
93
|
+ done();
|
|
|
94
|
+ });
|
|
|
95
|
+ });
|
|
|
96
|
+
|
|
|
97
|
+ it("get an individual society", function (done) {
|
|
|
98
|
+ request(base_url + "/society/view/foo123soc/", function (error, response, body) {
|
|
|
99
|
+ body = JSON.parse(body);
|
|
|
100
|
+ expect(response.statusCode).toBe(200);
|
|
|
101
|
+ expect(body.society).not.toBe(null);
|
|
|
102
|
+ expect(typeof body.society).toBe("object");
|
|
|
103
|
+ expect(body.society.name).toBe("foo123soc");
|
|
|
104
|
+ expect(body.society.admins[0]).toBe("foo123");
|
|
|
105
|
+ expect(body.society.description).toBe("A test society.");
|
|
|
106
|
+ expect(body.society.users[0]).toBe("foo123");
|
|
|
107
|
+ expect(body.error).toBe(0);
|
|
|
108
|
+ done();
|
|
|
109
|
+ });
|
|
|
110
|
+ });
|
|
|
111
|
+
|
|
|
112
|
+ it("cannot get a non existant society", function (done) {
|
|
|
113
|
+ request(base_url + "/society/view/foo12soc", function (error, response, body) {
|
|
|
114
|
+ body = JSON.parse(body);
|
|
|
115
|
+ expect(response.statusCode).toBe(200);
|
|
|
116
|
+ expect(body.society).not.toBe(null);
|
|
|
117
|
+ expect(typeof body.society).toBe("object");
|
|
|
118
|
+ expect(JSON.stringify(body.society)).toEqual(JSON.stringify({}));
|
|
|
119
|
+ done();
|
|
|
120
|
+ });
|
|
|
121
|
+ });
|
|
|
122
|
+ }); //end GET /society/view/:societyid
|
|
|
123
|
+
|
|
|
124
|
+});
|