"use strict";

var request = require('request');
var assert = require('assert');
var nconf = require('nconf');
var fs = require('fs');
var customerMock = require('../mock/customerSession');
var baseUrl = require('../../common').baseUrl;

describe('api', function () {

    var cid;

    before(function (done) {
        customerMock.create(function (res) {
            var customer = JSON.parse(res.body);
            cid = customer.msg.cid;
            done();
        });
    });


    after(function (done) {
        customerMock.delete(cid, done);
    });

    describe('#offline', function () {
        describe('POST /offlines', function () {

            describe('request is normal', function () {
                it('should response with success', function (done) {
                    request.post({
                        url: baseUrl + '/offlines',
                        form: {cid: cid, name: 'jian', email: 'test@gmail.com', content: 'test'}
                    }, function (err, res) {
                        assert.ifError(err);
                        var data = JSON.parse(res.body);
                        assert.equal(data.code, 200);
                        done();
                    });
                });
            });

            describe('request_name is null', function () {
                it('should response code 8000', function (done) {
                    request.post({
                        url: baseUrl + '/offlines',
                        form: {cid: cid, name: '', email: 'test@gmail.com', content: 'co'}
                    }, function (err, res) {
                        assert.ifError(err);
                        var data = JSON.parse(res.body);
                        assert.equal(data.code, 8000);
                        done();
                    });
                });
            });

            describe('request_email is error', function () {
                it('should response code 8001', function (done) {
                    request.post({
                        url: baseUrl + '/offlines',
                        form: {cid: cid, name: 'jian', email: 'email', content: 'co'}
                    }, function (err, res) {
                        assert.ifError(err);
                        var data = JSON.parse(res.body);
                        assert.equal(data.code, 8001);
                        done();
                    });
                });
            });

            describe('request_content is null', function () {
                it('should response code 8002', function (done) {
                    request.post({
                        url: baseUrl + '/offlines',
                        form: {cid: cid, name: 'jian', email: 'test@gmail.com', content: ''}
                    }, function (err, res) {
                        assert.ifError(err);
                        var data = JSON.parse(res.body);
                        assert.equal(data.code, 8002);
                        done();
                    });
                });
            });

            describe('Length of request_content is more than 256', function () {
                it('should response code 8002', function (done) {
                    var content = 'a'.repeat(258);
                    request.post({
                        url: baseUrl + '/offlines',
                        form: {cid: cid, name: 'jian', email: 'test@gmail.com', content: content}
                    }, function (err, res) {
                        assert.ifError(err);
                        var data = JSON.parse(res.body);
                        assert.equal(data.code, 8002);
                        done();
                    });
                });
            });

        });
    });
});
@@ -585,32 +585,33 @@
 , function () %7B%0A
+%0A
         describe
@@ -946,20 +946,28 @@
 ntent: '
-test
+offline body
 '%7D%0A     
@@ -3732,28 +3732,729 @@
 %7D);%0A%0A        %7D);
+%0A%0A        describe('POST /offlines/:uuid/reply', function () %7B%0A            // how to get ?%0A            var uuid='';%0A%0A            describe('request is normal', function () %7B%0A                it('should response with success', function (done) %7B%0A                    request.post(%7B%0A                        url: baseUrl + '/offlines/' + uuid + '/reply',%0A                        form: %7Bcontent: 'reply'%7D%0A                    %7D, function (err, res) %7B%0A                        assert.ifError(err);%0A                        var data = JSON.parse(res.body);%0A                        assert.equal(data.code, 200);%0A                        done();%0A                    %7D);%0A                %7D);%0A            %7D);%0A        %7D);
 %0A    %7D);%0A%7D);

test offline