Skip to content

Commit 23020ad

Browse files
committed
knock this whole f'in thing
1 parent 0351cbc commit 23020ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+7918
-156
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ See the [Mux-Node docs](https://muxinc.github.io/mux-node-sdk/identifiers.html)
209209
210210
## Development
211211
212-
Run unit tests: `npm test` or `npm run test:unit`
212+
Run unit tests: `yarn test` or `yarn test:unit`
213213
214-
Run integration tests: `npm run test:int`
214+
Run integration tests: `yarn test:int` - this will run integration tests with `nock` and `NOCK_BACK_MODE` set to `record`. This means that previously recorded API requests will be stubbed and any missing ones will be recorded.
215215
216-
**Note**: running the integration tests will require you to configure the `MUX_TOKEN_ID` and `MUX_TOKEN_SECRET` environment variables with your Mux access token and secret. You should use the credentials for [email protected], where we generate views for this purpose ("watch-this" project).
216+
You can also run integration tests with real requests by running `yarn test:int:wild`. Make sure you have `MUX_TOKEN_ID` and `MUX_TOKEN_SECRET` set as environment variables so your requests are authenticated. This is useful to run locally to verify that actual API requests work as expected. When running the whole suite locally you might run into Mux API rate limits so keep that in mind.
217217
218-
Integration tests do not get run on CI because of Mux API rate limits, so run them locally.
218+
**Pro Tip** Use mocha `-g` option to run only a specific test or group of tests. For example: `yarn test -g 'creates a new Assets'`.
219219
220220
To generate the ESDocs, run:
221221

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"docs": "esdoc",
2222
"test": "yarn test:unit",
2323
"test:unit": "mocha --recursive ./test/unit",
24-
"test:int": "NOCK_BACK_MODE=wild mocha --recursive ./test/integration",
25-
"test:int:record": "mocha --recursive ./test/integration --timeout 10000",
24+
"test:int": "NOCK_BACK_MODE=record mocha --recursive ./test/integration --timeout 10000",
25+
"test:int:wild": "NOCK_BACK_MODE=wild mocha --recursive ./test/integration --timeout 10000",
2626
"format": "eslint src/** test/** types/** --no-error-on-unmatched-pattern",
2727
"lint": "yarn format"
2828
},

test/integration/data/errors.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { expect } = require('chai');
22
const Mux = require('../../../src/mux');
3+
const nockBack = require('nock').back;
34

45
/** @test {Errors} */
56
describe('Integration::Errors', () => {
@@ -10,11 +11,13 @@ describe('Integration::Errors', () => {
1011
describe('Errors.list', () => {
1112
/** @test {Errors.list} */
1213
it('Returns a list of playback errors', async () => {
14+
const { nockDone } = await nockBack('Errors/list.json');
1315
const resp = await Data.Errors.list({
1416
filters: ['operating_system:linux'],
1517
});
1618
expect(resp.data).to.be.an('array');
1719
expect(resp.timeframe).to.be.an('array');
20+
nockDone();
1821
});
1922
});
2023
});

test/integration/data/exports.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { expect } = require('chai');
22
const Mux = require('../../../src/mux');
3+
const nockBack = require('nock').back;
34

45
/** @test {Exports} */
56
describe('Integration::Exports', () => {
@@ -10,10 +11,12 @@ describe('Integration::Exports', () => {
1011
describe('Exports.list', () => {
1112
/** @test {Exports.list} */
1213
it('Lists the available video view exports along with URLs to retrieve them', async () => {
14+
const { nockDone } = await nockBack('Exports/list.json');
1315
const resp = await Data.Exports.list();
1416
expect(resp.data).to.be.an('array');
1517
expect(resp.total_row_count).to.be.greaterThan(6); // we should have 7 or 8
1618
expect(resp.timeframe).to.be.an('array');
19+
nockDone();
1720
});
1821
});
1922
});

test/integration/data/filters.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { expect } = require('chai');
22
const Mux = require('../../../src/mux');
3+
const nockBack = require('nock').back;
34

45
/** @test {Filters} */
56
describe('Integration::Filters', () => {
@@ -10,20 +11,24 @@ describe('Integration::Filters', () => {
1011
describe('Filters.list', () => {
1112
/** @test {Filters.list} */
1213
it('Lists all the filters broken out into basic and advanced', async () => {
14+
const { nockDone } = await nockBack('Filters/list.json');
1315
const resp = await Data.Filters.list();
1416
expect(resp.timeframe).to.be.an('array');
1517
expect(resp.data.basic).to.be.an('array');
1618
expect(resp.data.advanced).to.be.an('array');
19+
nockDone();
1720
});
1821
});
1922

2023
/** @test {Filters.get} */
2124
describe('Filters.get', () => {
2225
/** @test {Filters.get} */
2326
it('Lists the values for a filter along with a total count of related views', async () => {
27+
const { nockDone } = await nockBack('Filters/get.json');
2428
const resp = await Data.Filters.get('browser');
2529
expect(resp.data).to.be.an('array');
2630
expect(resp.timeframe).to.be.an('array');
31+
nockDone();
2732
});
2833
});
2934
});

test/integration/data/incidents.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { expect } = require('chai');
22
const Mux = require('../../../src/mux');
3+
const nockBack = require('nock').back;
34

45
/** @test {Incidents} */
56
describe('Integration::Incidents', () => {
@@ -10,11 +11,13 @@ describe('Integration::Incidents', () => {
1011
describe('Incidents.list', () => {
1112
/** @test {Incidents.list} */
1213
it('Returns a list of open incidents', async () => {
14+
const { nockDone } = await nockBack('Incidents/list.json');
1315
const resp = await Data.Incidents.list({
1416
status: 'open',
1517
});
1618
expect(resp.data).to.be.an('array');
1719
expect(resp.timeframe).to.be.an('array');
20+
nockDone();
1821
});
1922
});
2023
});

test/integration/data/metrics.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { expect } = require('chai');
22
const Mux = require('../../../src/mux');
3+
const nockBack = require('nock').back;
34

45
/** @test {Metrics} */
56
describe('Integration::Metrics', () => {
@@ -10,54 +11,64 @@ describe('Integration::Metrics', () => {
1011
describe('Metrics.breakdown', () => {
1112
/** @test {Metrics.breakdown} */
1213
it('Lists all of the values across every breakdown for a specific metric', async () => {
14+
const { nockDone } = await nockBack('Metrics/breakdown.json');
1315
const resp = await Data.Metrics.breakdown('aggregate_startup_time', {
1416
group_by: 'browser',
1517
});
1618
expect(resp.data).to.be.an('array');
1719
expect(resp.timeframe).to.be.an('array');
20+
nockDone();
1821
});
1922
});
2023

2124
/** @test {Metrics.comparision} */
2225
describe('Metrics.comparision', () => {
2326
/** @test {Metrics.comparision} */
2427
it('Lists the breakdown values for a specific metric', async () => {
28+
const { nockDone } = await nockBack('Metrics/comparison.json');
2529
const resp = await Data.Metrics.comparison({
2630
value: 'Safari',
2731
dimension: 'browser',
2832
});
2933
expect(resp.data).to.be.an('array');
3034
expect(resp.timeframe).to.be.an('array');
35+
nockDone();
3136
});
3237
});
3338

3439
/** @test {Metrics.insights} */
3540
describe('Metrics.insights', () => {
3641
/** @test {Metrics.insights} */
3742
it('Returns a list of insights for a metric', async () => {
43+
const { nockDone } = await nockBack('Metrics/insights.json');
3844
const resp = await Data.Metrics.insights('video_startup_time');
3945
expect(resp.data).to.be.an('array');
4046
expect(resp.timeframe).to.be.an('array');
47+
nockDone();
4148
});
4249
});
4350

4451
/** @test {Metrics.overall} */
4552
describe('Metrics.overall', () => {
4653
/** @test {Metrics.overall} */
4754
it('Returns the overall value for a specific metric, as well as the total view count, watch time, and the Mux Global metric value for the metric', async () => {
55+
const { nockDone } = await nockBack('Metrics/overall.json');
4856
const resp = await Data.Metrics.overall('video_startup_time');
4957
expect(resp.data).to.be.an('object');
5058
expect(resp.timeframe).to.be.an('array');
59+
nockDone();
5160
});
5261
});
5362

5463
/** @test {Metrics.timeseries} */
5564
describe('Metrics.timeseries', () => {
5665
/** @test {Metrics.timeseries} */
5766
it('Returns the overall value for a specific metric, as well as the total view count, watch time, and the Mux Global metric value for the metric', async () => {
67+
const { nockDone } = await nockBack('Metrics/timeseries.json');
5868
const resp = await Data.Metrics.timeseries('video_startup_time');
5969
expect(resp.data).to.be.an('array');
6070
expect(resp.timeframe).to.be.an('array');
71+
nockDone();
6172
});
6273
});
6374
});

test/integration/data/real_time.spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { expect } = require('chai');
22
const Mux = require('../../../src/mux');
3+
const nockBack = require('nock').back;
34

45
/** @test {RealTime} */
56
describe('Integration::RealTime', () => {
@@ -10,59 +11,70 @@ describe('Integration::RealTime', () => {
1011
describe('RealTime.dimensions', () => {
1112
/** @test {RealTime.dimensions} */
1213
it('List of available real-time dimensions', async () => {
14+
const { nockDone } = await nockBack('RealTime/dimensions.json');
1315
const resp = await Data.RealTime.dimensions();
1416
expect(resp.data).to.be.an('array');
1517
expect(resp.data[0]).to.be.an('object');
18+
nockDone();
1619
});
1720
});
1821

1922
/** @test {RealTime.metrics} */
2023
describe('RealTime.metrics', () => {
2124
/** @test {RealTime.metrics} */
2225
it('List available real-time metrics', async () => {
26+
const { nockDone } = await nockBack('RealTime/metrics.json');
2327
const resp = await Data.RealTime.metrics();
2428
expect(resp.data).to.be.an('array');
2529
expect(resp.data[0]).to.be.an('object');
30+
nockDone();
2631
});
2732
});
2833

2934
/** @test {RealTime.breakdown} */
3035
describe('RealTime.breakdown', () => {
3136
/** @test {RealTime.breakdown} */
3237
it('Get breakdown information for a specific dimension and metric', async () => {
38+
const { nockDone } = await nockBack('RealTime/breakdown.json');
39+
const timestamp = 1592357452; // freeze this time for nock
3340
const resp = await Data.RealTime.breakdown(
3441
'playback-failure-percentage',
3542
{
3643
dimension: 'asn',
37-
timestamp: Math.floor(new Date().getTime() / 1000),
44+
timestamp,
3845
filters: ['operating_system:windows', 'country:US'],
3946
}
4047
);
4148
expect(resp.data).to.be.an('array');
49+
nockDone();
4250
});
4351
});
4452

4553
/** @test {RealTime.histogramTimeseries} */
4654
describe('RealTime.histogramTimeseries', () => {
4755
/** @test {RealTime.histogramTimeseries} */
4856
it('List histogram timeseries information for a specific metric', async () => {
57+
const { nockDone } = await nockBack('RealTime/histogramTimeseries.json');
4958
const resp = await Data.RealTime.histogramTimeseries(
5059
'video-startup-time',
5160
{ filters: ['operating_system:windows', 'country:US'] }
5261
);
5362
expect(resp.data).to.be.an('array');
63+
nockDone();
5464
});
5565
});
5666

5767
/** @test {RealTime.timeseries} */
5868
describe('RealTime.timeseries', () => {
5969
/** @test {RealTime.timeseries} */
6070
it('List timeseries information for the playback-failure-percentage metric along with the number of concurrent viewers for the Windows operating system in the US', async () => {
71+
const { nockDone } = await nockBack('RealTime/timeseries.json');
6172
const resp = await Data.RealTime.timeseries(
6273
'playback-failure-percentage',
6374
{ filters: ['operating_system:windows', 'country:US'] }
6475
);
6576
expect(resp.data).to.be.an('array');
77+
nockDone();
6678
});
6779
});
6880
});

test/integration/data/video_views.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { expect } = require('chai');
22
const Mux = require('../../../src/mux');
3+
const nockBack = require('nock').back;
34

45
/** @test {VideoViews} */
56
describe('Integration::VideoViews', () => {
@@ -10,21 +11,25 @@ describe('Integration::VideoViews', () => {
1011
describe('VideoViews.list', () => {
1112
/** @test {VideoViews.list} */
1213
it('Returns a list of video views for a property that occurred within the specified timeframe', async () => {
14+
const { nockDone } = await nockBack('VideoViews/list.json');
1315
const resp = await Data.VideoViews.list({
1416
viewer_id: 'test',
1517
order_direction: 'asc',
1618
});
1719
expect(resp.data).to.be.an('array');
20+
nockDone();
1821
});
1922
});
2023

2124
/** @test {VideoViews.get} */
2225
describe('VideoViews.get', () => {
2326
/** @test {VideoViews.get} */
2427
it('Returns the details for a single video view', async () => {
28+
const { nockDone } = await nockBack('VideoViews/listAndGet.json');
2529
const resp = await Data.VideoViews.list();
2630
const view = await Data.VideoViews.get(resp.data[0].id);
2731
expect(view).to.be.an('object');
32+
nockDone();
2833
});
2934
});
3035
});

test/integration/helper.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const path = require('path');
22
const nockBack = require('nock').back;
33

44
before(() => {
5-
console.log('debug', nockBack.currentMode);
65
// If we decide to use nock with other modules we should move this to a test helper
76
nockBack.fixtures = path.join(__dirname, '/nockFixtures');
87
});

0 commit comments

Comments
 (0)