var expect = require("chai").expect,
    exec = require('child_process').exec,
    request = require('request')

describe("when using the example JSON file", function() {
    before(function(done) {
        exec('npm start');
        setTimeout(function() { done(); }, 1500);
    });

    it("should redirect the root to the start node", function(done) {
        request("http://localhost:3000/", function(error, response, body) {
            expect(body).to.exist;
            expect(body).to.equal('<?xml version="1.0" encoding="UTF-8"?><Response><Gather method="GET" numDigits="3" finishOnKey="*"><Say voice="alice" language="en">This is the first node</Say><Pause length="2"></Pause><Say>The value of query param &apos;foo&apos; is undefined</Say><Say voice="man">Please make a selection!</Say></Gather></Response>');
            done();
        });
    });

    describe("when the content is a function", function(done) {
        it("should execute when it's the root content", function(done) {
            request("http://localhost:3000/second?foo=Applesauce", function(error, response, body) {
                expect(body).to.equal('<?xml version="1.0" encoding="UTF-8"?><Response><Say>This is the second node. Foo is Applesauce</Say></Response>');
                done();
            });        
        })

        it("should execute when it's part of a content array", function(done) {
            request("http://localhost:3000/first?foo=Applesauce", function(error, response, body) {
                expect(body).to.exist;
                expect(body).to.equal('<?xml version="1.0" encoding="UTF-8"?><Response><Gather method="GET" numDigits="3" finishOnKey="*"><Say voice="alice" language="en">This is the first node</Say><Pause length="2"></Pause><Say>The value of query param &apos;foo&apos; is Applesauce</Say><Say voice="man">Please make a selection!</Say></Gather></Response>');
                done();
            });        
        });
    });

    describe("when passing parameters", function(done) {
        it("should persist through a Digit redirect", function(done) {
            request("http://localhost:3000/first?foo=Applesauce", function(error, response, body) {
                expect(body).to.equal('<?xml version="1.0" encoding="UTF-8"?><Response><Gather method="GET" numDigits="3" finishOnKey="*"><Say voice="alice" language="en">This is the first node</Say><Pause length="2"></Pause><Say>The value of query param &apos;foo&apos; is Applesauce</Say><Say voice="man">Please make a selection!</Say></Gather></Response>');
                done();
            });        
        });

        it("should persist through a root redirect", function(done) {
            request("http://localhost:3000/?foo=Applesauce", function(error, response, body) {
                expect(body).to.exist;
                expect(body).to.equal('<?xml version="1.0" encoding="UTF-8"?><Response><Gather method="GET" numDigits="3" finishOnKey="*"><Say voice="alice" language="en">This is the first node</Say><Pause length="2"></Pause><Say>The value of query param &apos;foo&apos; is Applesauce</Say><Say voice="man">Please make a selection!</Say></Gather></Response>');
                done();
            });        
        });
    });
});

@@ -2127,32 +2127,41 @@
 host:3000/first?
+Digits=1&
 foo=Applesauce%22,
@@ -2287,265 +2287,59 @@
 se%3E%3C
-Gather method=%22GET%22 numDigits=%223%22 finishOnKey=%22*%22%3E%3CSay voice=%22alice%22 language=%22en%22%3EThis is the first node%3C/Say%3E%3CPause length=%222%22%3E%3C/Pause%3E%3CSay%3EThe value of query param &apos;foo&apos; is Applesauce%3C/Say%3E%3CSay voice=%22man%22%3EPlease make a selection!%3C/Say%3E%3C/Gather
+Say%3EThis is the second node. Foo is Applesauce%3C/Say
 %3E%3C/R
@@ -2580,47 +2580,8 @@
 ) %7B%0A
-                expect(body).to.exist;%0A
     

Fix wonky tests