Newer
Older
package rootmux
import (
"encoding/json"
"testing"
"forge.grandlyon.com/apoyen/elections/internal/auth"
"forge.grandlyon.com/apoyen/sdk-go/pkg/tester"
)
/**
Banker TESTS (those tests are to check the bankers rights)
**/
func AdminTests(t *testing.T) {
// Create the tester
ts, do, _ := createTester(t)
defer ts.Close() // Close the tester
tests := func() {
// Get the XSRF Token
response := do("GET", "/api/common/WhoAmI", noH, "", 200, "")
token := auth.TokenData{}
json.Unmarshal([]byte(response), &token)
xsrfHeader := tester.Header{Key: "XSRF-TOKEN", Value: token.XSRFToken}
// Create a capturer
do("POST", "/api/Capturer", xsrfHeader, `{"UserID":1,"Name":"Capturer"}`, 200, `{"ID":3,"UserID":1,"Name":"Capturer","DeskRounds":null}`)
// Get the capturer
do("GET", "/api/Capturer/1", xsrfHeader, ``, 200, `{"ID":1,"UserID":2,"Name":"Capturer","DeskRounds":[]}`)
// Get all the capturer
do("GET", "/api/Capturer/", xsrfHeader, ``, 200, `[{"ID":1,"UserID":2,"Name":"Capturer","DeskRounds":[]},{"ID":2,"UserID":3,"Name":"Capturer","DeskRounds":[]},{"ID":3,"UserID":1,"Name":"Capturer","DeskRounds":[]}]`)
// Update a capturer
do("PUT", "/api/Capturer/1", xsrfHeader, `{"ID":1,"UserID":2,"Name":"capturer"}`, 200, `{"ID":1,"UserID":2,"Name":"capturer","DeskRounds":[]}`)
// Delete a capturer
do("DELETE", "/api/Capturer/3", xsrfHeader, ``, 200, ``)
// Create an Election
do("POST", "/api/Election", xsrfHeader, `{"Name":"Grand Lyon 2020", "BallotType":"metropolitan-direct"}`, 200, `{"ID":1,"Name":"Grand Lyon 2020","BallotType":"metropolitan-direct","Areas":null,"Rounds":null}`)
// Get the election
do("GET", "/api/Election/1", xsrfHeader, ``, 200, `{"ID":1,"Name":"Grand Lyon 2020","BallotType":"metropolitan-direct","Areas":[],"Rounds":null}`)
// Get all the elections
do("GET", "/api/Election/", xsrfHeader, ``, 200, `[{"ID":1,"Name":"Grand Lyon 2020","BallotType":"metropolitan-direct","Areas":[],"Rounds":null}]`)
// Update a election
do("PUT", "/api/Election/1", xsrfHeader, `{"ID":1,"Name":"Grand-Lyon 2020", "BallotType":"metropolitan-direct"}`, 200, `{"ID":1,"Name":"Grand-Lyon 2020","BallotType":"metropolitan-direct","Areas":[],"Rounds":null}`)
// Delete a election
do("DELETE", "/api/Election/1", xsrfHeader, ``, 200, ``)
}
// Do a in memory login with an known admin
do("POST", "/Login", noH, `{"login": "admin","password": "password"}`, 200, "")
tests()
// Try to logout (must pass)
do("GET", "/Logout", noH, "", 200, "Logout OK")
}