Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* global after, it, describe */
- var request = require("supertest");
- var expect = require("chai").expect;
- const app = require("../../index").http;
- var Account = require("../../models/account");
- const RESPONSE = require("../../constants/Response");
- const STAFF_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzU4NzU1NDksImFjY291bnQiOnsiYWN0aXZlIjp0cnVlLCJ2aXNpYmxlIjp0cnVlLCJfaWQiOiI1YjJmNWFiNWIxNzYxNzBmMmM2ZTU1NTQiLCJyb2xlIjoic3RhZmYiLCJ1c2VybmFtZSI6InRlc3QiLCJlbWFpbCI6InZpZXRAZ21haWwuY29tIiwicGFzc3dvcmQiOiJlMTBhZGMzOTQ5YmE1OWFiYmU1NmUwNTdmMjBmODgzZSIsImZ1bGxuYW1lIjoiSOG6vyBuw7QifSwiaWF0IjoxNTM1MjcwNzQ5fQ.-aEUkxNNshik8AhkyK7OPyQzSARXBX2LJb0Yr0qHWRM";
- const TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzU3Mjk5NDYsImFjY291bnQiOnsiYWN0aXZlIjp0cnVlLCJ2aXNpYmxlIjp0cnVlLCJfaWQiOiI1YjFhMDFjOTgxNDc0ZDFlMzA3Njk4MmYiLCJ1c2VybmFtZSI6ImFuaGR2IiwiZW1haWwiOiJ2aWV0YW5oczA4MTdAZ21haWwuY29tIiwicGFzc3dvcmQiOiIzYjAyMmVlZmZmYzVkYTE5ZWJjNTg5YTU2OTQyYzNlNCIsInJvbGUiOiJhZG1pbiIsImZ1bGxuYW1lIjoiVmlldCBBbmgiLCJhZGRyZXNzIjoiSMOgIE7hu5lpIiwicGhvbmUiOiIwOTY2MzQzNjM1In0sImlhdCI6MTUzNTEyNTE0Nn0.LQxDVHsPZjZlL-wfJUWXealiV4HVZ10W5YRah_gGgxU";
- describe("Broadcast API", () => {
- describe("POST /api/broadcast/send/psid", () => {
- describe("access denied",() => {
- it("it should be return a error message",done => {
- request(app)
- .post("/api/broadcast/send/psid")
- .send({ email: "vietanh@gmail.com"})
- .set("Authorization", `Bearer ${STAFF_TOKEN}`)
- .set("content-type", "application/json")
- .expect(403).end(function (err, res) {
- expect(res.body.err).to.equal(RESPONSE.ERROR.ACCESS_DENIED);
- done();
- });
- });
- });
- describe("bad request",() => {
- it("it should be return a error message",done => {
- request(app)
- .post("/api/broadcast/send/psid")
- .send({ psids: ["hello"]})
- .set("Authorization", `Bearer ${TOKEN}`)
- .set("content-type", "application/json")
- .expect(400).end(function (err, res) {
- expect(res.body.err).to.equal(RESPONSE.ERROR.MESSAGE_REQUIRED);
- done();
- });
- });
- });
- describe("sent message success",() => {
- it("it should be return a success message",done => {
- request(app)
- .post("/api/broadcast/send/psid")
- .send({ psids: ["1891301497555754"], message: {text:"waooo"}})
- .set("Authorization", `Bearer ${TOKEN}`)
- .set("content-type", "application/json")
- .expect(200).end(function (err, res) {
- expect(res.body.result).to.equal(RESPONSE.SUCCESS.SUCCESS);
- done();
- });
- });
- });
- });
- describe("POST /api/broadcast/send/tag", () => {
- describe("access denied",() => {
- it("it should be return a error message",done => {
- request(app)
- .post("/api/broadcast/send/tag")
- .send({ email: "vietanh@gmail.com"})
- .set("Authorization", `Bearer ${STAFF_TOKEN}`)
- .set("content-type", "application/json")
- .expect(403).end(function (err, res) {
- expect(res.body.err).to.equal(RESPONSE.ERROR.ACCESS_DENIED);
- done();
- });
- });
- });
- describe("bad request",() => {
- it("it should be return a error message",done => {
- request(app)
- .post("/api/broadcast/send/tag")
- .send({ tags: ["hello"]})
- .set("Authorization", `Bearer ${TOKEN}`)
- .set("content-type", "application/json")
- .expect(400).end(function (err, res) {
- expect(res.body.err).to.equal(RESPONSE.ERROR.MESSAGE_REQUIRED);
- done();
- });
- });
- });
- describe("sent message success",() => {
- it("it should be return a success message",done => {
- request(app)
- .post("/api/broadcast/send/tag")
- .send({ tags: ["vietanhs0817"], message: {text:"waooo"}})
- .set("Authorization", `Bearer ${TOKEN}`)
- .set("content-type", "application/json")
- .expect(200).end(function (err, res) {
- expect(res.body.result).to.equal(RESPONSE.SUCCESS.SUCCESS);
- done();
- });
- });
- });
- });
- after(done => {
- Account.update({ username: "anhdv" }, { $set: { password: "3b022eefffc5da19ebc589a56942c3e4" } }, () => {
- Account.remove({ username: "wao" }, done);
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement