Test not allowing users to be re-created with the same username

This commit is contained in:
Aaron Lindsay 2017-10-14 20:47:57 -04:00
parent 85a58c3ff8
commit af9371aeb9
1 changed files with 19 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package handlers_test
import (
"github.com/aclindsa/moneygo/internal/handlers"
"net/http"
"strconv"
"testing"
@ -50,6 +51,24 @@ func TestCreateUser(t *testing.T) {
})
}
func TestDontRecreateUser(t *testing.T) {
RunWith(t, &data[0], func(t *testing.T, d *TestData) {
for _, user := range data[0].users {
_, err := createUser(&user)
if err == nil {
t.Fatalf("Expected error re-creating user")
}
if herr, ok := err.(*handlers.Error); ok {
if herr.ErrorId != 4 { // User exists
t.Fatalf("Unexpected API error re-creating user: %s", herr)
}
} else {
t.Fatalf("Expected error re-creating user")
}
}
})
}
func TestGetUser(t *testing.T) {
RunWith(t, &data[0], func(t *testing.T, d *TestData) {
u, err := getUser(d.clients[0], d.users[0].UserId)