Exemplo n.º 1
0
func TestUnfollowProject(t *testing.T) {
	project, _ := nerdz.NewProject(2)

	t.Log("I want to unfollow a useless project whose name is: ", project.Name)
	oldNumFollowers := len(project.Followers())

	if err := me.Unfollow(project); err != nil {
		t.Error(err)
	}

	if len(project.Followers()) != oldNumFollowers-1 {
		t.Error("The follower isn't removed from the project's followers!")
	}
}
Exemplo n.º 2
0
func TestFollowProject(t *testing.T) {
	project, _ := nerdz.NewProject(1)

	t.Log("I want to follow a fantastic project whose name is: ", project.Name)
	oldNumFollowers := len(project.NumericFollowers())

	if err := me.Follow(project); err != nil {
		t.Log("The user should correctly follow the project but: ")
		t.Error(err)
	}

	if len(project.NumericFollowers()) != oldNumFollowers+1 {
		t.Log("There isn't a new follower for the project!")
		t.Error("No new follower")
	}
}
Exemplo n.º 3
0
// Project extract "id" from the url parameter, parse it and returns
// the Project if the "me" (in the context) user is allowed to see it.
// Otherwise returns an error
func Project(projectID string, c echo.Context) (*nerdz.Project, error) {
	var id uint64
	var e error
	if id, e = strconv.ParseUint(c.Param(projectID), 10, 64); e != nil {
		c.JSON(http.StatusBadRequest, &Response{
			HumanMessage: "Invalid project identifier specified",
			Message:      e.Error(),
			Status:       http.StatusBadRequest,
			Success:      false,
		})
		return nil, e
	}

	var project *nerdz.Project
	if project, e = nerdz.NewProject(id); e != nil {
		c.JSON(http.StatusBadRequest, &Response{
			HumanMessage: "Project does not exists",
			Message:      e.Error(),
			Status:       http.StatusBadRequest,
			Success:      false,
		})
		return nil, e
	}

	me := c.Get("me").(*nerdz.User)
	if !me.CanSee(project) {
		message := "You can't see the required project"
		c.JSON(http.StatusUnauthorized, &Response{
			HumanMessage: message,
			Message:      message,
			Status:       http.StatusUnauthorized,
			Success:      false,
		})
		return nil, errors.New(message)
	}
	return project, nil
}
Exemplo n.º 4
0
func init() {
	prj, err = nerdz.NewProject(1)
	if err != nil {
		panic(fmt.Sprintf("No error should happen when create existing user, but got: %+v", err))
	}
}