Просмотр исходного кода

Add unit tests for /society/promote/ and /society/kick

Matt Coles лет назад: 9
Родитель
Сommit
981ef60f67
1 измененных файлов с 199 добавлено и 0 удалено
  1. 199 0
      spec/society-ops-spec.js

+ 199 - 0
spec/society-ops-spec.js

@@ -293,4 +293,203 @@ describe("Society Operations", function () {
293 293
     });
294 294
   }); //end POST /society/leave/
295 295
 
296
+  describe("POST /society/promote/", function() {
297
+    it("rejects invalid admin auth key", function (done) {
298
+      request({
299
+        url: base_url + "/society/join/",
300
+        method: "POST",
301
+        json: {
302
+          society: "foo123soc",
303
+          auth: foo456auth
304
+        }
305
+      }, function (error, response, body) {
306
+        request({
307
+          url: base_url + "/society/promote/",
308
+          method: "POST",
309
+          json: {
310
+            user: "foo456",
311
+            society: "foo123soc",
312
+            auth: "nah"
313
+          }
314
+        }, function (error, response, body) {
315
+          expect(response.statusCode).toBe(200);
316
+          expect(body.success).toBe(0);
317
+          expect(body.error).toBe(1);
318
+          done();
319
+        });
320
+      });
321
+    });
322
+
323
+    it("successfully promotes a user", function (done) {
324
+      request({
325
+        url: base_url + "/society/promote/",
326
+        method: "POST",
327
+        json: {
328
+          user: "foo456",
329
+          society: "foo123soc",
330
+          auth: foo123auth
331
+        }
332
+      }, function (error, response, body) {
333
+        expect(response.statusCode).toBe(200);
334
+        expect(body.success).toBe(1);
335
+        expect(body.error).toBe(0);
336
+        done();
337
+      });
338
+    });
339
+
340
+    it("doesn't promote a user twice", function (done) {
341
+      request({
342
+        url: base_url + "/society/promote/",
343
+        method: "POST",
344
+        json: {
345
+          user: "foo456",
346
+          society: "foo123soc",
347
+          auth: foo123auth
348
+        }
349
+      }, function (error, response, body) {
350
+        expect(response.statusCode).toBe(200);
351
+        expect(body.success).toBe(0);
352
+        expect(body.error).toBe(3);
353
+        done();
354
+      });
355
+    });
356
+
357
+    it("doesn't promote users who aren't in the society", function (done) {
358
+      request({
359
+        url: base_url + "/society/promote/",
360
+        method: "POST",
361
+        json: {
362
+          user: "foo789",
363
+          society: "foo123soc",
364
+          auth: foo123auth
365
+        }
366
+      }, function (error, response, body) {
367
+        expect(response.statusCode).toBe(200);
368
+        expect(body.success).toBe(0);
369
+        expect(body.error).toBe(2);
370
+        done();
371
+      });
372
+    });
373
+
374
+    it("rejects malformed requests", function (done) {
375
+      request({
376
+        url: base_url + "/society/promote/",
377
+        method: "POST",
378
+        json: {
379
+          user: "foo456",
380
+          society: "foo123soc",
381
+        }
382
+      }, function (error, response, body) {
383
+        expect(response.statusCode).toBe(200);
384
+        expect(body.success).toBe(0);
385
+        expect(body.error).toBe(4);
386
+        done();
387
+      });
388
+    });
389
+  }); //end POST /society/promote/
390
+
391
+  describe("POST /society/kick/", function() {
392
+    it("rejects invalid admin auth key", function (done) {
393
+      request({
394
+        url: base_url + "/user/auth/",
395
+        method: "POST",
396
+        json: {
397
+          user: "foo789",
398
+          password: "foofoo"
399
+        }
400
+      }, function (error, response, body) {
401
+        foo789auth = body["auth-key"];
402
+        request({
403
+          url: base_url + "/society/join/",
404
+          method: "POST",
405
+          json: {
406
+            society: "foo123soc",
407
+            auth: foo789auth
408
+          }
409
+        }, function (error, response, body) {
410
+          request({
411
+            url: base_url + "/society/kick/",
412
+            method: "POST",
413
+            json: {
414
+              user: "foo789",
415
+              society: "foo123soc",
416
+              auth: "nah"
417
+            }
418
+          }, function (error, response, body) {
419
+            expect(response.statusCode).toBe(200);
420
+            expect(body.success).toBe(0);
421
+            expect(body.error).toBe(1);
422
+            done();
423
+          });
424
+        });
425
+      })
426
+    });
427
+
428
+    it("successfully kicks a user", function (done) {
429
+      request({
430
+        url: base_url + "/society/kick/",
431
+        method: "POST",
432
+        json: {
433
+          user: "foo789",
434
+          society: "foo123soc",
435
+          auth: foo123auth
436
+        }
437
+      }, function (error, response, body) {
438
+        expect(response.statusCode).toBe(200);
439
+        expect(body.success).toBe(1);
440
+        expect(body.error).toBe(0);
441
+        done();
442
+      });
443
+    });
444
+
445
+    it("doesn't kick a user twice", function (done) {
446
+      request({
447
+        url: base_url + "/society/kick/",
448
+        method: "POST",
449
+        json: {
450
+          user: "foo789",
451
+          society: "foo123soc",
452
+          auth: foo123auth
453
+        }
454
+      }, function (error, response, body) {
455
+        expect(response.statusCode).toBe(200);
456
+        expect(body.success).toBe(0);
457
+        expect(body.error).toBe(2);
458
+        done();
459
+      });
460
+    });
461
+
462
+    it("doesn't kick admins", function (done) {
463
+      request({
464
+        url: base_url + "/society/kick/",
465
+        method: "POST",
466
+        json: {
467
+          user: "foo456",
468
+          society: "foo123soc",
469
+          auth: foo123auth
470
+        }
471
+      }, function (error, response, body) {
472
+        expect(response.statusCode).toBe(200);
473
+        expect(body.success).toBe(0);
474
+        expect(body.error).toBe(3);
475
+        done();
476
+      });
477
+    });
478
+
479
+    it("rejects malformed requests", function (done) {
480
+      request({
481
+        url: base_url + "/society/kick/",
482
+        method: "POST",
483
+        json: {
484
+          user: "foo456",
485
+          society: "foo123soc",
486
+        }
487
+      }, function (error, response, body) {
488
+        expect(response.statusCode).toBe(200);
489
+        expect(body.success).toBe(0);
490
+        expect(body.error).toBe(4);
491
+        done();
492
+      });
493
+    });
494
+  }); //end POST /society/kick/
296 495
 });