Commit 36497ade authored by Alexis POYEN's avatar Alexis POYEN
Browse files

Test : add app test

parent 9937ee52
......@@ -62,6 +62,8 @@ func TestAll(t *testing.T) {
BankerTests(t)
resetData(t)
AdminTests(t)
resetData(t)
appTests(t)
os.RemoveAll("./data")
}
......@@ -77,15 +79,46 @@ func Oauth2Tests(t *testing.T) {
do("GET", "/OAuth2Login", noH, "", 500, "invalid oauth state")
}
// func createUserTests(t *testing.T) {
func appTests(t *testing.T) {
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}
// Add invalid operation between client and Bakery must be refused with 417 (Expectation failed)
do("POST", "/api/Operations", xsrfHeader, `{"Debtor":1,"Amount":-1789,"Creditor":2}`, 417, "Not enough money")
// }
// Add an operation between Dupond and Bakery and verify that bank accounts are updated and opposite operation is created
do("POST", "/api/Operations", xsrfHeader, `{"Debtor":1,"Amount":-100,"Creditor":2}`, 200, "")
do("GET", "/api/Operations/1", xsrfHeader, "", 200, `{"ID":1,"Debtor":1,"Amount":-100`)
do("GET", "/api/Operations/2", xsrfHeader, "", 200, `{"ID":2,"Debtor":2,"Amount":100`)
do("GET", "/api/BankAccounts/1", xsrfHeader, "", 200, `{"ID":1,"Number":"01-01","UserClientID":1,"Type":"checking-account","Amount":358,"BankOverdraft":-100,"Operations":[{"ID":1,"Debtor":1,"Amount":-100,"Date":"`)
do("GET", "/api/BankAccounts/2", xsrfHeader, "", 200, `{"ID":2,"Number":"02-01","UserClientID":2,"Type":"checking-account","Amount":4845,"BankOverdraft":-500,"Operations":[{"ID":2,"Debtor":2,"Amount":100,"Date":`)
// func appTests(t *testing.T) {
// // Add invalid operation between client and Bakery must be refused with 417 (Expectation failed)
// // do("POST", "/api/Operations", xsrfHeader, `{"Debtor":1,"Amount":-1789,"Creditor":3}`, 417, "Not enough money")
// Try to delete the first operation, the opposite operation should also have been deleted and bank accounts updated
do("DELETE", "/api/Operations/1", xsrfHeader, ``, 200, "")
do("GET", "/api/Operations/1", xsrfHeader, "", 404, `id does not exist`)
do("GET", "/api/Operations/2", xsrfHeader, "", 404, `id does not exist`)
do("GET", "/api/BankAccounts/1", xsrfHeader, "", 200, `{"ID":1,"Number":"01-01","UserClientID":1,"Type":"checking-account","Amount":458,"BankOverdraft":-100,"Operations":[]}`)
do("GET", "/api/BankAccounts/2", xsrfHeader, "", 200, `{"ID":2,"Number":"02-01","UserClientID":2,"Type":"checking-account","Amount":4745,"BankOverdraft":-500,"Operations":[]}`)
// }
// Delete a client should also delete his banks accounts
do("DELETE", "/api/UserClients/1", xsrfHeader, ``, 200, "")
do("GET", "/api/BankAccounts/1", xsrfHeader, "", 404, `id does not exist`)
}
// Do an OAuth2 login with an known admin
do("GET", "/OAuth2Login", noH, "", 200, "<!DOCTYPE html>")
tests()
// Try to logout (must pass)
do("GET", "/Logout", noH, "", 200, "Logout OK")
}
func resetData(t *testing.T) {
os.RemoveAll("./data")
......
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