'use strict';

describe('url parameters', function() {
  it('ignores optional parameters that are missing', function(done) {
    hippie(app, swaggerSchema)
    .get('/foos')
    .end(done);
  });

  it('errors if a required parameter is missing', function() {
    expect(function() {
      hippie(app, swaggerSchema)
      .get('/foos/{fooId}')
      .end();
    }).to.throw(/Missing required parameter in path: fooId/);
  });

  it('replaces path parameters with provided variables', function(done) {
    hippie(app, swaggerSchema)
    .get('/foos/{fooId}')
    .pathParams({ fooId:data.firstFoo.id })
    .end(function(err, res) {
      expect(err).to.be.undefined;
      expect(res.req.path).to.equal('/foos/' + data.firstFoo.id);
      done();
    });
  });

  it('errors if a parameter fails json-schema validation', function() {
    expect(function() {
      hippie(app, swaggerSchema)
      .get('/foos/{fooId}')
      .pathParams({ fooId:45 })
      .end()
    }).to.throw(/Invalid format for parameter {fooId}/);
  });

  it('replaces query string variables', function(done) {
    var limit = 10, offset = 2;

    hippie(app, swaggerSchema)
    .get('/foos?limit={limit}&offset={offset}')
    .queryParams({ limit:limit, offset:offset })
    .end(function(err, res) {
      expect(err).to.be.undefined;
      expect(res.req.path).to.equal('/foos?limit=' + limit + '&offset=' + offset);
      done();
    });
  });

  describe('header variables', function() {
    it('errors if the header is required', function() {
      var objectAssign = require('object-assign'),
          headerSchema = objectAssign({}, swaggerSchema);

      //set X-Total-Count to be required for this test
      headerSchema["paths"]["/foos"]["get"]["parameters"].filter(function(param) {
        return param.name == 'X-Total-Count';
      })[0]["required"] = true;

      expect(function() {
        hippie(app, headerSchema)
        .get('/foos')
        .end();
      }).to.throw(/Missing required parameter in header: X-Total-Count/)
    });

    it('replaces header variables', function(done) {
      hippie(app, swaggerSchema)
      .get('/foos')
      .header("X-Total-Count", 1)
      .end(function(err, res) {
        expect(err).to.be.undefined;
        expect(res.request.headers["X-Total-Count"]).to.exist;
        expect(res.request.headers["X-Total-Count"]).to.equal(1);
        done();
      });
    });
  });

  it('errors if extra parameters are provided which are not mentioned in the swagger spec', function() {
    expect(function() {
      hippie(app, swaggerSchema)
      .get('/foos')
      .pathParams({ asdf: 50 })
      .end();
    }).to.throw(/Parameter not mentioned in swagger spec: "asdf"/);
  });
});
@@ -194,239 +194,8 @@
 );%0A%0A
-  it('errors if a required parameter is missing', function() %7B%0A    expect(function() %7B%0A      hippie(app, swaggerSchema)%0A      .get('/foos/%7BfooId%7D')%0A      .end();%0A    %7D).to.throw(/Missing required parameter in path: fooId/);%0A  %7D);%0A%0A
   it
@@ -529,274 +529,8 @@
 );%0A%0A
-  it('errors if a parameter fails json-schema validation', function() %7B%0A    expect(function() %7B%0A      hippie(app, swaggerSchema)%0A      .get('/foos/%7BfooId%7D')%0A      .pathParams(%7B fooId:45 %7D)%0A      .end()%0A    %7D).to.throw(/Invalid format for parameter %7BfooId%7D/);%0A  %7D);%0A%0A
   it
@@ -1908,29 +1908,577 @@
  %7D);%0A%0A  
-it('errors if
+describe('errors', function() %7B%0A    it('when a required parameter is missing', function() %7B%0A      expect(function() %7B%0A        hippie(app, swaggerSchema)%0A        .get('/foos/%7BfooId%7D')%0A        .end();%0A      %7D).to.throw(/Missing required parameter in path: fooId/);%0A    %7D);%0A%0A    it('when a parameter fails json-schema validation', function() %7B%0A      expect(function() %7B%0A        hippie(app, swaggerSchema)%0A        .get('/foos/%7BfooId%7D')%0A        .pathParams(%7B fooId:45 %7D)%0A        .end()%0A      %7D).to.throw(/Invalid format for parameter %7BfooId%7D/);%0A    %7D);%0A%0A    it('when
  extra p
@@ -2559,24 +2559,26 @@
 ion() %7B%0A    
+  
 expect(funct
@@ -2583,32 +2583,34 @@
 ction() %7B%0A      
+ 
+ 
 hippie(app, swag
@@ -2618,32 +2618,34 @@
 erSchema)%0A      
+  
 .get('/foos')%0A  
@@ -2638,24 +2638,26 @@
 et('/foos')%0A
+  
       .pathP
@@ -2678,32 +2678,34 @@
 50 %7D)%0A      
+  
 .end();%0A
     %7D).to.th
@@ -2688,24 +2688,26 @@
     .end();%0A
+  
     %7D).to.th
@@ -2762,16 +2762,24 @@
 sdf%22/);%0A
+    %7D);%0A
   %7D);%0A%7D)

reorganize tests