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) } }
}) It("Return status code 400", func() { serve.Handler.ServeHTTP(recorder, request) Expect(recorder.Code).To(gomega.Equal(400)) }) }) Context("With a real user", func() { var user *models.User BeforeEach(func() { user = gory.Build("userOk").(*models.User) token, _ := models.GenerateToken(user.Email + "#" + user.Pass) user.Token = token user.Save() body := "" request, _ = http.NewRequest("GET", "/fake", strings.NewReader(body)) request.Header.Add("Authorization", "Bearer "+token.Hash) }) It("Check if user with token is saved on the database", func() { chkUser := models.User{} chkUser.IdUser = user.IdUser chkUser, err := chkUser.Get() Expect(err).To(gomega.BeNil()) Expect(chkUser).ShouldNot(gomega.BeZero())