From 70341df9b84bfeb1d9cfbefcb171a760da3d86ed Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Mon, 11 May 2020 11:40:14 +0530 Subject: [PATCH] Bug: Use v2 reports instead of v1 reports (#843) --- app/javascript/dashboard/api/ApiClient.js | 4 ++-- app/javascript/dashboard/api/reports.js | 2 +- .../dashboard/api/specs/reports.spec.js | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 app/javascript/dashboard/api/specs/reports.spec.js diff --git a/app/javascript/dashboard/api/ApiClient.js b/app/javascript/dashboard/api/ApiClient.js index 0b2ed28d0..9199109a1 100644 --- a/app/javascript/dashboard/api/ApiClient.js +++ b/app/javascript/dashboard/api/ApiClient.js @@ -1,10 +1,10 @@ /* global axios */ -const API_VERSION = `/api/v1`; +const DEFAULT_API_VERSION = 'v1'; class ApiClient { constructor(resource, options = {}) { - this.apiVersion = API_VERSION; + this.apiVersion = `/api/${options.apiVersion || DEFAULT_API_VERSION}`; this.options = options; this.resource = resource; } diff --git a/app/javascript/dashboard/api/reports.js b/app/javascript/dashboard/api/reports.js index d2a96cda8..8dedcc5d2 100644 --- a/app/javascript/dashboard/api/reports.js +++ b/app/javascript/dashboard/api/reports.js @@ -3,7 +3,7 @@ import ApiClient from './ApiClient'; class ReportsAPI extends ApiClient { constructor() { - super('reports', { accountScoped: true }); + super('reports', { accountScoped: true, apiVersion: 'v2' }); } getAccountReports(metric, since, until) { diff --git a/app/javascript/dashboard/api/specs/reports.spec.js b/app/javascript/dashboard/api/specs/reports.spec.js new file mode 100644 index 000000000..6d1c5db3e --- /dev/null +++ b/app/javascript/dashboard/api/specs/reports.spec.js @@ -0,0 +1,16 @@ +import reports from '../reports'; +import ApiClient from '../ApiClient'; + +describe('#Reports API', () => { + it('creates correct instance', () => { + expect(reports).toBeInstanceOf(ApiClient); + expect(reports.apiVersion).toBe('/api/v2'); + expect(reports).toHaveProperty('get'); + expect(reports).toHaveProperty('show'); + expect(reports).toHaveProperty('create'); + expect(reports).toHaveProperty('update'); + expect(reports).toHaveProperty('delete'); + expect(reports).toHaveProperty('getAccountReports'); + expect(reports).toHaveProperty('getAccountSummary'); + }); +});