Skip to content

Commit

Permalink
add some hls specific tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Aug 22, 2023
1 parent f54cc95 commit 88c4fc4
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions test/util/content-steering.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import QUnit from 'qunit';
import ContentSteering from '../../src/util/content-steering';
import { useFakeEnvironment } from '../test-helpers';
import xhrFactory from '../../src/xhr';

QUnit.module('ContentSteering', {
beforeEach(assert) {
this.env = useFakeEnvironment(assert);
this.requests = this.env.requests;
this.fakeVhs = {
xhr: xhrFactory()
};
},
afterEach() {
this.env.restore();
}
});

QUnit.test('Can handle HLS content steering object with serverUri only', function(assert) {
const hlsServerUriOnly = {
serverUri: 'https://content.steering.test'
};
const contentSteering = new ContentSteering(this.fakeVhs.xhr, this.manifestUri, hlsServerUriOnly);

this.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{ "VERSION": 1 }');
assert.equal(contentSteering.reloadUri, hlsServerUriOnly.serverUri, 'reloadUri is expected value');
});

QUnit.test('Can handle HLS content steering object with pathwayId', function(assert) {
const hlsSteeringTag = {
serverUri: 'https://content.steering.test',
pathwayId: 'test'
};
const contentSteering = new ContentSteering(this.fakeVhs.xhr, this.manifestUri, hlsSteeringTag);

contentSteering.mainSegmentLoader_ = {
throughput: {
rate: 99999
}
};
this.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{ "VERSION": 1 }');
assert.equal(contentSteering.reloadUri, hlsSteeringTag.serverUri, 'reloadUri is expected value');
// check pathway query param
assert.equal(this.requests[0].uri, contentSteering.reloadUri + '/?_HLS_pathway=test', 'query parameters are set');
assert.equal(contentSteering.currentCdn, hlsSteeringTag.pathwayId, 'current cdn is expected value');
});

QUnit.test('Can add throughput to steering manifest requests', function(assert) {
const hlsServerUriOnly = {
serverUri: 'https://content.steering.test'
};
const contentSteering = new ContentSteering(this.fakeVhs.xhr, this.manifestUri, hlsServerUriOnly);
const expectedThroughputUrl = hlsServerUriOnly.serverUri + '/?_HLS_throughput=99999';

contentSteering.mainSegmentLoader_ = {
throughput: {
rate: 99999
}
};
assert.equal(contentSteering.setSteeringParams_(hlsServerUriOnly.serverUri), expectedThroughputUrl, 'throughput parameters set as expected');
});

// Steering manifest tests

QUnit.test('Can handle HLS content steering manifest with VERSION', function(assert) {
const hlsServerUriOnly = {
serverUri: 'https://content.steering.test'
};
const contentSteering = new ContentSteering(this.fakeVhs.xhr, this.manifestUri, hlsServerUriOnly);

this.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{ "VERSION": 1 }');
assert.equal(contentSteering.version, 1, 'version is expected value');
// check that ttl is set to default value if absent
assert.equal(contentSteering.ttl, 300, 'ttl is 300 by default');
});

QUnit.test('Can handle HLS content steering manifest with RELOAD-URI', function(assert) {
const hlsServerUriOnly = {
serverUri: 'https://content.steering.test'
};
const contentSteering = new ContentSteering(this.fakeVhs.xhr, this.manifestUri, hlsServerUriOnly);

this.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{ "VERSION": 1, "RELOAD-URI": "https://foo.bar" }');
assert.equal(contentSteering.reloadUri, 'https://foo.bar', 'reloadUri is expected value');
});

QUnit.test('Can handle HLS content steering manifest with TTL', function(assert) {
const hlsServerUriOnly = {
serverUri: 'https://content.steering.test'
};
const contentSteering = new ContentSteering(this.fakeVhs.xhr, this.manifestUri, hlsServerUriOnly);

this.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{ "VERSION": 1, "TTL": 1 }');
assert.equal(contentSteering.ttl, 1, 'ttl is expected value');
});

QUnit.test('Can handle HLS content steering manifest with PATHWAY-PRIORITY', function(assert) {
const hlsServerUriOnly = {
serverUri: 'https://content.steering.test',
pathwayId: 'test'
};
const contentSteering = new ContentSteering(this.fakeVhs.xhr, this.manifestUri, hlsServerUriOnly);

this.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{ "VERSION": 1, "PATHWAY-PRIORITY": ["test1", "test2"] }');
assert.deepEqual(contentSteering.cdnPriority, ['test1', 'test2'], 'cdn priority is expected value');
});

0 comments on commit 88c4fc4

Please sign in to comment.