Commit a750cefd authored by Sonja Happ's avatar Sonja Happ
Browse files

WIP: dashboard test independent of test data

parent 6e68940e
......@@ -158,10 +158,6 @@ var DashboardA = database.Dashboard{
Name: "Dashboard_A",
Grid: 15,
}
var DashboardB = database.Dashboard{
Name: "Dashboard_B",
Grid: 10,
}
// Widgets
var customPropertiesSlider = json.RawMessage(`{"default_value" : 0, "orientation" : 0, "rangeUseMinMax": false, "rangeMin" : 0, "rangeMax": 200, "rangeUseMinMax" : true, "showUnit": true, "continous_update": false, "value": "", "resizeLeftRightLock": false, "resizeTopBottomLock": true, "step": 0.1 }`)
......
......@@ -22,6 +22,7 @@
package dashboard
import (
"encoding/json"
"fmt"
"log"
"os"
......@@ -52,13 +53,18 @@ type ScenarioRequest struct {
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
}
var newDashboard = DashboardRequest{
Name: "Dashboard_A",
Grid: 15,
}
func addScenario(token string) (scenarioID uint) {
// POST $newScenario
newScenario := ScenarioRequest{
Name: helper.ScenarioA.Name,
Running: helper.ScenarioA.Running,
StartParameters: helper.ScenarioA.StartParameters,
Name: "Scenario1",
Running: true,
StartParameters: postgres.Jsonb{json.RawMessage(`{"parameter1" : "testValue1A", "parameter2" : "testValue2A", "parameter3" : 42}`)},
}
_, resp, err := helper.TestEndpoint(router, token,
"/api/scenarios", "POST", helper.KeyModels{"scenario": newScenario})
......@@ -112,12 +118,8 @@ func TestAddDashboard(t *testing.T) {
scenarioID := addScenario(token)
// test POST dashboards/ $newDashboard
newDashboard := DashboardRequest{
Name: helper.DashboardA.Name,
Grid: helper.DashboardA.Grid,
ScenarioID: scenarioID,
}
// test POST dashboards/ $newDashboad
newDashboard.ScenarioID = scenarioID
code, resp, err := helper.TestEndpoint(router, token,
"/api/dashboards", "POST", helper.KeyModels{"dashboard": newDashboard})
assert.NoError(t, err)
......@@ -199,11 +201,7 @@ func TestUpdateDashboard(t *testing.T) {
scenarioID := addScenario(token)
// test POST dashboards/ $newDashboard
newDashboard := DashboardRequest{
Name: helper.DashboardA.Name,
Grid: helper.DashboardA.Grid,
ScenarioID: scenarioID,
}
newDashboard.ScenarioID = scenarioID
code, resp, err := helper.TestEndpoint(router, token,
"/api/dashboards", "POST", helper.KeyModels{"dashboard": newDashboard})
assert.NoError(t, err)
......@@ -214,8 +212,8 @@ func TestUpdateDashboard(t *testing.T) {
assert.NoError(t, err)
updatedDashboard := DashboardRequest{
Name: helper.DashboardB.Name,
Grid: helper.DashboardB.Grid,
Name: "Dashboard_B",
Grid: 10,
}
// authenticate as guest user
......@@ -280,11 +278,7 @@ func TestDeleteDashboard(t *testing.T) {
scenarioID := addScenario(token)
// test POST dashboards/ $newDashboard
newDashboard := DashboardRequest{
Name: helper.DashboardA.Name,
Grid: helper.DashboardA.Grid,
ScenarioID: scenarioID,
}
newDashboard.ScenarioID = scenarioID
code, resp, err := helper.TestEndpoint(router, token,
"/api/dashboards", "POST", helper.KeyModels{"dashboard": newDashboard})
assert.NoError(t, err)
......@@ -358,20 +352,16 @@ func TestGetAllDashboardsOfScenario(t *testing.T) {
assert.NoError(t, err)
// test POST dashboards/ $newDashboard
newDashboardA := DashboardRequest{
Name: helper.DashboardA.Name,
Grid: helper.DashboardA.Grid,
ScenarioID: scenarioID,
}
newDashboard.ScenarioID = scenarioID
code, resp, err := helper.TestEndpoint(router, token,
"/api/dashboards", "POST", helper.KeyModels{"dashboard": newDashboardA})
"/api/dashboards", "POST", helper.KeyModels{"dashboard": newDashboard})
assert.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// POST a second dashboard for the same scenario
newDashboardB := DashboardRequest{
Name: helper.DashboardB.Name,
Grid: helper.DashboardB.Grid,
Name: "Dashboard_B",
Grid: 10,
ScenarioID: scenarioID,
}
code, resp, err = helper.TestEndpoint(router, token,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment