Advertisement
Guest User

broadcast.test.js

a guest
Aug 26th, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* global after, it, describe */
  2. var request = require("supertest");
  3. var expect = require("chai").expect;
  4. const app = require("../../index").http;
  5. var Account = require("../../models/account");
  6. const RESPONSE = require("../../constants/Response");
  7. const STAFF_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzU4NzU1NDksImFjY291bnQiOnsiYWN0aXZlIjp0cnVlLCJ2aXNpYmxlIjp0cnVlLCJfaWQiOiI1YjJmNWFiNWIxNzYxNzBmMmM2ZTU1NTQiLCJyb2xlIjoic3RhZmYiLCJ1c2VybmFtZSI6InRlc3QiLCJlbWFpbCI6InZpZXRAZ21haWwuY29tIiwicGFzc3dvcmQiOiJlMTBhZGMzOTQ5YmE1OWFiYmU1NmUwNTdmMjBmODgzZSIsImZ1bGxuYW1lIjoiSOG6vyBuw7QifSwiaWF0IjoxNTM1MjcwNzQ5fQ.-aEUkxNNshik8AhkyK7OPyQzSARXBX2LJb0Yr0qHWRM";
  8. const TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzU3Mjk5NDYsImFjY291bnQiOnsiYWN0aXZlIjp0cnVlLCJ2aXNpYmxlIjp0cnVlLCJfaWQiOiI1YjFhMDFjOTgxNDc0ZDFlMzA3Njk4MmYiLCJ1c2VybmFtZSI6ImFuaGR2IiwiZW1haWwiOiJ2aWV0YW5oczA4MTdAZ21haWwuY29tIiwicGFzc3dvcmQiOiIzYjAyMmVlZmZmYzVkYTE5ZWJjNTg5YTU2OTQyYzNlNCIsInJvbGUiOiJhZG1pbiIsImZ1bGxuYW1lIjoiVmlldCBBbmgiLCJhZGRyZXNzIjoiSMOgIE7hu5lpIiwicGhvbmUiOiIwOTY2MzQzNjM1In0sImlhdCI6MTUzNTEyNTE0Nn0.LQxDVHsPZjZlL-wfJUWXealiV4HVZ10W5YRah_gGgxU";
  9.  
  10. describe("Broadcast API", () => {
  11.  
  12.     describe("POST /api/broadcast/send/psid", () => {
  13.         describe("access denied",() => {
  14.             it("it should be return a error message",done => {
  15.                 request(app)
  16.                 .post("/api/broadcast/send/psid")
  17.                 .send({ email: "vietanh@gmail.com"})
  18.                 .set("Authorization", `Bearer ${STAFF_TOKEN}`)
  19.                 .set("content-type", "application/json")
  20.                 .expect(403).end(function (err, res) {
  21.                     expect(res.body.err).to.equal(RESPONSE.ERROR.ACCESS_DENIED);
  22.                     done();
  23.                 });
  24.             });
  25.         });
  26.  
  27.         describe("bad request",() => {
  28.             it("it should be return a error message",done => {
  29.                 request(app)
  30.                 .post("/api/broadcast/send/psid")
  31.                 .send({ psids: ["hello"]})
  32.                 .set("Authorization", `Bearer ${TOKEN}`)
  33.                 .set("content-type", "application/json")
  34.                 .expect(400).end(function (err, res) {
  35.                     expect(res.body.err).to.equal(RESPONSE.ERROR.MESSAGE_REQUIRED);
  36.                     done();
  37.                 });
  38.             });
  39.         });
  40.  
  41.         describe("sent message success",() => {
  42.             it("it should be return a success message",done => {
  43.                 request(app)
  44.                 .post("/api/broadcast/send/psid")
  45.                 .send({ psids: ["1891301497555754"], message: {text:"waooo"}})
  46.                 .set("Authorization", `Bearer ${TOKEN}`)
  47.                 .set("content-type", "application/json")
  48.                 .expect(200).end(function (err, res) {
  49.                     expect(res.body.result).to.equal(RESPONSE.SUCCESS.SUCCESS);
  50.                     done();
  51.                 });
  52.             });
  53.         });
  54.     });
  55.  
  56.     describe("POST  /api/broadcast/send/tag", () => {
  57.         describe("access denied",() => {
  58.             it("it should be return a error message",done => {
  59.                 request(app)
  60.                 .post("/api/broadcast/send/tag")
  61.                 .send({ email: "vietanh@gmail.com"})
  62.                 .set("Authorization", `Bearer ${STAFF_TOKEN}`)
  63.                 .set("content-type", "application/json")
  64.                 .expect(403).end(function (err, res) {
  65.                     expect(res.body.err).to.equal(RESPONSE.ERROR.ACCESS_DENIED);
  66.                     done();
  67.                 });
  68.             });
  69.         });
  70.  
  71.         describe("bad request",() => {
  72.             it("it should be return a error message",done => {
  73.                 request(app)
  74.                 .post("/api/broadcast/send/tag")
  75.                 .send({ tags: ["hello"]})
  76.                 .set("Authorization", `Bearer ${TOKEN}`)
  77.                 .set("content-type", "application/json")
  78.                 .expect(400).end(function (err, res) {
  79.                     expect(res.body.err).to.equal(RESPONSE.ERROR.MESSAGE_REQUIRED);
  80.                     done();
  81.                 });
  82.             });
  83.         });
  84.  
  85.         describe("sent message success",() => {
  86.             it("it should be return a success message",done => {
  87.                 request(app)
  88.                 .post("/api/broadcast/send/tag")
  89.                 .send({ tags: ["vietanhs0817"], message: {text:"waooo"}})
  90.                 .set("Authorization", `Bearer ${TOKEN}`)
  91.                 .set("content-type", "application/json")
  92.                 .expect(200).end(function (err, res) {
  93.                     expect(res.body.result).to.equal(RESPONSE.SUCCESS.SUCCESS);
  94.                     done();
  95.                 });
  96.             });
  97.         });
  98.     });
  99.  
  100.     after(done => {
  101.         Account.update({ username: "anhdv" }, { $set: { password: "3b022eefffc5da19ebc589a56942c3e4" } }, () => {
  102.             Account.remove({ username: "wao" }, done);
  103.         });
  104.     });
  105. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement