summaryrefslogtreecommitdiff
path: root/server/test/guest_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'server/test/guest_test.go')
-rw-r--r--server/test/guest_test.go52
1 files changed, 27 insertions, 25 deletions
diff --git a/server/test/guest_test.go b/server/test/guest_test.go
index 490df84..b7d1aae 100644
--- a/server/test/guest_test.go
+++ b/server/test/guest_test.go
@@ -21,7 +21,7 @@ var (
password = os.Getenv("PASS")
host = "localhost"
port = "5432"
- database = "postgres"
+ database = "wedding"
)
func TestUpdateRSVP(test *testing.T) {
@@ -66,13 +66,13 @@ func TestUpdateRSVP(test *testing.T) {
func logInGuest(guestHandler *guest.GuestHandler, test *testing.T) guest.Login {
response := httptest.NewRecorder()
loginRequest, err := http.NewRequest(http.MethodPost,
- fmt.Sprintf("http://%s:8080/guests/login", host), strings.NewReader(getName()))
+ fmt.Sprintf("http://%s:8080/api/guests/login", host), strings.NewReader(getName()))
if err != nil {
test.Error(err)
}
guestHandler.ServeHTTP(response, loginRequest)
- assertEquals(test, response.Result().StatusCode, 200)
+ assertEquals(test, response.Code, 200)
var login guest.Login
if err = json.NewDecoder(response.Body).Decode(&login); err != nil {
log.Fatal(err)
@@ -83,24 +83,24 @@ func logInGuest(guestHandler *guest.GuestHandler, test *testing.T) guest.Login {
func addPartyMember(guestHandler *guest.GuestHandler, token string, test *testing.T) {
response := httptest.NewRecorder()
putRequest, err := http.NewRequest(http.MethodPut,
- fmt.Sprintf("http://%s:8080/guests/1", host), strings.NewReader(getUpdatedGuest()))
+ fmt.Sprintf("http://%s:8080/api/guests/1", host), strings.NewReader(getUpdatedGuest()))
if err != nil {
test.Error(err)
}
putRequest.Header.Set("Authorization", token)
guestHandler.ServeHTTP(response, putRequest)
- assertEquals(test, response.Result().StatusCode, 200)
+ assertEquals(test, response.Code, 200)
}
func logInAdmin(adminHandler *admin.AdminHandler, test *testing.T) admin.Login {
response := httptest.NewRecorder()
loginRequest, err := http.NewRequest(http.MethodPost,
- fmt.Sprintf("http://%s:8080/admin/login", host), strings.NewReader(getCredentials()))
+ fmt.Sprintf("http://%s:8080/api/admin/login", host), strings.NewReader(getCredentials()))
if err != nil {
test.Error(err)
}
adminHandler.ServeHTTP(response, loginRequest)
- assertEquals(test, response.Result().StatusCode, 200)
+ assertEquals(test, response.Code, 200)
var login admin.Login
if err = json.NewDecoder(response.Body).Decode(&login); err != nil {
log.Fatal(err)
@@ -111,13 +111,13 @@ func logInAdmin(adminHandler *admin.AdminHandler, test *testing.T) admin.Login {
func getGuests(guestHandler *guest.GuestHandler, token string, test *testing.T) []guest.Guest {
response := httptest.NewRecorder()
getRequest, err := http.NewRequest(http.MethodGet,
- fmt.Sprintf("http://%s:8080/guests/", host), nil)
+ fmt.Sprintf("http://%s:8080/api/guests/", host), nil)
if err != nil {
test.Error(err)
}
getRequest.Header.Set("Authorization", token)
guestHandler.ServeHTTP(response, getRequest)
- assertEquals(test, response.Result().StatusCode, 200)
+ assertEquals(test, response.Code, 200)
var guests []guest.Guest
if err := json.NewDecoder(response.Body).Decode(&guests); err != nil {
test.Error(err)
@@ -128,18 +128,18 @@ func getGuests(guestHandler *guest.GuestHandler, token string, test *testing.T)
func deletePartyMember(guestHandler *guest.GuestHandler, token string, test *testing.T) {
response := httptest.NewRecorder()
putRequest, err := http.NewRequest(http.MethodPut,
- fmt.Sprintf("http://%s:8080/guests/1", host), strings.NewReader(getEmptyGuest()))
+ fmt.Sprintf("http://%s:8080/api/guests/4095e885-8d1b-4c59-9fee-4d6ef53b86a3", host), strings.NewReader(getEmptyGuest()))
if err != nil {
test.Error(err)
}
putRequest.Header.Set("Authorization", token)
guestHandler.ServeHTTP(response, putRequest)
- assertEquals(test, response.Result().StatusCode, 200)
+ assertEquals(test, response.Code, 200)
}
func findGuest(guests []guest.Guest) *guest.Guest {
for _, guest := range guests {
- if guest.ID == 1 {
+ if guest.FirstName == "Michael" {
return &guest
}
}
@@ -163,14 +163,16 @@ func getCredentials() string {
}
func getUpdatedGuest() string {
- return `{"id":1,"firstName":"Michael","lastName":"Hunteman", "attendance":"accept",
+ return `{"id":"4095e885-8d1b-4c59-9fee-4d6ef53b86a3","firstName":"Michael",
+ "lastName":"Hunteman", "attendance":"accept",
"email":"mhunteman@cox.net","message":"We'll be there!","partySize":2,
"partyList":[{"firstName":"Madison","lastName":"Rossitto"}]}`
}
func getEmptyGuest() string {
- return `{"id":1,"firstName":"Michael","lastName":"Hunteman","attendance":"",
- "email":"","message":"","partySize":1,"partyList":[]}`
+ return `{"id":"4095e885-8d1b-4c59-9fee-4d6ef53b86a3","firstName":"Michael",
+ "lastName":"Hunteman","attendance":"", "email":"","message":"",
+ "partySize":1,"partyList":[]}`
}
func TestAddGuest(test *testing.T) {
@@ -206,25 +208,25 @@ func TestAddGuest(test *testing.T) {
func deleteGuest(guestHandler *guest.GuestHandler, token string, test *testing.T) {
response := httptest.NewRecorder()
deleteRequest, err := http.NewRequest(http.MethodDelete,
- fmt.Sprintf("http://%s:8080/guests/1", host), nil)
+ fmt.Sprintf("http://%s:8080/api/guests/4095e885-8d1b-4c59-9fee-4d6ef53b86a3", host), nil)
if err != nil {
test.Error(err)
}
deleteRequest.Header.Set("Authorization", token)
guestHandler.ServeHTTP(response, deleteRequest)
- assertEquals(test, response.Result().StatusCode, 200)
+ assertEquals(test, response.Code, 200)
}
func postGuest(guestHandler *guest.GuestHandler, token string, test *testing.T) {
response := httptest.NewRecorder()
putRequest, err := http.NewRequest(http.MethodPost,
- fmt.Sprintf("http://%s:8080/guests/", host), strings.NewReader(getEmptyGuest()))
+ fmt.Sprintf("http://%s:8080/api/guests/", host), strings.NewReader(getEmptyGuest()))
if err != nil {
test.Error(err)
}
putRequest.Header.Set("Authorization", token)
guestHandler.ServeHTTP(response, putRequest)
- assertEquals(test, response.Result().StatusCode, 200)
+ assertEquals(test, response.Code, 200)
}
func TestInvalidGuest(test *testing.T) {
@@ -244,25 +246,25 @@ func TestInvalidGuest(test *testing.T) {
func logInInvalidGuest(guestHandler *guest.GuestHandler, test *testing.T) {
response := httptest.NewRecorder()
loginRequest, err := http.NewRequest(http.MethodPost,
- fmt.Sprintf("http://%s:8080/guests/login", host), strings.NewReader("{}"))
+ fmt.Sprintf("http://%s:8080/api/guests/login", host), strings.NewReader("{}"))
if err != nil {
test.Error(err)
}
guestHandler.ServeHTTP(response, loginRequest)
- assertEquals(test, response.Result().StatusCode, 401)
+ assertEquals(test, response.Code, 401)
}
func updateInvalidGuest(guestHandler *guest.GuestHandler, token string, test *testing.T) {
response := httptest.NewRecorder()
putRequest, err := http.NewRequest(http.MethodPut,
- fmt.Sprintf("http://%s:8080/guests/1", host), strings.NewReader(getUpdatedGuest()))
+ fmt.Sprintf("http://%s:8080/api/guests/1", host), strings.NewReader(getUpdatedGuest()))
if err != nil {
test.Error(err)
}
putRequest.Header.Set("Authorization", token)
guestHandler.ServeHTTP(response, putRequest)
- assertEquals(test, response.Result().StatusCode, 400)
+ assertEquals(test, response.Code, 400)
}
func TestInvalidAdmin(test *testing.T) {
@@ -282,11 +284,11 @@ func TestInvalidAdmin(test *testing.T) {
func logInInvalidAdmin(adminHandler *admin.AdminHandler, token string, test *testing.T) {
response := httptest.NewRecorder()
putRequest, err := http.NewRequest(http.MethodPost,
- fmt.Sprintf("http://%s:8080/admin/login", host), strings.NewReader("{}"))
+ fmt.Sprintf("http://%s:8080/api/admin/login", host), strings.NewReader("{}"))
if err != nil {
test.Error(err)
}
putRequest.Header.Set("Authorization", token)
adminHandler.ServeHTTP(response, putRequest)
- assertEquals(test, response.Result().StatusCode, 401)
+ assertEquals(test, response.Code, 401)
}