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

extend testing for updating scenarios in locked state

parent 0a62c781
Pipeline #434841 passed with stages
in 56 minutes and 1 second
......@@ -268,6 +268,48 @@ func TestUpdateScenario(t *testing.T) {
err = helper.CompareResponse(resp, helper.KeyModels{"scenario": updatedScenario})
assert.NoError(t, err)
// Get the updatedScenario
code, resp, err = helper.TestEndpoint(router, token,
fmt.Sprintf("/api/v2/scenarios/%v", newScenarioID), "GET", nil)
assert.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// Compare GET's response with the newScenario
err = helper.CompareResponse(resp, helper.KeyModels{"scenario": updatedScenario})
assert.NoError(t, err)
// change a locked scenario as admin user (should work)
updatedScenario.Name = "Updated as admin"
code, resp, err = helper.TestEndpoint(router, token,
fmt.Sprintf("/api/v2/scenarios/%v", newScenarioID), "PUT", helper.KeyModels{"scenario": updatedScenario})
assert.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// Compare GET's response with the updatedScenario
err = helper.CompareResponse(resp, helper.KeyModels{"scenario": updatedScenario})
assert.NoError(t, err)
// authenticate as normal user
token, err = helper.AuthenticateForTest(router, helper.UserACredentials)
assert.NoError(t, err)
// Get the updatedScenario
code, resp, err = helper.TestEndpoint(router, token,
fmt.Sprintf("/api/v2/scenarios/%v", newScenarioID), "GET", nil)
assert.NoError(t, err)
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
// Compare GET's response with the updatedScenario
err = helper.CompareResponse(resp, helper.KeyModels{"scenario": updatedScenario})
assert.NoError(t, err)
// try to change a locked scenario as normal user (should result in unprocessable entity error)
updatedScenario.Name = "another new name"
code, resp, err = helper.TestEndpoint(router, token,
fmt.Sprintf("/api/v2/scenarios/%v", newScenarioID), "PUT", helper.KeyModels{"scenario": updatedScenario})
assert.NoError(t, err)
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
}
func TestGetAllScenariosAsAdmin(t *testing.T) {
......
Markdown is supported
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