'use strict';

var _ = require('lodash'),
    assert = require('assert'),
    filters = require('../src/filters');


describe('filters', function () {

    var URL = 'github.com';

    function req(url, param) {
        var r = {};
        r[param || 'data'] = {
            url: url
        };
        return r;
    }

    function res(value) {
        return {
            sendFile: function () {
                return value;
            }
        };
    }


    describe('merge', function () {

        function next(req) {
            return function () {
                return req.data.url;
            };
        }

        it('should take url from body', function () {
            var r = req(URL, 'body');
            assert.equal(URL, filters.merge(r, res(), next(r)));
        });

        it('should take url from query', function () {
            var r = req(URL, 'query');
            assert.equal(URL, filters.merge(r, res(), next(r)));
        });

        it('should take from url query in priority', function () {
            var r = _.defaults(req(URL, 'query'), req(URL + URL, 'body'));
            assert.equal(URL, filters.merge(r, res(), next(r)));
        });

    });

    describe('usage', function () {

        var next = function(value) {
            return function () {
                return value;
            };
        },
        usage = filters.usage({ ui: true });

        it('should process url parameter', function () {
            assert.equal(true, usage(req(URL), res(false), next(true)));
        });

        it('should process next function', function () {
            assert.equal(true, usage(req(null), res(true), next(false)));
            assert.equal(true, usage(req(''), res(true), next(false)));
        });

    });

});

@@ -140,25 +140,24 @@
 nction () %7B%0A
-%0A
     var URL 
@@ -170,22 +170,31 @@
 hub.com'
-;%0A%0A   
+,%0A        req =
  functio
@@ -195,19 +195,16 @@
 unction 
-req
 (url, pa
@@ -206,24 +206,28 @@
 l, param) %7B%0A
+    
         var 
@@ -242,16 +242,20 @@
         
+    
 r%5Bparam 
@@ -281,16 +281,20 @@
         
+    
 url: url
@@ -294,35 +294,43 @@
 rl: url%0A        
+  
+  
 %7D;%0A
+    
         return r
@@ -331,26 +331,40 @@
 turn r;%0A
+    
     %7D
-%0A%0A   
+,%0A        res =
  functio
@@ -365,19 +365,16 @@
 unction 
-res
 (value) 
@@ -379,24 +379,28 @@
 ) %7B%0A        
+ 
+   
 return %7B%0A   
@@ -408,16 +408,20 @@
         
+  
+  
 sendFile
@@ -444,32 +444,36 @@
                 
+    
 return value;%0A  
@@ -462,32 +462,36 @@
   return value;%0A
+    
             %7D%0A  
@@ -500,17 +500,25 @@
     
+    
 %7D;%0A    
+ 
-%7D%0A
+   %7D;
 %0A%0A  
@@ -551,24 +551,34 @@
 on () %7B%0A
-%0A
        
+ var next =
  functio
@@ -579,20 +579,16 @@
 unction 
-next
 (req) %7B%0A
@@ -681,16 +681,17 @@
        %7D
+;
 %0A%0A      
@@ -1291,17 +1291,16 @@
 on () %7B%0A
-%0A
         
@@ -1314,102 +1314,187 @@
 t = 
-function(value) %7B%0A            return function () %7B%0A                return value;%0A            %7D
+_.constant,%0A            usage = filters.usage(%7B ui: true %7D);%0A%0A        it('should depend on configuration', function () %7B%0A            assert.equal(true, null === filters.usage(%7B%7D))
 ;%0A  
@@ -1503,25 +1503,39 @@
     
-%7D,%0A
     
-    usage 
+assert.equal(false, null ==
 = fi
@@ -1549,32 +1549,45 @@
 sage(%7B ui: true 
+%7D));%0A        
 %7D);%0A%0A        it(
@@ -1943,12 +1943,276 @@
    %7D);%0A%0A
+    describe('basic', function () %7B%0A%0A        it('should depend on configuration', function () %7B%0A            assert.equal(true, null === filters.basic(%7B%7D));%0A            assert.equal(false, null === filters.basic(%7B security: %7B basic: %7B%7D %7D %7D));%0A        %7D);%0A%0A    %7D);%0A%0A
 %7D);%0A

Add more unit tests for filters