-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MetricsAdapter): add submitMetrics method
- Loading branch information
1 parent
eec4234
commit 6e0b215
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {throwError} from 'rxjs'; | ||
|
||
import WebexAdapter from './WebexAdapter'; | ||
|
||
/** | ||
* A metric sent to webex. | ||
* | ||
* @typedef {object} Metric | ||
* @property {MetricType} type The type of metric to be captured | ||
* @property {string} name The metric name | ||
* @property {object} fields The data to be sent in metric | ||
* @property {object} tags Tags for categorization | ||
* @property {object} eventPayload Business metric payload | ||
*/ | ||
|
||
/** | ||
* All potential types of a metric. | ||
* | ||
* @readonly | ||
* @enum {string} | ||
*/ | ||
export const MetricType = { | ||
BEHAVIORAL: 'behavioral', | ||
BUSINESS: 'business', | ||
OPERATIONAL: 'operational', | ||
}; | ||
|
||
/** | ||
* This is a base class that defines the interface for sending metrics. | ||
* Developers that want to extend `MetricsAdapter` must implement all of its methods, | ||
* adhering to the exact parameters and structure of the returned objects. | ||
* | ||
* @interface | ||
*/ | ||
export default class MetricsAdapter extends WebexAdapter { | ||
/** | ||
* submit metrics to metric service. | ||
* | ||
* @param {Metric} metric metric object containing type, fields, tags | ||
* @param {string} [preLoginID] ID of person during onboarding | ||
* @returns {external:Observable.<Metric>} Observable stream that emits metric data | ||
* @memberof MetricsAdapter | ||
*/ | ||
submitMetrics(metric, preLoginID) { | ||
return throwError( | ||
new Error('submitMetrics(metric, preLoginID) must be defined in MetricsAdapter'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import MetricsAdapter from './MetricsAdapter'; | ||
|
||
describe('Metrics Adapter Interface', () => { | ||
let metricsAdapter; | ||
|
||
beforeEach(() => { | ||
metricsAdapter = new MetricsAdapter(); | ||
}); | ||
|
||
afterEach(() => { | ||
metricsAdapter = null; | ||
}); | ||
|
||
describe('submitMetrics()', () => { | ||
const eventName = 'test_event'; | ||
const mockMetric = { | ||
fields: { | ||
testField: 123, | ||
}, | ||
tags: { | ||
testTag: 'tag value', | ||
}, | ||
metricName: eventName, | ||
type: 'behavioral', | ||
eventPayload: {value: 'splunk business metric payload'}, | ||
}; | ||
|
||
test('errors because it needs to be defined', (done) => { | ||
const message = 'submitMetrics(metric, preLoginID) must be defined in MetricsAdapter'; | ||
|
||
metricsAdapter.submitMetrics(eventName, mockMetric).subscribe( | ||
() => {}, | ||
(error) => { | ||
expect(error.message).toBe(message); | ||
done(); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |