func (suite *AuthenticationServicesTestSuite) TestLogin(c *C) { user := models.User{ Username: "******", Password: "******", } response, token := services.Login(&user) assert.Equal(t, http.StatusOK, response) assert.NotEmpty(t, token) }
func (suite *AuthenticationServicesTestSuite) TestLoginEmptyCredentials(c *C) { user := models.User{ Username: "", Password: "", } response, token := services.Login(&user) assert.Equal(t, http.StatusUnauthorized, response) assert.Empty(t, token) }
func Login(w http.ResponseWriter, r *http.Request) { requestUser := new(models.User) decoder := json.NewDecoder(r.Body) decoder.Decode(&requestUser) responseStatus, token := services.Login(requestUser) w.Header().Set("Content-Type", "application/json") w.WriteHeader(responseStatus) w.Write(token) }