var sample_xform = require('./sample_xform');
var vumigo = require('vumigo_v02');
var basic_auth = vumigo.utils.basic_auth;

module.exports = function() {
    return [
        {
            request: {
                method: "GET",
                url: "http://www.example.org/xform00",
            },
            response: {
                code: "200",
                data: sample_xform,
            },
        },
        {
            request: {
                method: "GET",
                url: "http://www.example.org/xform00",
                headers: {
                    Authorization: basic_auth('testuser', 'testpass')
                },
            },
            response: {
                code: "200",
                data: sample_xform,
            },
        },
        {
            request: {
                method: "GET",
                url: "http://www.example.org/xform01",
            },
            response: {
                code: "500",
                data: 'Server error',
            },
        },
        {
            request: {
                method: "GET",
                url: "http://www.example.org/xform01",
                headers: {
                    Authorization: basic_auth('testuser', 'testpass')
                },
            },
            response: {
                code: "500",
                data: 'Server error',
            },
        },
        {
            request: {
                method: "POST",
                url: "http://www.xforms.org/forms",
                headers: {
                    "Content-Type": "application/xml"
                },
                data: sample_xform,
            },
            response: {
                code: "201",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    "message": "Created XForm.",
                    "status": 201,
                    "id": "cc46192a-8aba-43f3-9d4e-8b78486346dc"
                },
            },
        },
        {
            request: {
                method: "GET",
                url: "http://www.xforms.org/responses/cc46192a-8aba-43f3-9d4e-8b78486346dc/0",
            },
            response: {
                code: "200",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    "message": "Question retrieved successfully.",
                    "status": 200,
                    "question": "What is your name?",
                    "id": "cc46192a-8aba-43f3-9d4e-8b78486346dc"
                },
            },
        },
        {
            request: {
                method: "POST",
                url: "http://www.xforms.org/responses/cc46192a-8aba-43f3-9d4e-8b78486346dc",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    answer: "Jon Snow",
                },
            },
            response: {
                code: "200",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    "id":"cc46192a-8aba-43f3-9d4e-8b78486346dc",
                    "question":"What is your age?",
                    "status":200,
                    "message":"Question completed."
                },
            },
        },
        {
            request: {
                method: "POST",
                url: "http://www.xforms.org/responses/cc46192a-8aba-43f3-9d4e-8b78486346dc",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    answer: "20",
                },
            },
            response: {
                code: "200",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    "message": "XForm completed.",
                    "status": 200,
                    "id": "cc46192a-8aba-43f3-9d4e-8b78486346dc"
                },
            },
        },
        {
            request: {
                method: "GET",
                url: "http://www.xforms.org/answers/cc46192a-8aba-43f3-9d4e-8b78486346dc",
            },
            response: {
                code: "200",
                headers: {
                    "Content-Type": "application/xml",
                },
                data: "<?xml version='1.0' ?><test id=\"test\" version=\"201505270916\"><formhub><uuid /></formhub><name>Jon Snow</name><age>20</age><meta><instanceID /></meta></test>",
            },
        },
        {
            request: {
                method: "POST",
                headers: {
                    "Content-Type": "application/xml",
                },
                data: "<?xml version='1.0' ?><test id=\"test\" version=\"201505270916\"><formhub><uuid /></formhub><name>Jon Snow</name><age>20</age><meta><instanceID /></meta></test>",
            },
            response: {
                code: "200",
            },
        }
    ];
};

@@ -4758,32 +4758,87 @@
 method: %22POST%22,%0A
+                url: %22http://www.badxforms.org/forms%22,%0A
                 
@@ -4893,33 +4893,32 @@
 application/xml%22
-,
 %0A               
@@ -4947,170 +4947,249 @@
 ta: 
-%22%3C?xml version='1.0' ?%3E%3Ctest id=%5C%22test%5C%22 version=%5C%22201505270916%5C%22%3E%3Cformhub%3E%3Cuuid /%3E%3C/formhub%3E%3Cname%3EJon Snow%3C/name%3E%3Cage%3E20%3C/age%3E%3Cmeta%3E%3CinstanceID /%3E%3C/meta%3E%3C/test%3E%22
+sample_xform,%0A            %7D,%0A            response: %7B%0A                code: %22400%22,%0A                headers: %7B%0A                    %22Content-Type%22: %22application/json%22,%0A                %7D,%0A                data: %7B%0A                    %22status%22: 400
 ,%0A  
@@ -5194,35 +5194,32 @@
             
-%7D,%0A
         
     response
@@ -5206,33 +5206,154 @@
         
-    response: %7B%0A 
+%22message%22: %22An error occurred while attempting to save the provided XForm. Please ensure the XML you provided is well-formed and valid.%22,%0A
         
@@ -5355,35 +5355,26 @@
             
-code: %22200%22
+ %7D
 ,%0A          
@@ -5387,16 +5387,17 @@
        %7D
+,
 %0A    %5D;%0A

Add fixture for xforms service down