func putCorrectDataUser(user *models.User) { date := time.Now() user.IdUser = "******" user.Name = "Juan Login" user.Pass = "******" user.Email = "*****@*****.**" user.LastLogin = date.Add(time.Minute * (-5)) user.CreatedAt = date.AddDate(-1, 0, 0) user.UpdateAt = date.Add(time.Hour * (-5)) token, err := models.GenerateToken(user.Name, user.Pass) user.Token = token err = user.Save() if err != nil { log.Println("Can't save user for test login", err) } }
user := models.User{} body, _ := json.Marshal(user) request, _ = http.NewRequest("POST", "/auth/login", bytes.NewReader(body)) }) It("Response should be 400 with empty input", func() { serve.Handler.ServeHTTP(recorder, request) Expect(recorder.Code).To(gomega.Equal(400)) }) It("Response should be 400 with wrong data", func() { user := models.User{} putCorrectDataUser(&user) user.Name = "wrong" user.IdUser = "******" user.Pass = "******" body, _ := json.Marshal(user) request, _ = http.NewRequest("POST", "/auth/login", bytes.NewReader(body)) serve.Handler.ServeHTTP(recorder, request) Expect(recorder.Code).To(gomega.Equal(404)) }) }) Context("With valid JSON", func() { var user models.User user = models.User{}