<commit_before>package handlers_test

import (
	"net/http"
	"strconv"
	"testing"
)

func createUser(user *User) (*User, error) {
	var u User
	err := create(server.Client(), user, &u, "/user/", "user")
	return &u, err
}

func getUser(client *http.Client, userid int64) (*User, error) {
	var u User
	err := read(client, &u, "/user/"+strconv.FormatInt(userid, 10), "user")
	if err != nil {
		return nil, err
	}
	return &u, nil
}

func updateUser(client *http.Client, user *User) (*User, error) {
	var u User
	err := update(client, user, &u, "/user/"+strconv.FormatInt(user.UserId, 10), "user")
	if err != nil {
		return nil, err
	}
	return &u, nil
}

func deleteUser(client *http.Client, u *User) error {
	err := remove(client, "/user/"+strconv.FormatInt(u.UserId, 10), "user")
	if err != nil {
		return err
	}
	return nil
}

func TestCreateUser(t *testing.T) {
	RunWith(t, &data[0], func(t *testing.T, d *TestData) {
		if d.users[0].UserId == 0 || len(d.users[0].Username) == 0 {
			t.Errorf("Unable to create user: %+v", data[0].users[0])
		}

		if len(d.users[0].Password) != 0 || len(d.users[0].PasswordHash) != 0 {
			t.Error("Never send password, only send password hash when necessary")
		}
	})
}
<commit_msg>Test not allowing users to be re-created with the same username<commit_after>package handlers_test

import (
	"github.com/aclindsa/moneygo/internal/handlers"
	"net/http"
	"strconv"
	"testing"
)

func createUser(user *User) (*User, error) {
	var u User
	err := create(server.Client(), user, &u, "/user/", "user")
	return &u, err
}

func getUser(client *http.Client, userid int64) (*User, error) {
	var u User
	err := read(client, &u, "/user/"+strconv.FormatInt(userid, 10), "user")
	if err != nil {
		return nil, err
	}
	return &u, nil
}

func updateUser(client *http.Client, user *User) (*User, error) {
	var u User
	err := update(client, user, &u, "/user/"+strconv.FormatInt(user.UserId, 10), "user")
	if err != nil {
		return nil, err
	}
	return &u, nil
}

func deleteUser(client *http.Client, u *User) error {
	err := remove(client, "/user/"+strconv.FormatInt(u.UserId, 10), "user")
	if err != nil {
		return err
	}
	return nil
}

func TestCreateUser(t *testing.T) {
	RunWith(t, &data[0], func(t *testing.T, d *TestData) {
		if d.users[0].UserId == 0 || len(d.users[0].Username) == 0 {
			t.Errorf("Unable to create user: %+v", data[0].users[0])
		}

		if len(d.users[0].Password) != 0 || len(d.users[0].PasswordHash) != 0 {
			t.Error("Never send password, only send password hash when necessary")
		}
	})
}

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")
			}
		}
	})
}

{'fraction_non_alphanumeric': 0.18066666666666667, 'fraction_numerical': 0.013666666666666667, 'mean_word_length': 3.75594294770206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2207110', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1150, 'n_words': 307}