const request = require('supertest')
const uuidv4 = require('uuid/v4')

function Push (uuid) {
  const mlkccaEndpoint = 'https://pubsub1.mlkcca.com'
  const pushURL = '/api/push/demo/demo?c={{dspath}}'
  // const onPushURL = '/on/push/demo/demo?c=[["{{dspath}}",0]]'

  describe('GET /push/', function () {
    let agent = request.agent(mlkccaEndpoint)

    it('should return 500 when no paramaters', function (done) {
      agent
      .get(pushURL.replace(/{{dspath}}/, 'http/' + uuid + '/push/get'))
      .expect(500)
      .end(function (err, res) {
        if (err) return done(err)
        done()
      })
    })

    it('should return 400 when v === empty', function (done) {
      agent
      .get(pushURL.replace(/{{dspath}}/, 'http/' + uuid + '/push/get&v='))
      .expect(400)
      .end(function (err, res) {
        if (err) return done(err)
        done()
      })
    })

    it('should return 200 when paramaters are valid', function (done) {
      agent
      .get(pushURL.replace(/{{dspath}}/, 'http/' + uuid + '/push/get') + '&v={"val":10}')
      .expect(function (res) {
        let result = JSON.parse(res.text)
        res.body = {
          err: result.err
        }
      })
      .expect(200, {
        err: null
      }, done)
    })
  })

  describe('POST /push/', function () {
    let agent = request.agent(mlkccaEndpoint)

    it('should return 500 when no paramaters', function (done) {
      agent
      .post(pushURL.replace(/{{dspath}}/, 'http/' + uuid + '/push/post'))
      .send({})
      .expect(500)
      .end(function (err, res) {
        if (err) return done(err)
        done()
      })
    })

    it('should return 400 when v === empty', function (done) {
      agent
      .post(pushURL.replace(/{{dspath}}/, 'http/' + uuid + '/push/post'))
      .send({v: ''})
      .expect(400)
      .end(function (err, res) {
        if (err) return done(err)
        done()
      })
    })

    it('should return 200 when paramaters are valid', function (done) {
      agent
      .post(pushURL.replace(/{{dspath}}/, 'http/' + uuid + '/push/post'))
      .send({v: '{"val":10}'})
      .expect(function (res) {
        let result = JSON.parse(res.text)
        res.body = {
          err: result.err
        }
      })
      .expect(200, {
        err: null
      }, done)
    })
  })
}

Push(global.uuid || uuidv4())

module.exports = Push

@@ -122,16 +122,20 @@
 https://
+stg-
 pubsub1.
@@ -175,25 +175,66 @@
 pi/push/
-demo/demo
+SJL79bh1z/Slb_e7RMdYz8feIaiacTfXkJjlmew5TQJT0GPj8O
 ?c=%7B%7Bdsp
@@ -406,33 +406,33 @@
 ('should return 
-5
+4
 00 when no param
@@ -547,33 +547,33 @@
 )%0A      .expect(
-5
+4
 00)%0A      .end(f
@@ -1416,17 +1416,17 @@
  return 
-5
+4
 00 when 
@@ -1575,17 +1575,17 @@
 .expect(
-5
+4
 00)%0A    

Update http test, 500 -> 400