// 'Model/Controller' Spec Skeleton
// ---------------------------------------
//
// !! REMEMBER !!
//      * fake servers and stubs are generated automatically, so delete those you do not need
//      * server URL regexes are based on the model, so they are likely to be insufficient or incorrect for your test
//      * the response data is also based on the Model; check its correctness
//      * variable names are also generated, so edit them to make them more readable
//      * test spec names should be edited for readability too
//      * Report any bugs here https://github.com/viadeo/abu
// And
//      replace this comment with proper documentation of your test!
//

//
// -- Add description here --
//
// @author your name
// @link https://github.com/pivotal/jasmine/wiki
//
describe('{{scope}}/{{name}} model-controller', function() {

    'use strict';

    beforeEach(function() {
        {{#if controllerGlobals.length}}
        // Controller / View references
        // ---------------------------------------
        {{#each controllerGlobals}}var {{variableName}} = tetra.debug.{{type}}.retrieve('{{scope}}', '{{name}}');
        {{/each}}
        {{/if}}
        {{#if fakeServers.length}}
        // Fake Servers & Response Paths
        // ---------------------------------------
        this.server = sinon.fakeServer.create();

        var FAIL = {
           "status": "FAIL",
           "data": {},
           "alerts": {},
           "errors": []
        };
        {{#each fakeServers}}
         {{#if isGET}}
         var {{name}}Data = {{{responseObj}}};
         var {{name}}_GET = {
            "status": "SUCCESS",
            "data": {{name}}Data,
            "alerts": {},
            "errors": []
         };
         this.server.respondWith('GET', /{{#if url}}{{{url}}}{{else}}url{{/if}}/,
            [200, {'Content-type': '{{contentType}}' }, JSON.stringify({{name}}Data)]);
         this.server.respondWith('GET', /fail_flag/,
            [200, {'Content-type': '{{contentType}}' }, JSON.stringify(FAIL)]);
         this.server.respondWith('GET', /error_flag/,
            [500, {'Content-type': '{{contentType}}' }, ""]);
         {{else}}
         var {{name}}_POST = {
             "status": "SUCCESS",
             "data": {},
             "alerts": {},
             "errors": []
         };
         this.server.respondWith('POST', /{{#if url}}{{{url}}}{{else}}url{{/if}}/, function(xhr, id) {
             var postBody = xhr.requestBody || '';
             switch(postBody) {
                 case "success_flag":
                     xhr.respond(200, {'Content-type': '{{contentType}}' }, JSON.stringify({{name}}_POST));
                     break;
                 case "fail_flag":
                     xhr.respond(200, {'Content-type': '{{contentType}}' }, JSON.stringify(FAIL));
                     break;
                 case "error_flag":
                     xhr.respond(500, {'Content-type': '{{contentType}}' }, JSON.stringify(FAIL));
                     break;
                 default:
                     break;
             }
         });
         {{/if}}
        {{/each}}
        {{/if}}
        {{#if controllerStubs.length}}
        // Stubs
        // ---------------------------------------
        {{#each controllerStubs}}this.{{variableName}} = sinon.stub({{globalName}}.events.{{type}}, '{{target}}');
        {{/each}}
        {{/if}}
        this.growlStub = sinon.stub(VNS.ui, 'growl');
    });

    afterEach(function() {
        {{#if fakeServers.length}}this.server.restore();{{/if}}
        {{#each controllerStubs}}this.{{variableName}}.restore();
        {{/each}}
        this.growlStub.restore();
    });

    // Test specs
    // ------------------------
    {{#if controllerSpecs.length}}{{#each controllerSpecs}}
    it('should {{name}}', function(){
        expect(false).toBe(true);
    });
    {{/each}}
    {{else}}
    it('should do something', function(){
        expect(false).toBe(true);
    });
    {{/if}}
});