Esempio n. 1
0
func TestWithReview(t *testing.T) {
	is := is.New(t)
	freelancerRepositoryMock := &FreelancerRepositoryMock{}
	var freelancerContext = &ApplicationContext{
		FreelancerRepository: freelancerRepositoryMock,
	}
	w := httptest.NewRecorder()
	r := getRequest(freelancerContext, `
	{
		"title":        "title",
		"clientID":     2,
		"content":      "content",
		"freelancerID": 3,
		"jobID":        4,
		"rating":       5.6
	}`)

	next := func(review *Review) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			is.Equal(review.Title, "title")
			is.Equal(review.ClientID, 2)
			is.Equal(review.Content, "content")
			is.Equal(review.FreelancerID, 3)
			is.Equal(review.JobID, 4)
			is.Equal(review.Rating, 5.6)
		})
	}

	withReview{next}.ServeHTTP(w, r)
}
Esempio n. 2
0
func TestIndexProject(t *testing.T) {
	is := is.New(t)
	projectRepositoryMock := &ProjectRepositoryMock{}
	projectRepositoryMock.GetAllProjectsCall.Returns.Projects = []Project{
		Project{
			Model: Model{
				ID: 1,
			},
		},
		Project{
			Model: Model{
				ID: 2,
			},
		},
	}
	userContext := &ApplicationContext{
		ProjectRepository: projectRepositoryMock,
	}

	r := getRequest(userContext, ``)
	w := httptest.NewRecorder()

	IndexProject(w, r)

	is.Equal(w.Code, http.StatusOK)
	var body []Project
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(body[0].Model.ID, 1)
	is.Equal(body[1].Model.ID, 2)
}
Esempio n. 3
0
func TestValueEqual(t *testing.T) {
	is := is.New(t)

	v := ParseValue([]byte("something"))
	is.True(v.Equal("something"))
	is.False(v.Equal("else"))
	is.Equal("string", v.Type())

	v = ParseValue([]byte("123"))
	is.Equal("float64", v.Type())

	v = ParseValue([]byte("/^2.{2}$/"))
	is.True(v.Equal(200))
	is.True(v.Equal(201))
	is.False(v.Equal(404))
	is.Equal("regex", v.Type())

	v = ParseValue([]byte("/application/json/"))
	is.True(v.Equal("application/json"))
	is.True(v.Equal("application/json; charset=utf-8"))
	is.True(v.Equal("text/xml; application/json; charset=utf-8"))
	is.False(v.Equal("text/xml; charset=utf-8"))
	is.Equal("regex", v.Type())
	is.Equal(`/application/json/`, v.String())

	v = ParseValue([]byte("/Silk/"))
	is.True(v.Equal("My name is Silk."))
	is.True(v.Equal("Silk is my name."))
	is.False(v.Equal("I don't contain that word!"))
}
Esempio n. 4
0
func TestWithError(t *testing.T) {
	is := is.New(t)

	w := httptest.NewRecorder()
	r := newTestRequest()

	err := errors.New("something went wrong")

	opts := &respond.Options{
		Before: func(w http.ResponseWriter, r *http.Request, status int, data interface{}) (int, interface{}) {
			if err, ok := data.(error); ok {
				return status, map[string]interface{}{"error": err.Error()}
			}
			return status, data
		},
	}
	testHandler := &testHandler{
		status: http.StatusInternalServerError,
		data:   err,
	}
	handler := opts.Handler(testHandler)

	handler.ServeHTTP(w, r)

	is.Equal(http.StatusInternalServerError, w.Code)
	var data map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &data))
	is.Equal(data, map[string]interface{}{"error": err.Error()})
	is.Equal(w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")
}
Esempio n. 5
0
func TestFileList(t *testing.T) {
	is := is.New(t)
	s := NewShell(shellUrl)

	list, err := s.FileList(fmt.Sprintf("/ipfs/%s", examplesHash))
	is.Nil(err)

	is.Equal(list.Type, "Directory")
	is.Equal(list.Size, 0)
	is.Equal(len(list.Links), 6)

	// TODO: document difference in sice betwen 'ipfs ls' and 'ipfs file ls -v'. additional object encoding in data block?
	expected := map[string]UnixLsLink{
		"about":          {Type: "File", Hash: "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V", Name: "about", Size: 1677},
		"contact":        {Type: "File", Hash: "QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y", Name: "contact", Size: 189},
		"help":           {Type: "File", Hash: "QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7", Name: "help", Size: 311},
		"quick-start":    {Type: "File", Hash: "QmUzLxaXnM8RYCPEqLDX5foToi5aNZHqfYr285w2BKhkft", Name: "quick-start", Size: 1686},
		"readme":         {Type: "File", Hash: "QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB", Name: "readme", Size: 1091},
		"security-notes": {Type: "File", Hash: "QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ", Name: "security-notes", Size: 1016},
	}
	for _, l := range list.Links {
		el, ok := expected[l.Name]
		is.True(ok)
		is.NotNil(el)
		is.Equal(*l, el)
	}
}
Esempio n. 6
0
func TestAfter(t *testing.T) {
	is := is.New(t)

	options := &respond.Options{}
	var aftercall map[string]interface{}
	options.After = func(w http.ResponseWriter, r *http.Request, status int, data interface{}) {
		aftercall = map[string]interface{}{
			"w": w, "r": r, "status": status, "data": data,
		}
	}

	testHandler := &testHandler{
		status: http.StatusOK, data: testdata,
	}
	handler := options.Handler(testHandler)

	w := httptest.NewRecorder()
	r := newTestRequest()

	handler.ServeHTTP(w, r)

	is.OK(aftercall)
	is.Equal(aftercall["w"], w)
	is.Equal(aftercall["r"], r)
	is.Equal(aftercall["status"], testHandler.status)
	is.Equal(aftercall["data"], testHandler.data)

	is.Equal(http.StatusOK, w.Code)
	var data map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &data))
	is.Equal(data, testdata)
	is.Equal(w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")

}
Esempio n. 7
0
func TestEncoderOnErr(t *testing.T) {
	is := is.New(t)

	var onErrCall map[string]interface{}
	options := &respond.Options{
		OnErr: func(err error) {
			onErrCall = map[string]interface{}{"err": err}
		},
	}
	encoderErr := errors.New("something went wrong while encoding")
	options.Encoder = func(w http.ResponseWriter, r *http.Request) respond.Encoder {
		return &testEncoder{
			err: encoderErr,
		}
	}

	testHandler := &testHandler{
		status: http.StatusOK, data: testdata,
	}
	handler := options.Handler(testHandler)

	w := httptest.NewRecorder()
	r := newTestRequest()

	handler.ServeHTTP(w, r)

	is.OK(onErrCall)
	is.Equal(onErrCall["err"], encoderErr)

}
Esempio n. 8
0
func TestIDLess(t *testing.T) {
	is := is.New(t)
	id1 := encode(strings.NewReader(`1`)) // c42yrSHMvUcscrQBssLhrRE28YpGUv9Gf95uH8KnwTiBv4odDbVqNnCYFs3xpsLrgVZfHebSaQQsvxgDGmw5CX1fVy
	id2 := encode(strings.NewReader(`2`)) // c42i2hTBA9Ej4nqEo9iUy3pJRRE53KAH9RwwMSWjmfaQN7LxCymVz1zL9hEjqeFYzxtxXz2wRK7CBtt71AFkRfHodu

	is.Equal(id1.Less(id2), false)
}
Esempio n. 9
0
func TestCompareIDs(t *testing.T) {
	is := is.New(t)

	for _, test := range []struct {
		Id_A *asset.ID
		Id_B *asset.ID
		Exp  int
	}{
		{

			Id_A: encode(strings.NewReader("Test string")),
			Id_B: encode(strings.NewReader("Test string")),
			Exp:  0,
		},
		{
			Id_A: encode(strings.NewReader("Test string A")),
			Id_B: encode(strings.NewReader("Test string B")),
			Exp:  -1,
		},
		{
			Id_A: encode(strings.NewReader("Test string B")),
			Id_B: encode(strings.NewReader("Test string A")),
			Exp:  1,
		},
		{
			Id_A: encode(strings.NewReader("Test string")),
			Id_B: nil,
			Exp:  -1,
		},
	} {
		is.Equal(test.Id_A.Cmp(test.Id_B), test.Exp)
	}

}
Esempio n. 10
0
func TestAddFreelancer(t *testing.T) {
	is := is.New(t)
	freelancerRepositoryMock := &FreelancerRepositoryMock{}
	freelancerContext := &ApplicationContext{
		FreelancerRepository: freelancerRepositoryMock,
	}

	r := getRequest(freelancerContext, ``)
	w := httptest.NewRecorder()

	user := &User{
		Model: Model{
			ID: 1,
		},
		FirstName: "first",
		LastName:  "last",
		Email:     "*****@*****.**",
	}

	AddFreelancer(user).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	is.Equal(freelancerRepositoryMock.AddFreelancerCall.Receives.Freelancer.User.Model.ID, 1)
	is.Equal(freelancerRepositoryMock.AddFreelancerCall.Receives.Freelancer.User.FirstName, "first")
	is.Equal(freelancerRepositoryMock.AddFreelancerCall.Receives.Freelancer.User.LastName, "last")
	is.Equal(freelancerRepositoryMock.AddFreelancerCall.Receives.Freelancer.User.Email, "*****@*****.**")
}
Esempio n. 11
0
func TestLogin(t *testing.T) {
	is := is.New(t)
	userRepositoryMock := &UserRepositoryMock{}
	userRepositoryMock.CheckCredentialsCall.Returns.UserType = "freelancer"
	userRepositoryMock.CheckCredentialsCall.Returns.User = User{
		Model: Model{
			ID: 1,
		},
		FirstName: "firstname",
		LastName:  "lastname",
		Password:  "******",
		Email:     "*****@*****.**",
	}
	userContext := &ApplicationContext{
		UserRepository: userRepositoryMock,
	}

	r := getRequest(userContext, `
		{
			"email": "*****@*****.**",
			"password": "******"
		}
	`)
	w := httptest.NewRecorder()

	Login(w, r)

	is.Equal(w.Code, http.StatusOK)
	var body map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(body["id"], 1)
	is.OK(body["token"])
	is.Equal(body["type"], "freelancer")
}
Esempio n. 12
0
func TestAddFreelancerReferenceByID(t *testing.T) {
	is := is.New(t)
	referenceRepositoryMock := &ReferenceRepositoryMock{}
	var freelancerContext = &ApplicationContext{
		ReferenceRepository: referenceRepositoryMock,
	}

	w := httptest.NewRecorder()
	r := getRequest(freelancerContext, ``)

	reference := Reference{
		Title:   "title",
		Content: "content",
		Media: Media{
			Image: "image",
			Video: "video",
		},
	}

	addFreelancerReferenceByID{3, &reference}.ServeHTTP(w, r)
	receivedReference := referenceRepositoryMock.AddReferenceCall.Receives.Reference

	is.Equal(receivedReference.Title, "title")
	is.Equal(receivedReference.Content, "content")
	is.Equal(receivedReference.Media.Image, "image")
	is.Equal(receivedReference.Media.Video, "video")
	is.Equal(referenceRepositoryMock.AddReferenceCall.Receives.ID, 3)
}
Esempio n. 13
0
func TestWithReference(t *testing.T) {
	is := is.New(t)
	referenceRepositoryMock := &ReferenceRepositoryMock{}
	var freelancerContext = &ApplicationContext{
		ReferenceRepository: referenceRepositoryMock,
	}

	w := httptest.NewRecorder()
	r := getRequest(freelancerContext, `
	{
		"content":      "content",
		"title":		"title",
		"media":		{
			"image":	"image",
			"video":	"video"
		}
	}`)

	next := func(reference *Reference) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			is.Equal(reference.Title, "title")
			is.Equal(reference.Content, "content")
			is.Equal(reference.Media.Image, "image")
			is.Equal(reference.Media.Video, "video")
		})
	}

	withReference{next}.ServeHTTP(w, r)
}
Esempio n. 14
0
func TestAddFreelancerReviewByID(t *testing.T) {
	is := is.New(t)
	freelancerRepositoryMock := &FreelancerRepositoryMock{}
	var freelancerContext = &ApplicationContext{
		FreelancerRepository: freelancerRepositoryMock,
	}

	w := httptest.NewRecorder()
	r := getRequest(freelancerContext, ``)

	review := Review{
		Title:    "title",
		ClientID: 2,
		Content:  "content",
		JobID:    4,
		Rating:   5.6,
	}

	addFreelancerReviewByID{3, &review}.ServeHTTP(w, r)
	receivedReview := freelancerRepositoryMock.AddReviewCall.Receives.Review

	is.Equal(receivedReview.Title, "title")
	is.Equal(receivedReview.Content, "content")
	is.Equal(receivedReview.Rating, 5.6)
	is.Equal(receivedReview.ClientID, 2)
	is.Equal(receivedReview.JobID, 4)
	is.Equal(freelancerRepositoryMock.AddReviewCall.Receives.ID, 3)
}
Esempio n. 15
0
func TestAddClient(t *testing.T) {
	is := is.New(t)
	clientRepositoryMock := &ClientRepositoryMock{}
	userContext := &ApplicationContext{
		ClientRepository: clientRepositoryMock,
	}

	r := getRequest(userContext, ``)
	w := httptest.NewRecorder()

	user := &User{
		Model: Model{
			ID: 1,
		},
	}

	AddClient(user).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	is.Equal(clientRepositoryMock.AddClientCall.Receives.Client.User.ID, 1)
	var body map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	userMap := body["user"].(map[string]interface{})
	is.Equal(userMap["id"], 1)
	is.Equal(body["type"], "client")
}
Esempio n. 16
0
func TestBytesToID(t *testing.T) {
	is := is.New(t)

	b := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58}
	id := asset.BytesToID(b)
	is.Equal(id.String(), "c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111121")
}
Esempio n. 17
0
func TestUpdateClientByID(t *testing.T) {
	is := is.New(t)
	clientRepositoryMock := &ClientRepositoryMock{}
	clientRepositoryMock.GetClientCall.Returns.Client = &Client{
		User: User{
			Model: Model{
				ID: 1,
			},
		},
	}
	userContext := &ApplicationContext{
		ClientRepository: clientRepositoryMock,
	}

	r := getRequest(userContext, `
    {
        "timezone": "UTC",
        "payment": "paypal",
        "industry": "feet cartoon drawings"
    }`)
	w := httptest.NewRecorder()

	UpdateClientByID(1).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	is.Equal(clientRepositoryMock.GetClientCall.Receives.ID, 1)
	is.Equal(clientRepositoryMock.UpdateClientCall.Receives.Client.Timezone, "UTC")
	is.Equal(clientRepositoryMock.UpdateClientCall.Receives.Client.Payment, "paypal")
	is.Equal(clientRepositoryMock.UpdateClientCall.Receives.Client.Industry, "feet cartoon drawings")
}
Esempio n. 18
0
func TestNILID(t *testing.T) {
	is := is.New(t)

	// ID of nothing constant
	nilid := asset.NIL_ID
	is.Equal(nilid.String(), "c459CSJESBh38BxDwwxNFKTXE4cC9HASGe3bhtN6z58GbwLqpCyRaKyZSvBAvTdF5NpSTPdUMH4hHRJ75geLsB1Sfs")
}
Esempio n. 19
0
func TestEncoder(t *testing.T) {
	is := is.New(t)

	options := &respond.Options{}
	var encodercall map[string]interface{}
	options.Encoder = func(w http.ResponseWriter, r *http.Request) respond.Encoder {
		encodercall = map[string]interface{}{
			"w": w, "r": r,
		}
		return &testEncoder{}
	}

	testHandler := &testHandler{
		status: http.StatusOK, data: testdata,
	}
	handler := options.Handler(testHandler)

	w := httptest.NewRecorder()
	r := newTestRequest()

	handler.ServeHTTP(w, r)

	is.OK(encodercall)
	is.Equal(encodercall["w"], w)
	is.Equal(encodercall["r"], r)

	is.Equal(http.StatusOK, w.Code)
	is.Equal(w.Body.String(), "testEncoder")
	is.Equal(w.HeaderMap.Get("Content-Type"), "test/encoder")

}
Esempio n. 20
0
func TestAppendOrder(t *testing.T) {
	is := is.New(t)
	byteData := [4][]byte{
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0d, 0x24},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0xfa, 0x28},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xac, 0xad, 0x10},
	}
	expectedIDs := [4]string{
		`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111121`,
		`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111211`,
		`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111112111`,
		`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111121111`,
	}
	for k := 0; k < 4; k++ {
		b := byteData[k]
		bignum := big.NewInt(0)
		bignum = bignum.SetBytes(b)
		id := asset.ID(*bignum)
		is.Equal(id.String(), expectedIDs[k])

		id2, err := asset.ParseID(expectedIDs[k])
		is.NoErr(err)
		bignum2 := big.Int(*id2)
		b = (&bignum2).Bytes()
		size := len(b)
		for size < 64 {
			b = append([]byte{0}, b...)
			size++
		}
		for i, bb := range b {
			is.Equal(bb, byteData[k][i])
		}
	}
}
Esempio n. 21
0
func TestMultipleWith(t *testing.T) {
	is := is.New(t)

	options := &respond.Options{}
	handler := options.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		respond.With(w, r, http.StatusInternalServerError, errors.New("borked"))
		respond.With(w, r, http.StatusOK, nil)
	}))

	w := httptest.NewRecorder()
	r := newTestRequest()

	is.PanicWith("respond: multiple responses", func() {
		handler.ServeHTTP(w, r)
	})

	options = &respond.Options{
		AllowMultiple: true,
	}
	handler = options.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		respond.With(w, r, http.StatusInternalServerError, errors.New("borked"))
		respond.With(w, r, http.StatusOK, nil)
	}))

	w = httptest.NewRecorder()
	r = newTestRequest()

	handler.ServeHTTP(w, r)

}
Esempio n. 22
0
func TestIdentify(t *testing.T) {
	is := is.New(t)

	id, err := asset.Identify(iotest.DataErrReader(strings.NewReader("foo")))
	is.NoErr(err)
	is.Equal(id.String(), "c45XyDwWmrPQwJPdULBhma6LGNaLghKtN7R9vLn2tFrepZJ9jJFSDzpCKei11EgA5r1veenBu3Q8qfvWeDuPc7fJK2")
}
Esempio n. 23
0
func TestIDofIDSlice(t *testing.T) {
	is := is.New(t)
	var b, s []byte
	for i := 0; i < 64; i++ {
		b = append(b, 0xFF)
		s = append(s, 0x00)
	}
	bigBig := big.NewInt(0)
	bigSmall := big.NewInt(0)
	bigBig = bigBig.SetBytes(b)
	bigSmall = bigSmall.SetBytes(s)
	bigID := asset.ID(*bigBig)
	smallID := asset.ID(*bigSmall)

	encoder := asset.NewIDEncoder()
	is.OK(encoder)
	_, err := io.Copy(encoder, strings.NewReader(`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111111c467RPWkcUr5dga8jgywjSup7CMoA9FNqkNjEFgAkEpF9vNktFnx77e2Js11EDL3BNu9MaKFUbacZRt1HYym4b8RNp`))
	is.NoErr(err)
	id := encoder.ID()

	var idSlice asset.IDSlice
	idSlice.Push(&bigID)
	idSlice.Push(&smallID)
	sliceID, err := idSlice.ID()
	is.NoErr(err)

	is.Equal(sliceID.String(), id.String())
}
Esempio n. 24
0
func TestWithUser(t *testing.T) {
	is := is.New(t)
	userContext := &ApplicationContext{}
	r := getRequest(userContext, `
		{
            "firstName": "firstname",
            "lastName": "lastname",
			"email": "*****@*****.**",
			"password": "******"
		}
	`)
	w := httptest.NewRecorder()
	withUser := WithUser{
		next: func(u *User) http.Handler {
			return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				is.Equal(u.FirstName, "firstname")
				is.Equal(u.LastName, "lastname")
				is.Equal(u.Email, "*****@*****.**")
				is.Equal(u.Password, "password")
			})
		},
	}

	withUser.ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
}
Esempio n. 25
0
func TestPatch_rmLink(t *testing.T) {
	is := is.New(t)
	s := NewShell(shellUrl)
	newRoot, err := s.Patch(examplesHash, "rm-link", "about")
	is.Nil(err)
	is.Equal(newRoot, "QmNjJ3naRhHCn14E895R1xtGmDgKQb8vnVvQar6RrnraC1")
}
Esempio n. 26
0
func TestOnceReset(t *testing.T) {
	is := is.New(t)
	var calls int
	var c resync.Once
	c.Do(func() {
		calls++
	})
	c.Do(func() {
		calls++
	})
	c.Do(func() {
		calls++
	})
	is.Equal(calls, 1)
	c.Reset()
	c.Do(func() {
		calls++
	})
	c.Do(func() {
		calls++
	})
	c.Do(func() {
		calls++
	})
	is.Equal(calls, 2)
}
Esempio n. 27
0
func TestProjectGetByID(t *testing.T) {
	projectRepositoryMock := ProjectRepositoryMock{}
	projectRepositoryMock.GetByIDCall.Returns.Project = Project{
		Model: Model{
			ID: 123456789,
		},
		Name:        "Name1",
		Description: "Description1",
		ClientID:    1,
		IsActive:    true,
	}
	var context = &ApplicationContext{
		ProjectRepository: &projectRepositoryMock,
	}
	is := is.New(t)
	w := httptest.NewRecorder()
	r := getRequest(context, "")

	GetProjectByID(0).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	var body Project
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(body.Model.ID, uint(123456789))
	is.Equal(body.Name, "Name1")
	is.Equal(body.Description, "Description1")
	is.Equal(body.IsActive, true)
}
Esempio n. 28
0
func TestPlaceJSON(t *testing.T) {
	is := is.New(t)

	var e meander.Place

	j := `{
   "geometry" : {
      "location" : {
         "lat" : -33.870775,
         "lng" : 151.199025
      }
   },
   "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/travel_agent-71.png",
   "id" : "21a0b251c9b8392186142c798263e289fe45b4aa",
   "name" : "Rhythmboat Cruises"
  }`

	is.NoErr(json.NewDecoder(strings.NewReader(j)).Decode(&e))

	is.Equal("Rhythmboat Cruises", e.Name)
	is.Equal("http://maps.gstatic.com/mapfiles/place_api/icons/travel_agent-71.png", e.Icon)
	is.Equal(-33.870775, e.Lat)
	is.Equal(151.199025, e.Lng)

}
Esempio n. 29
0
func TestCostRangeString(t *testing.T) {
	is := is.New(t)
	is.Equal("$$...$$$$", (&meander.CostRange{
		From: meander.Cost2,
		To:  meander.Cost4,
	}).String())
}
Esempio n. 30
0
func TestUpdateFreelancerHandler(t *testing.T) {
	is := is.New(t)
	freelancerRepositoryMock := &FreelancerRepositoryMock{}
	freelancerRepositoryMock.GetFreelancerCall.Returns.Freelancer = Freelancer{
		User: User{
			Model: Model{
				ID: 1,
			},
		},
	}
	var freelancerContext = &ApplicationContext{
		FreelancerRepository: freelancerRepositoryMock,
	}
	w := httptest.NewRecorder()
	r := getRequest(freelancerContext, ``)

	updateFreelancerHandler{1, &FreelancerUpdate{
		HourlyRateFrom: 11,
		HourlyRateTo:   22,
		IsAvailable:    true,
		Timezone:       "timez",
		Skills:         stringList{"one", "two"},
	}}.ServeHTTP(w, r)

	freelancer := freelancerRepositoryMock.UpdateFreelancerCall.Receives.Freelancer
	is.Equal(w.Code, http.StatusOK)
	is.Equal(freelancer.HourlyRateFrom, 11)
	is.Equal(freelancer.HourlyRateTo, 22)
	is.Equal(freelancer.IsAvailable, true)
	is.Equal(freelancer.Timezone, "timez")
	is.Equal(freelancer.Skills[0], "one")
	is.Equal(freelancer.Skills[1], "two")
}