CEC-2970: Multiple Superset Dashboards (#229)
Co-authored-by: Alexander Andrews <aandrews@fiskerinc.com>
This commit is contained in:
committed by
GitHub
parent
843fddd0b7
commit
2d298368c5
13
src/services/__mocks__/superset.js
Normal file
13
src/services/__mocks__/superset.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const SupersetAPI = {
|
||||
getEmbeddedDashboards: async () => {
|
||||
return [{
|
||||
title: "test title",
|
||||
embedded_id: "00000000-0000-0000-0000-000000000000"
|
||||
}]
|
||||
},
|
||||
SupersetDashboardID: () => {
|
||||
return "11111100-0000-1111-1111-000000000000"
|
||||
}
|
||||
}
|
||||
|
||||
export default SupersetAPI
|
||||
@@ -21,15 +21,32 @@ const supersetAPI = {
|
||||
let q = r["token"]
|
||||
return q
|
||||
},
|
||||
getEmbeddedDashboards: async(token) => {
|
||||
const u = addQueryParams(`${API_ENDPOINT}/dashboard/embedded-dashboards`);
|
||||
let res = await fetch(u, {
|
||||
method: "GET",
|
||||
headers: Object.assign(
|
||||
getAuthHeaderOptions(token)
|
||||
),
|
||||
})
|
||||
if(res.status !== 200){
|
||||
return [{title: "dashboard", embedded_id: GetSupersetDashboardID()}]
|
||||
}
|
||||
let r = await res.json()
|
||||
return r
|
||||
},
|
||||
SupersetDashboardURL: () => {
|
||||
const SUPERSET_BASE_URL = process.env.REACT_APP_SUPERSET_URL;
|
||||
return SUPERSET_BASE_URL
|
||||
},
|
||||
SupersetDashboardID: () => {
|
||||
const SUPERSET_BASE_ID = process.env.REACT_APP_SUPERSET_KEYS_LIST;
|
||||
return SUPERSET_BASE_ID
|
||||
return GetSupersetDashboardID()
|
||||
}
|
||||
}
|
||||
|
||||
const GetSupersetDashboardID = () => {
|
||||
const SUPERSET_BASE_ID = process.env.REACT_APP_SUPERSET_KEYS_LIST;
|
||||
return SUPERSET_BASE_ID
|
||||
}
|
||||
|
||||
export default supersetAPI;
|
||||
15
src/services/superset.test.js
Normal file
15
src/services/superset.test.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import superset from "./superset"
|
||||
|
||||
describe("Superset tests", () => {
|
||||
it("Outdated API doesn't cause problems", async () => {
|
||||
process.env.REACT_APP_SUPERSET_KEYS_LIST = "11111100-0000-1111-1111-000000000000"
|
||||
global.fetch = jest.fn(() => {
|
||||
return { status: 404 }
|
||||
}
|
||||
);
|
||||
|
||||
const res = await superset.getEmbeddedDashboards()
|
||||
expect(res).toHaveLength(1)
|
||||
expect(res[0].embedded_id).toBe("11111100-0000-1111-1111-000000000000")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user