var filter = require('../../lib/index').filter;
var assert = require('../../lib/index').assert;

var should = require('chai').should();

describe('filter.all', function () {
    var assertions = [
        assert.entry.isResourceType('Foo'),
        function(entry){
            return entry.content.value !== undefined;
        }
    ];
    var resource = {
        resourceType: 'Bundle',
        entry: [
            {
                id: 1,
                content: {
                    resourceType: 'Foo',
                    value: 123456
                }
            },
            {
                id: 2,
                content: {
                    resourceType: 'Foo'
                }
            },
            {
                id: 3,
                content: {
                    resourceType: 'Fubar',
                    value: 123456
                }
            },
            {
                id: 4,
                content: {
                    resourceType: 'Bar'
                }
            }
        ]
    };

    it('should throw exception if assertions undefined', function () {
        should.Throw(function () {
            filter.all();
        });
    });

    it('should return a filtered list of entries', function () {
        var result = resource.entry.filter(filter.all(assertions));

        should.exist(result);
        result.length.should.equal(1);
    });

    it('should return a filtered list of entries for a single assertion', function () {
        var result = resource.entry.filter(filter.all(assertions[0]));

        should.exist(result);
        result.length.should.equal(2);
    });
});

