Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstreamsvcs #3832

Merged
merged 6 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/@webex/internal-plugin-device/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export default {
* @type {boolean}
*/
ephemeralDeviceTTL: 30 * 60,

/**
* energyForcast
* @type {boolean}
*/
energyForecast: false,
},

/**
Expand Down
27 changes: 27 additions & 0 deletions packages/@webex/internal-plugin-device/src/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ const Device = WebexPlugin.extend({
*/
isReachabilityChecked: ['boolean', false, false],

/**
* This property stores whether or not the next refresh or register request should request energy forecast data
* in order to prevent over fetching energy forecasts
*
* @type {boolean}
*/
energyForecastConfig: 'boolean',

/**
* This property stores whether or not the current device is in a meeting
* to prevent an unneeded timeout of a meeting due to inactivity.
Expand Down Expand Up @@ -344,6 +352,15 @@ const Device = WebexPlugin.extend({
this.webex.trigger('meeting ended');
},

/**
* Set the value of energy forecast config for the current registered device.
* @param {boolean} [energyForecastConfig=false] - fetch an energy forecast on the next refresh/register
* @returns {void}
*/
setEnergyForecastConfig(energyForecastConfig = false) {
this.energyForecastConfig = energyForecastConfig;
},

// Registration method members

/* eslint-disable require-jsdoc */
Expand Down Expand Up @@ -395,6 +412,11 @@ const Device = WebexPlugin.extend({
uri: this.url,
body,
headers,
qs: {
includeUpstreamServices: `all${
this.config.energyForecast && this.energyForecastConfig ? ',energyforecast' : ''
}`,
},
})
.then((response) => this.processRegistrationSuccess(response))
.catch((reason) => {
Expand Down Expand Up @@ -464,6 +486,11 @@ const Device = WebexPlugin.extend({
resource: 'devices',
body,
headers,
qs: {
includeUpstreamServices: `all${
this.config.energyForecast && this.energyForecastConfig ? ',energyforecast' : ''
}`,
},
})
.catch((error) => {
this.webex.internal.newMetrics.submitInternalEvent({
Expand Down
68 changes: 66 additions & 2 deletions packages/@webex/internal-plugin-device/test/unit/spec/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,14 @@ describe('plugin-device', () => {
describe('#refresh()', () => {
let requestSpy;

const setup = () => {
const setup = (config = {}) => {
sinon.stub(device, 'canRegister').callsFake(() => Promise.resolve());
sinon.stub(device, 'processRegistrationSuccess').callsFake(() => {});
requestSpy = sinon.spy(device, 'request');
device.config.defaults = {};
Object.keys((config)).forEach((key) => {
device.config[key] = config[key];
});
device.set('registered', true);
};

Expand All @@ -207,15 +210,40 @@ describe('plugin-device', () => {

assert.deepEqual(requestSpy.args[0][0].headers, {});
});

it('uses the energy forecast config to append upstream services to the outgoing call', async () => {
setup({energyForecast: true});
device.setEnergyForecastConfig(true);

await device.register();

assert.calledWith(requestSpy, sinon.match({
qs: { includeUpstreamServices: 'all,energyforecast' }
}))
});

it('uses the energy forecast config to not append upstream services to the outgoing call', async () => {
setup({energyForecast: true});
device.setEnergyForecastConfig(false);

await device.register();

assert.calledWith(requestSpy, sinon.match({
qs: { includeUpstreamServices: 'all' }
}))
});
});

describe('#register()', () => {
const setup = () => {
const setup = (config = {}) => {
webex.internal.metrics.submitClientMetrics = sinon.stub();

sinon.stub(device, 'processRegistrationSuccess').callsFake(() => {});

device.config.defaults = {};
Object.keys(config).forEach((key) => {
device.config[key] = config[key];
});
device.set('registered', false);
};

Expand Down Expand Up @@ -284,6 +312,42 @@ describe('plugin-device', () => {

});

it('uses the energy forecast config to append upstream services to the outgoing call', async () => {
setup({energyForecast: true});
sinon.stub(device, 'canRegister').callsFake(() => Promise.resolve());
const spy = sinon.spy(device, 'request');
device.setEnergyForecastConfig(true);

await device.register();

assert.calledWith(spy, {
method: 'POST',
service: 'wdm',
resource: 'devices',
body: {},
headers: {},
qs: { includeUpstreamServices: 'all,energyforecast' }
} )
});

it('uses the energy forecast config to not append upstream services to the outgoing call', async () => {
setup({energyForecast: true});
sinon.stub(device, 'canRegister').callsFake(() => Promise.resolve());
const spy = sinon.spy(device, 'request');
device.setEnergyForecastConfig(false);

await device.register();

assert.calledWith(spy, {
method: 'POST',
service: 'wdm',
resource: 'devices',
body: {},
headers: {},
qs: { includeUpstreamServices: 'all' }
} )
});

});

describe('#processRegistrationSuccess()', () => {
Expand Down
Loading