Exemple #1
0
				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())
				})

				It("Return status code 200", func() {
					serve.Handler.ServeHTTP(recorder, request)
					Expect(recorder.Code).To(gomega.Equal(200))
				})
			})

			Context("With a user who does not exist in the database", func() {

				var user *models.User
Exemple #2
0
					body, _ := json.Marshal(gory.Build("userBad"))
					request, _ = http.NewRequest("POST", "/auth/signup",
						bytes.NewReader(body))
				})

				It("Return a status code of 400", func() {
					serve.Handler.ServeHTTP(recorder, request)
					Expect(recorder.Code).To(gomega.Equal(400))
				})

				It("User must not be saved in the database", func() {
					user := gory.Build("userBad").(*models.User)
					userTest := models.User{
						IdUser: user.IdUser,
					}
					userTest, err := userTest.Get()
					errTest := errors.New("not found")
					Expect(err).To(gomega.Equal(errTest))
					Expect(userTest).To(gomega.BeZero())
				})
			})

			Context("With valid JSON", func() {

				BeforeEach(func() {
					body, _ := json.Marshal(gory.Build("userOk"))
					request, _ = http.NewRequest("POST", "/auth/signup",
						bytes.NewReader(body))
				})

				It("Return a status code of 200", func() {
Exemple #3
0
				Email:     "*****@*****.**",
				LastLogin: time.Now(),
				CreatedAt: time.Now(),
				UpdateAt:  time.Now(),
			}

			err := user.Save()
			Expect(err).To(gomega.BeNil())
		})

		It("Get user with Id", func() {
			user := models.User{
				IdUser: "******",
			}

			user, err := user.Get()
			Expect(err).To(gomega.BeNil())
			Expect(user.Name).To(gomega.Equal("test"))
			Expect(user.Pass).To(gomega.Equal("1234"))
		})

		It("Delete user with Id", func() {
			user := models.User{
				IdUser: "******",
			}
			err := user.Delete()
			Expect(err).To(gomega.BeNil())
		})

		Context("If user deleted", func() {
			user := models.User{