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

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

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

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

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

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

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

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

