Expect(recorder.Code).To(Equal(200))
			})

			It("returns a empty body", func() {
				server.ServeHTTP(recorder, request)
				Expect(recorder.Body.String()).To(Equal("[]"))
			})
		})

		Context("when requestedFiles exist", func() {

			// Insert two valid requestedFiles into the database
			// before each test in this context.
			BeforeEach(func() {
				collection := session.DB(dbName).C("requestedFiles")
				collection.Insert(gory.Build("requestedFile"))
				collection.Insert(gory.Build("requestedFile"))

			})

			It("returns a status code of 200", func() {
				server.ServeHTTP(recorder, request)
				Expect(recorder.Code).To(Equal(200))
			})

			It("returns those requestedFiles in the body", func() {
				server.ServeHTTP(recorder, request)
				peopleJSON := sliceFromJSON(recorder.Body.Bytes())
				fmt.Println(recorder)
				Expect(len(peopleJSON)).To(Equal(2))
				Expect(eventJSON["category"]).To(Equal("Sale"))
				//Expect(time.Parse(time.RFC3339,eventJSON["start_time"].(string))).To(Equal(time.Date(2999, time.January, 1, 12, 12, 12, 12, time.UTC)))
				//Expect(time.Parse(time.RFC3339,eventJSON["end_time"].(string))).To(Equal(time.Date(2999, time.January, 2, 12, 12, 12, 12, time.UTC)))
			})
		})
	})

	Describe("POST /events", func() {

		Context("with invalid JSON", func() {

			// Create a POST request using JSON from our invalid
			// factory object before each test in this context.
			BeforeEach(func() {
				body, _ := json.Marshal(
					gory.Build("eventAlreadyOver"))
				request, _ = http.NewRequest(
					"POST", "/events", bytes.NewReader(body))
			})

			It("returns a status code of 422", func() {
				testServer.ServeHTTP(recorder, request)
				Expect(recorder.Code).To(Equal(422))
			})
		})

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

			// Create a POST request with valid JSON from
			// our factory before each test in this context.
			BeforeEach(func() {
			})

			/*It("returns a empty body", func() {
				server.ServeHTTP(recorder, request)
				fmt.Printf("%v\n", recorder)
				Expect(recorder.Body.String()).To(Equal("[]"))
				//Expect(recorder.Body.String()).To(Equal(`"Email-Available"`))
			})*/
		})

		Context("when email in use", func() {

			// Insert a valid company uri
			// before each test in this context.
			BeforeEach(func() {
				regView := gory.Build("userRegistrationDuplicate").(*UserRegistrationView)
				credentials, _ = DecodeRegistrationDetails(regView)
				credentials.Id = uuid.NewV4()

				repo.SaveCredentials(credentials.Id, credentials)
			})

			It("returns a status code of 302", func() {
				server.ServeHTTP(recorder, request)
				fmt.Printf("%v\n", recorder)
				Expect(recorder.Code).To(Equal(302))
			})

			/*It("returns the user info", func() {
				server.ServeHTTP(recorder, request)
				fmt.Printf("%v\n", recorder)
Exemple #4
0
	var request *http.Request
	var recorder *httptest.ResponseRecorder
	BeforeEach(func() {
		server = Routes()
		recorder = httptest.NewRecorder()
	})
	AfterEach(func() {
		chanDelete := make(chan service.ExecSQLType)
		go service.ExecSQL("truncate table users", chanDelete)
		_ = <-chanDelete
	})
	Describe("POST /api/v1/users", func() {
		Context("with username and phone_number", func() {
			BeforeEach(func() {
				body, _ := json.Marshal(
					gory.Build("user"))
				request, _ = http.NewRequest(
					"POST", "/api/v1/users", bytes.NewReader(body))
				request.Header.Set("Authorization", "1234")
			})
			It("returns a status code of 201", func() {
				server.ServeHTTP(recorder, request)
				Expect(recorder.Code).To(Equal(201))
			})
		})

		Context("username empty", func() {
			BeforeEach(func() {
				body, _ := json.Marshal(
					gory.Build("userNameEmpty"))
				request, _ = http.NewRequest(
Exemple #5
0
			session = newSession(dburl)
			serve = server.NewServer()
			recorder = httptest.NewRecorder()
		})

		AfterEach(func() {
			// Clean the database
			session.DB(dbName).DropDatabase()
			session.Close()
		})

		Describe("POST /auth/signup", func() {

			Context("With invalid JSON", func() {
				BeforeEach(func() {
					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()
Exemple #6
0
package gory_test

import (
	"github.com/modocache/gory"
	"unsafe"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Gory", func() {
	Describe("Define()", func() {
		Context("when the factory function is nil", func() {
			It("creates a definition that doesn't set any values", func() {
				gory.Define("empty", Builtin{}, nil)
				empty := gory.Build("empty").(*Builtin)
				Expect(empty.Int).To(Equal(0))
			})
		})

		Context("when attempting to create a definition with the same name", func() {
			var name string
			BeforeEach(func() {
				name = "dupe"
				gory.Define(name, Builtin{}, func(factory gory.Factory) {})
			})

			It("panics", func() {
				define := func() { gory.Define(name, Builtin{}, func(factory gory.Factory) {}) }
				Expect(define).To(Panic())
			})
Exemple #7
0
						strings.NewReader(body))
					request.Header.Add("Authorization", "Bearer "+token.Hash)
				})

				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()
Exemple #8
0
	"net/http"
	"net/http/httptest"
)

var _ = Describe("Server", func() {
	var server Server
	var request *http.Request
	var recorder *httptest.ResponseRecorder
	BeforeEach(func() {
		server = routes.New()
		recorder = httptest.NewRecorder()
	})
	AfterEach(func() {

	})
	Describe("POST /api/v1/users", func() {
		Context("with username and phone_number", func() {
			BeforeEach(func() {
				body, _ := json.Marshal(
					gory.Build("user"))
				request, _ = http.NewRequest(
					"POST", "localhost:8080/api/v1/users", bytes.NewReader(body))
			})
			It("returns a status code of 201", func() {
				server.ServeHTTP(recorder, request)
				Expect(recorder.Code).To(Equal(200))
			})
		})
	})
})