// Defines factories for testing
// Allows for simple object creation during testing
func defineFactories() {
	validID := bson.NewObjectId()

	gory.Define("event", models.Event{},
		func(factory gory.Factory) {
			factory["Title"] = "Yard Sale!"
			factory["Description"] = "Getting a bunch of old stuff out of the attic!"
			factory["Category"] = "Sale"
			factory["CreatedBy"] = bson.NewObjectId()
			factory["StartTime"] = time.Date(2999, time.January, 1, 12, 12, 12, 12, time.UTC)
			factory["EndTime"] = time.Date(2999, time.January, 2, 12, 12, 12, 12, time.UTC)
		})

	gory.Define("eventAlreadyOver", models.Event{},
		func(factory gory.Factory) {
			factory["Title"] = "Pubcrawl!"
			factory["Description"] = "Come to the Ruck!"
			factory["Category"] = "Pubcrawl"
			factory["CreatedBy"] = bson.NewObjectId()
			factory["StartTime"] = time.Now().UTC()
			factory["EndTime"] = time.Now().UTC()
		})

	gory.Define("eventTitleTooShort", models.Event{},
		func(factory gory.Factory) {
			factory["Title"] = "Test"
			factory["Description"] = "Trying ThingsToDo"
			factory["Category"] = "Other"
			factory["CreatedBy"] = bson.NewObjectId()
			factory["StartTime"] = time.Date(2999, time.January, 1, 12, 12, 12, 12, time.UTC)
			factory["EndTime"] = time.Date(2999, time.January, 2, 12, 12, 12, 12, time.UTC)
		})

	gory.Define("eventCommentTest", models.Event{},
		func(factory gory.Factory) {
			factory["Title"] = "Yard Sale!"
			factory["Description"] = "Getting a bunch of old stuff out of the attic!"
			factory["Category"] = "Sale"
			factory["Id"] = validID
			factory["CreatedBy"] = bson.NewObjectId()
			factory["StartTime"] = time.Date(2999, time.January, 1, 12, 12, 12, 12, time.UTC)
			factory["EndTime"] = time.Date(2999, time.January, 2, 12, 12, 12, 12, time.UTC)
		})

	gory.Define("comment", models.Comment{},
		func(factory gory.Factory) {
			factory["Comment"] = "This is a valid comment."
			factory["EventId"] = validID
		})

}
func defineFactories() {

	gory.Define("userRegistration", UserRegistrationView{},
		func(factory gory.Factory) {
			factory["Email"] = gory.Sequence(
				func(n int) interface{} {
					return fmt.Sprintf("*****@*****.**", n)
				})
			factory["Password"] = "******"
		})

	gory.Define("userRegistrationDuplicate", UserRegistrationView{},
		func(factory gory.Factory) {
			factory["Email"] = "*****@*****.**"
			factory["Password"] = "******"
		})

	gory.Define("userRegistrationDupEmail", UserRegistrationView{},
		func(factory gory.Factory) {
			factory["Email"] = gory.Sequence(
				func(n int) interface{} {
					return fmt.Sprintf("*****@*****.**")
				})
			factory["Password"] = "******"
		})

	gory.Define("userRegistrationMissingEmail", UserRegistrationView{},
		func(factory gory.Factory) {
			factory["Password"] = "******"
		})

	gory.Define("loginValid", LoginView{},
		func(factory gory.Factory) {
			factory["Email"] = "*****@*****.**"
			factory["Password"] = "******"
		})

	gory.Define("passwordChangeRequest", ChangePasswordView{},
		func(factory gory.Factory) {
			factory["OldPassword"] = "******"
			factory["NewPassword"] = "******"
		})

	gory.Define("passwordChangeRequestWrongPassword", ChangePasswordView{},
		func(factory gory.Factory) {
			factory["OldPassword"] = "******"
			factory["NewPassword"] = "******"
		})

	gory.Define("passwordChangeRequestMissingInfo", ChangePasswordView{},
		func(factory gory.Factory) {
			factory["OldPassword"] = "******"
		})

}
Ejemplo n.º 3
0
/*
Define two factories: one for a valid signature,
and one for an invalid one (too young).
*/
func defineFactories() {
	gory.Define("signature", Signature{},
		func(factory gory.Factory) {
			factory["FirstName"] = "Jane"
			factory["LastName"] = "Doe"
			factory["Age"] = 27
			factory["Message"] = "I agree!"
			factory["Email"] = gory.Sequence(
				func(n int) interface{} {
					return fmt.Sprintf("*****@*****.**", n)
				})
		})

	gory.Define("signatureTooYoung", Signature{},
		func(factory gory.Factory) {
			factory["FirstName"] = "Joey"
			factory["LastName"] = "Invalid"
			factory["Age"] = 10
			factory["Email"] = "*****@*****.**"
		})
}
Ejemplo n.º 4
0
func defineFactories() {
	gory.Define("user", requests.User{},
		func(factory gory.Factory) {
			factory["UserName"] = "******"
			factory["PhoneNumber"] = "+628973187318"
		})
	gory.Define("userNameEmpty", requests.User{},
		func(factory gory.Factory) {
			factory["UserName"] = ""
			factory["PhoneNumber"] = "+628973187318"
		})
	gory.Define("phoneNumberEmpty", requests.User{},
		func(factory gory.Factory) {
			factory["UserName"] = "******"
			factory["PhoneNumber"] = ""
		})
	gory.Define("phoneNumberAndUserEmpty", requests.User{},
		func(factory gory.Factory) {
			factory["UserName"] = ""
			factory["PhoneNumber"] = ""
		})
}
Ejemplo n.º 5
0
// Define factories: for a valid user,
// and for an invalid one
func defineFactories() {
	date := time.Now()
	gory.Define("userOk", models.User{},
		func(factory gory.Factory) {
			factory["IdUser"] = "******"
			factory["Name"] = "Existe"
			factory["Pass"] = "******"
			factory["Email"] = "*****@*****.**"
			factory["LastLogin"] = date
			factory["CreatedAt"] = date
			factory["UpdateAt"] = date
		})

	gory.Define("userBad", models.User{},
		func(factory gory.Factory) {
			factory["IdUser"] = "******"
			factory["Name"] = "NoExisteElUsuario"
			factory["Pass"] = "******"
			factory["Email"] = "estonoesunmailcom"
			factory["LastLogin"] = date
			factory["CreatedAt"] = date
			factory["UpdateAt"] = date
		})
}
Ejemplo n.º 6
0
// Define factories: for a valid user,
// and for an invalid one
func defineFactories() {
	date := time.Now()
	gory.Define("userOk", models.User{},
		func(factory gory.Factory) {
			factory["IdUser"] = "******"
			factory["Name"] = "Juan"
			factory["Pass"] = "******"
			factory["Email"] = "*****@*****.**"
			factory["LastLogin"] = date.Add(time.Minute * (-5))
			factory["CreatedAt"] = date.AddDate(-1, 0, 0)
			factory["UpdateAt"] = date.Add(time.Hour * (-5))
		})

	gory.Define("userBad", models.User{},
		func(factory gory.Factory) {
			factory["IdUser"] = "******"
			factory["Name"] = "Juan123"
			factory["Pass"] = "******"
			factory["Email"] = "estonoesunmailcom"
			factory["LastLogin"] = date.Add(time.Minute * 5)
			factory["CreatedAt"] = date.AddDate(2, 0, 0)
			factory["UpdateAt"] = date.Add(time.Hour * 5)
		})
}
Ejemplo n.º 7
0
type Lazily struct {
	Uuid string
}

var _ = BeforeSuite(func() {
	gory.Define("builtin", Builtin{}, func(factory gory.Factory) {
		factory["Bool"] = true
		factory["String"] = "string"
		factory["Int"] = 1
		factory["Int8"] = int8(8)
		factory["Int16"] = int16(16)
		factory["Int32"] = int32(32)
		factory["Int64"] = int64(64)
		factory["Uint"] = uint(1)
		factory["Uint8"] = uint8(8)
		factory["Uint16"] = uint16(16)
		factory["Uint32"] = uint32(32)
		factory["Uint64"] = uint64(64)
		factory["Uintptr"] = unsafe.Sizeof([]int{})
		factory["Byte"] = factory["String"].(string)[0]
		factory["Rune"] = '⌘'
		factory["Float32"] = float32(32.0)
		factory["Float64"] = float64(64.0)
		factory["Complex64"] = complex(float32(10.0), float32(-1.0))
		factory["Complex128"] = complex(float64(-10.0), float64(1.0))
	})

	gory.Define("unexported", Unexported{}, func(factory gory.Factory) {
		factory["str"] = "boom!"
	})
Ejemplo n.º 8
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())
			})
Ejemplo n.º 9
0
func defineFactories() {
	gory.Define("location", Location{},
		func(factory gory.Factory) {
			factory["Latitude"] = "?"
		})
}