diff --git a/src/dash/vo/DescriptorType.js b/src/dash/vo/DescriptorType.js index 98ad2e4961..53a6ff9057 100644 --- a/src/dash/vo/DescriptorType.js +++ b/src/dash/vo/DescriptorType.js @@ -44,7 +44,7 @@ class DescriptorType { init(data) { if (data) { this.schemeIdUri = data.schemeIdUri ? data.schemeIdUri : null; - this.value = data.value ? data.value : null; + this.value = data.value ? data.value.toString() : null; this.id = data.id ? data.id : null; // Only add the DVB extensions if they exist if (data[DashConstants.DVB_URL]) { @@ -65,7 +65,7 @@ class DescriptorType { return ( this.schemeIdUri === entry.schemeIdUri && ( this.value ? - (this.value.match(entry.value)) : // check if provided value matches RegExp + (this.value.toString().match(entry.value)) : // check if provided value matches RegExp (''.match(entry.value)) // check if RegExp allows absent value ) ); diff --git a/test/unit/test/dash/dash.vo.DescriptorType.js b/test/unit/test/dash/dash.vo.DescriptorType.js index f0b89ee4fe..bed1491a36 100644 --- a/test/unit/test/dash/dash.vo.DescriptorType.js +++ b/test/unit/test/dash/dash.vo.DescriptorType.js @@ -1,44 +1,135 @@ import DescriptorType from '../../../../src/dash/vo/DescriptorType.js'; -import {expect} from 'chai'; +import { expect } from 'chai'; describe('DescriptorType', () => { - it('should be constructed with null values', () => { - const dt = new DescriptorType(); - expect(dt).to.deep.equal({ - schemeIdUri: null, - value: null, - id: null + describe('Initialization', () => { + it('should be constructed with null values', () => { + const dt = new DescriptorType(); + expect(dt).to.deep.equal({ + schemeIdUri: null, + value: null, + id: null + }); }); - }); - it('should initialise with correct base values', () => { - const dt = new DescriptorType(); - dt.init({ - schemeIdUri: 'testScheme', - value: '1', + it('should initialise with correct base values', () => { + const dt = new DescriptorType(); + dt.init({ + schemeIdUri: 'testScheme', + value: '1', + }); + expect(dt).to.deep.equal({ + schemeIdUri: 'testScheme', + value: '1', + id: null + }); }); - expect(dt).to.deep.equal({ - schemeIdUri: 'testScheme', - value: '1', - id: null + + it('should initialise with correct base values and type conversion', () => { + const dt = new DescriptorType(); + dt.init({ + schemeIdUri: 'testScheme', + value: 1, + }); + expect(dt).to.deep.equal({ + schemeIdUri: 'testScheme', + value: '1', + id: null + }); + }); + + it('should initialise with known dvb extensions if present', () => { + const dt = new DescriptorType(); + dt.init({ + schemeIdUri: 'testScheme', + value: '1', + 'dvb:url': 'testUrl' + }); + expect(dt).to.deep.equal({ + schemeIdUri: 'testScheme', + value: '1', + id: null, + dvbUrl: 'testUrl' + }); }); }); - it('should initialise with known dvb extensions if present', () => { - const dt = new DescriptorType(); - dt.init({ - schemeIdUri: 'testScheme', - value: '1', - 'dvb:url': 'testUrl' + describe('inArray', () => { + it('should return false array is empty', () => { + const dt = new DescriptorType(); + dt.init({ + schemeIdUri: 'testScheme', + value: 10 + }); + const testArray = []; + + let ret = dt.inArray(testArray); + expect(ret).to.be.false; }); - expect(dt).to.deep.equal({ - schemeIdUri: 'testScheme', - value: '1', - id: null, - dvbUrl: 'testUrl' + + it('should find a descriptor if only the schemeIdUri is provided', () => { + const dt = new DescriptorType(); + dt.init({ + schemeIdUri: 'testScheme', + value: 10 + }); + const testArray = [ + { schemeIdUri: 'notSupportedTestScheme' }, + { schemeIdUri: 'testScheme' }, + { schemeIdUri: 'notSupported' } + ]; + + let ret = dt.inArray(testArray); + expect(ret).to.be.true; }); - }); + it('should not erroneously match a descriptor if different schemeIdUri are provided', () => { + const dt = new DescriptorType(); + dt.init({ + schemeIdUri: 'testScheme', + value: 10 + }); + const testArray = [ + { schemeIdUri: 'notSupportedTestScheme' }, + { schemeIdUri: 'notSupported' } + ]; + + let ret = dt.inArray(testArray); + expect(ret).to.be.false; + }); + + it('should find a descriptor if schemeIdUri and value is provided', () => { + const dt = new DescriptorType(); + dt.init({ + schemeIdUri: 'testScheme', + value: 2 + }); + const testArray = [ + { schemeIdUri: 'notSupportedTestScheme', value: '1' }, + { schemeIdUri: 'testScheme', value: '2' }, + { schemeIdUri: 'notSupported', value: '3' } + ]; + + let ret = dt.inArray(testArray); + expect(ret).to.be.true; + }); + + it('should not find a descriptor if schemeIdUri is provided and value not matches', () => { + const dt = new DescriptorType(); + dt.init({ + schemeIdUri: 'testScheme', + value: 3 + }); + const testArray = [ + { schemeIdUri: 'notSupportedTestScheme', value: '1' }, + { schemeIdUri: 'testScheme', value: '1' }, + { schemeIdUri: 'notSupported', value: '1' } + ]; + + let ret = dt.inArray(testArray); + expect(ret).to.be.false; + }); + }); });