github.com/unclejack/drone@v0.2.1-0.20140918182345-831b034aa33b/pkg/handler/testing/users_test.go (about) 1 package testing 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "net/url" 7 "testing" 8 9 "github.com/drone/drone/pkg/database" 10 . "github.com/drone/drone/pkg/database/testing" 11 "github.com/drone/drone/pkg/handler" 12 . "github.com/drone/drone/pkg/model" 13 . "github.com/smartystreets/goconvey/convey" 14 ) 15 16 func TestUserProfilePage(t *testing.T) { 17 // seed the database with values 18 Setup() 19 defer Teardown() 20 21 // dummy request 22 req := http.Request{} 23 req.Form = url.Values{} 24 25 Convey("User Profile", t, func() { 26 SkipConvey("View Profile Information", func() { 27 user, _ := database.GetUser(1) 28 res := httptest.NewRecorder() 29 handler.UserUpdate(res, &req, user) 30 31 Convey("Email Address is correct", func() { 32 33 }) 34 Convey("User Name is correct", func() { 35 36 }) 37 }) 38 Convey("Update Email Address", func() { 39 Convey("With a Valid Email Address", func() { 40 user, _ := database.GetUser(1) 41 req.Form.Set("name", "John Smith") 42 req.Form.Set("email", "John.Smith@gmail.com") 43 res := httptest.NewRecorder() 44 handler.UserUpdate(res, &req, user) 45 46 So(res.Code, ShouldEqual, http.StatusOK) 47 }) 48 Convey("With an Invalid Email Address", func() { 49 user, _ := database.GetUser(1) 50 req.Form.Set("name", "John Smith") 51 req.Form.Set("email", "John.Smith") 52 res := httptest.NewRecorder() 53 handler.UserUpdate(res, &req, user) 54 55 So(res.Code, ShouldEqual, http.StatusBadRequest) 56 So(res.Body.String(), ShouldContainSubstring, ErrInvalidEmail.Error()) 57 }) 58 Convey("With an Empty Email Address", func() { 59 user, _ := database.GetUser(1) 60 req.Form.Set("name", "John Smith") 61 req.Form.Set("email", "") 62 res := httptest.NewRecorder() 63 handler.UserUpdate(res, &req, user) 64 65 So(res.Code, ShouldEqual, http.StatusBadRequest) 66 So(res.Body.String(), ShouldContainSubstring, ErrInvalidEmail.Error()) 67 }) 68 Convey("With a Duplicate Email Address", func() { 69 user, _ := database.GetUser(1) 70 req.Form.Set("name", "John Smith") 71 req.Form.Set("email", "cavepig@gmail.com") 72 res := httptest.NewRecorder() 73 handler.UserUpdate(res, &req, user) 74 75 So(res.Code, ShouldEqual, http.StatusBadRequest) 76 }) 77 }) 78 79 Convey("Update User Name", func() { 80 Convey("With a Valid Name", func() { 81 user, _ := database.GetUser(1) 82 req.Form.Set("name", "John Smith") 83 req.Form.Set("email", "John.Smith@gmail.com") 84 res := httptest.NewRecorder() 85 handler.UserUpdate(res, &req, user) 86 87 So(res.Code, ShouldEqual, http.StatusOK) 88 }) 89 Convey("With an Empty Name", func() { 90 user, _ := database.GetUser(1) 91 req.Form.Set("name", "") 92 req.Form.Set("email", "John.Smith@gmail.com") 93 res := httptest.NewRecorder() 94 handler.UserUpdate(res, &req, user) 95 96 So(res.Code, ShouldEqual, http.StatusBadRequest) 97 So(res.Body.String(), ShouldContainSubstring, ErrInvalidUserName.Error()) 98 }) 99 }) 100 101 Convey("Change Password", func() { 102 Convey("To a Valid Password", func() { 103 user, _ := database.GetUser(1) 104 req.Form.Set("password", "password123") 105 res := httptest.NewRecorder() 106 handler.UserPassUpdate(res, &req, user) 107 108 So(res.Code, ShouldEqual, http.StatusOK) 109 So(user.ComparePassword("password123"), ShouldBeNil) 110 }) 111 Convey("To an Invalid Password, too short", func() { 112 user, _ := database.GetUser(1) 113 req.Form.Set("password", "123") 114 res := httptest.NewRecorder() 115 handler.UserPassUpdate(res, &req, user) 116 117 So(res.Code, ShouldEqual, http.StatusBadRequest) 118 }) 119 }) 120 Convey("Delete the Account", func() { 121 Convey("Providing an Invalid Password", func() { 122 user, _ := database.GetUser(1) 123 req.Form.Set("password", "password111") 124 res := httptest.NewRecorder() 125 handler.UserDelete(res, &req, user) 126 127 So(res.Code, ShouldEqual, http.StatusBadRequest) 128 }) 129 SkipConvey("Providing a Valid Password", func() { 130 // TODO Skipping because there are no teampltes 131 // loaded which will cause a panic 132 user, _ := database.GetUser(2) 133 req.Form.Set("password", "password") 134 res := httptest.NewRecorder() 135 handler.UserDelete(res, &req, user) 136 137 So(res.Code, ShouldEqual, http.StatusOK) 138 }) 139 }) 140 }) 141 } 142 143 func TestUserTeamPage(t *testing.T) { 144 // seed the database with values 145 Setup() 146 defer Teardown() 147 148 // dummy request 149 //req := http.Request{} 150 //req.Form = url.Values{} 151 152 Convey("User Team Page", t, func() { 153 SkipConvey("View List of Teams", func() { 154 155 }) 156 SkipConvey("View Empty List of Teams", func() { 157 158 }) 159 }) 160 161 Convey("Create a Team", t, func() { 162 SkipConvey("With an Invalid Name", func() { 163 164 }) 165 SkipConvey("With an Invalid Email", func() { 166 167 }) 168 SkipConvey("With a Valid Name and Email", func() { 169 170 }) 171 }) 172 }