Skip to content

Commit

Permalink
[FE-10764] Make test host and credentials configurable (#178)
Browse files Browse the repository at this point in the history
* ⚙️ Make host configurable over cl, update tests

* ⚙️ Make credentials configurable
  • Loading branch information
israelvicars committed Apr 7, 2020
1 parent ba370f0 commit 1d0b4da
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 83 deletions.
21 changes: 14 additions & 7 deletions examples/browser.js
@@ -1,5 +1,12 @@
/* eslint-disable */

const hostname = process.env.HOSTNAME || "metis.mapd.com"
const protocol = process.env.PROTOCOL || "https"
const port = process.env.PORT || "443"
const database = process.env.DATABASE || "mapd"
const username = process.env.USERNAME || "mapd"
const password = process.env.PASSWORD || "HyperInteractive"

// The total number of tweets from Columbia
const query = "SELECT count(*) AS n FROM tweets_nov_feb WHERE country='CO'"
// try changing airtime to arrdelay in the query
Expand All @@ -9,12 +16,12 @@ const defaultQueryOptions = {}
const connector = new window.MapdCon()

connector
.protocol("https")
.host("metis.mapd.com")
.port("443")
.dbName("mapd")
.user("mapd")
.password("HyperInteractive")
.protocol(protocol)
.host(hostname)
.port(port)
.dbName(database)
.user(username)
.password(password)
.connectAsync()
.then(session =>
// now that we have a session open we can make some db calls:
Expand All @@ -29,7 +36,7 @@ connector
.then(values => {
// handle result of getTablesAsync
console.log(
"All tables available at metis.mapd.com:",
`All dashboards available at ${hostname}:\n`,
values[0].map(x => x.name)
)

Expand Down
24 changes: 15 additions & 9 deletions examples/node.js
Expand Up @@ -2,6 +2,13 @@

const Connector = require("../dist/node-connector.js")

const hostname = process.env.HOSTNAME || "metis.mapd.com"
const protocol = process.env.PROTOCOL || "https"
const port = process.env.PORT || "443"
const database = process.env.DATABASE || "mapd"
const username = process.env.USERNAME || "mapd"
const password = process.env.PASSWORD || "HyperInteractive"

// The total number of tweets from Columbia
const query = "SELECT count(*) AS n FROM tweets_nov_feb WHERE country='CO'"
const query2 =
Expand All @@ -10,14 +17,13 @@ const defaultQueryOptions = {}

const connector = new Connector()


connector
.protocol("https")
.host("metis.mapd.com")
.port("443")
.dbName("mapd")
.user("mapd")
.password("HyperInteractive")
.protocol(protocol)
.host(hostname)
.port(port)
.dbName(database)
.user(username)
.password(password)
.connectAsync()
.then(session =>
// now that we have a session open we can make some db calls:
Expand All @@ -33,13 +39,13 @@ connector
.then(values => {
// handle result of getDashboardsAsync
console.log(
"All dashboards available at metis.mapd.com:\n",
`All dashboards available at ${hostname}:\n`,
values[0].map(dash => dash.dashboard_name)
)

// handle result of getTablesAsync
console.log(
"\nAll tables available at metis.mapd.com:\n\n",
`\nAll tables available at ${hostname}:\n\n`,
values[1].map(x => x.name)
)

Expand Down
15 changes: 10 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 15 additions & 62 deletions test/integration.spec.js
@@ -1,4 +1,11 @@
"use strict"
const hostname = process.env.HOSTNAME || "metis.mapd.com"
const protocol = process.env.PROTOCOL || "https"
const port = process.env.PORT || "443"
const database = process.env.DATABASE || "mapd"
const username = process.env.USERNAME || "mapd"
const password = process.env.PASSWORD || "HyperInteractive"

const isNodeRuntime = typeof window === "undefined"
const expect = isNodeRuntime ? require("chai").expect : window.expect
const convertToDataUrl = isNodeRuntime
Expand All @@ -18,12 +25,12 @@ describe(isNodeRuntime ? "node" : "browser", () => {
let connector
beforeEach(() => {
connector = new Connector()
.protocol("https")
.host("metis.mapd.com")
.port("443")
.dbName("mapd")
.user("mapd")
.password("HyperInteractive")
.protocol(protocol)
.host(hostname)
.port(port)
.dbName(database)
.user(username)
.password(password)
})

const widgetId = 0
Expand Down Expand Up @@ -92,12 +99,7 @@ describe(isNodeRuntime ? "node" : "browser", () => {
session
.getTablesAsync()
.then(data => {
expect(data).to.deep.equal([
{ name: "flights_donotmodify", label: "obs" },
{ name: "contributions_donotmodify", label: "obs" },
{ name: "tweets_nov_feb", label: "obs" },
{ name: "zipcodes", label: "obs" }
])
expect(data).to.not.be.empty
done()
})
.catch(getTablesAsyncError => {
Expand All @@ -107,9 +109,6 @@ describe(isNodeRuntime ? "node" : "browser", () => {
})
})

// Note that this test assumes the list of dashboards (and their metadata) on Metis aren't
// changed. If they do change, this test will fail. The only exception is each dash's
// `update_time`, which we filter out since that is too volatile to rely on.
it(".getDashboardsAsync", done => {
connector.connect((connectError, session) => {
expect(connectError).to.not.be.an("error")
Expand All @@ -121,53 +120,7 @@ describe(isNodeRuntime ? "node" : "browser", () => {
const dataNoUpdateTime = data.map(d =>
Object.assign({}, d, { update_time: null })
)
expect(dataNoUpdateTime).to.deep.equal([
{
dashboard_name: "__E2E_LINE_CHART_BRUSH__DO_NOT_MODIFY__",
dashboard_state: "",
image_hash: "",
update_time: null,
dashboard_metadata:
'{"table":"flights_donotmodify","version":"v2"}',
dashboard_id: 452,
dashboard_owner: "mapd",
is_dash_shared: false
},
{
dashboard_name:
"__E2E_MULTI_BIN_DIM_HEATMAP_FILTER__DO_NOT_MODIFY__",
dashboard_state: "",
image_hash: "",
update_time: null,
dashboard_metadata:
'{"table":"flights_donotmodify","version":"v2"}',
dashboard_id: 451,
dashboard_owner: "mapd",
is_dash_shared: false
},
{
dashboard_name: "__E2E_NUMBER_CHART__DO_NOT_MODIFY__",
dashboard_state: "",
image_hash: "",
update_time: null,
dashboard_metadata:
'{"table":"flights_donotmodify","version":"v2"}',
dashboard_id: 450,
dashboard_owner: "mapd",
is_dash_shared: false
},
{
dashboard_name: "__E2E__ALL_CHARTS__DO_NOT_MODIFY__",
dashboard_state: "",
image_hash: "",
update_time: null,
dashboard_metadata:
'{"table":"contributions_donotmodify","version":"v2"}',
dashboard_id: 449,
dashboard_owner: "mapd",
is_dash_shared: false
}
])
expect(dataNoUpdateTime).to.not.be.empty
done()
})
// eslint-disable-next-line max-nested-callbacks
Expand Down

0 comments on commit 1d0b4da

Please sign in to comment.