Reference Source Test

test/unit/data/resources/metrics.spec.js

  1. const { expect } = require('chai');
  2. const moxios = require('moxios');
  3. const Metrics = require('../../../../src/data/resources/metrics');
  4.  
  5. /** @test {Metrics} */
  6. describe('Unit::Metrics', () => {
  7. const testApiKey = 'testKey';
  8. const testSecret = 'testSecret';
  9. const metricsInstance = new Metrics(testApiKey, testSecret);
  10.  
  11. beforeEach(() => {
  12. moxios.install(metricsInstance.http);
  13. });
  14.  
  15. afterEach(() => {
  16. moxios.uninstall(metricsInstance.http);
  17. });
  18.  
  19. /** @test {Metrics} */
  20. describe('Metrics', () => {
  21. /** @test {Metrics} */
  22. it('throws an error if an api key is not given', () => {
  23. expect(() => new Metrics()).to.throw(
  24. 'API Access Token must be provided.'
  25. );
  26. });
  27.  
  28. /** @test {Metrics} */
  29. it('throws an error if a secret key is not given', () => {
  30. expect(() => new Metrics(testApiKey)).to.throw(
  31. 'API secret key must be provided'
  32. );
  33. });
  34.  
  35. /** @test {Metrics} */
  36. it('creates a new Metrics instance', () => {
  37. const TestMetrics = new Metrics(testApiKey, testSecret);
  38. expect(() => new Metrics(testApiKey, testSecret)).to.not.throw();
  39. expect(TestMetrics.tokenId).to.equal(testApiKey);
  40. expect(TestMetrics.tokenSecret).to.equal(testSecret);
  41. });
  42. });
  43.  
  44. /** @test {Metrics.comparison} */
  45. describe('Metrics.comparison', () => {
  46. /** @test {Metrics.comparison} */
  47. it('throws an error if the value query parameter is not provided', () => {
  48. expect(() => metricsInstance.comparison()).to.throw(
  49. 'The value query parameter is required for comparing metrics'
  50. );
  51. expect(() => metricsInstance.comparison({})).to.throw(
  52. 'The value query parameter is required for comparing metrics'
  53. );
  54. });
  55. });
  56.  
  57. /** @test {Metrics.insights} */
  58. describe('Metrics.insights', () => {
  59. /** @test {Metrics.insights} */
  60. it('throws an error if a metric Id is not provided', () => {
  61. expect(() => metricsInstance.insights()).to.throw(
  62. 'A metric Id is required for insight metrics.'
  63. );
  64. });
  65. });
  66.  
  67. /** @test {Metrics.overall} */
  68. describe('Metrics.overall', () => {
  69. /** @test {Metrics.overall} */
  70. it('throws an error if a metric Id is not provided', () => {
  71. expect(() => metricsInstance.overall()).to.throw(
  72. 'A metric Id is required for overall metrics.'
  73. );
  74. });
  75. });
  76.  
  77. /** @test {Metrics.timeseries} */
  78. describe('Metrics.timeseries', () => {
  79. /** @test {Metrics.timeseries} */
  80. it('throws an error if a metric Id is not provided', () => {
  81. expect(() => metricsInstance.timeseries()).to.throw(
  82. 'A metric Id is required for timeseries metrics.'
  83. );
  84. });
  85. });
  86. });