var patient = require('../../lib/util/patient');

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

describe('util.patient', function () {
    describe('getIdentifier', function () {
        it('should throw exception if resource undefined', function () {
            should.Throw(function () {
                patient.getIdentifier();
            });
        });

        it('should throw exception if system undefined', function () {
            should.Throw(function () {
                patient.getIdentifier({});
            });
        });

        it('should return identifier', function () {
            var system = 'http://foo.com/bar';
            var candidate = {
                identifier: [
                    {
                        system: 'http://test.com/nomatch',
                        value: 'nomatch'
                    },
                    {
                        system: 'http://foo.com/bar',
                        value: 'bar'
                    }
                ]
            };

            var result = patient.getIdentifier(candidate, system);

            should.exist(result);
            result.system.should.equal('http://foo.com/bar');
            result.value.should.equal('bar');
        });

        it('should return undefined if no match', function () {
            var system = 'http://foo.com/bar';
            var candidate = {
                identifier: [
                    {
                        system: 'http://test.com/nomatch',
                        value: 'nomatch'
                    },
                    {
                        system: 'http://foo.com/xyz',
                        value: 'xyz'
                    }
                ]
            };

            var result = patient.getIdentifier(candidate, system);

            should.not.exist(result);
        });
    });
});