Skip to content

Commit

Permalink
add test to tournament, still failing...
Browse files Browse the repository at this point in the history
involves #308
  • Loading branch information
santiaago committed Mar 5, 2014
1 parent ca05212 commit 7331536
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 36 deletions.
12 changes: 6 additions & 6 deletions controllers/teams/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ func DestroyJson(w http.ResponseWriter, r *http.Request, u *mdl.User) error {
}
// delete the team
team.Destroy(c)
// publish new activity
actor := mdl.ActivityEntity{ID: u.Id, Type: "user", DisplayName: u.Username}
object := mdl.ActivityEntity{ID: team.Id, Type: "team", DisplayName: team.Name}
target := mdl.ActivityEntity{}
mdl.Publish(c, "team", "deleted team", actor, object, target, u.Id)

// publish new activity
actor := mdl.ActivityEntity{ID: u.Id, Type: "user", DisplayName: u.Username}
object := mdl.ActivityEntity{ID: team.Id, Type: "team", DisplayName: team.Name}
target := mdl.ActivityEntity{}
mdl.Publish(c, "team", "deleted team", actor, object, target, u.Id)

// return destroyed status
return templateshlp.RenderJson(w, c, "team has been destroyed")
Expand Down
12 changes: 6 additions & 6 deletions controllers/tournaments/tournaments.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ func DestroyJson(w http.ResponseWriter, r *http.Request, u *mdl.User) error {
}
// delete the tournament
tournament.Destroy(c)
// publish new activity
actor := mdl.ActivityEntity{ID: u.Id, Type: "user", DisplayName: u.Username}
object := mdl.ActivityEntity{ID: tournament.Id, Type: "tournament", DisplayName: tournament.Name}
target := mdl.ActivityEntity{}
mdl.Publish(c, "tournament", "deleted tournament", actor, object, target, u.Id)

// publish new activity
actor := mdl.ActivityEntity{ID: u.Id, Type: "user", DisplayName: u.Username}
object := mdl.ActivityEntity{ID: tournament.Id, Type: "tournament", DisplayName: tournament.Name}
target := mdl.ActivityEntity{}
mdl.Publish(c, "tournament", "deleted tournament", actor, object, target, u.Id)

// return destroyed status
return templateshlp.RenderJson(w, c, "tournament has been destroyed")
Expand Down
34 changes: 17 additions & 17 deletions models/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ func TestPublishActivity(t *testing.T) {
log.Infof(c, "Test Publish Activity")

tests := []struct {
name string
activity Activity
want *Activity
name string
activity Activity
want *Activity
}{
{
name: "Simple publish",
activity: Activity{
Type: "Team",
Verb: "created",
Actor: ActivityEntity { 1, "user", "John Smith"},
Object: ActivityEntity { 10, "team", "TeamFoo"},
Target: ActivityEntity { 100, "foo", "TargetFoo"},
Published: time.Now(),
UserID: 1,
Type: "Team",
Verb: "created",
Actor: ActivityEntity{1, "user", "John Smith"},
Object: ActivityEntity{10, "team", "TeamFoo"},
Target: ActivityEntity{100, "foo", "TargetFoo"},
Published: time.Now(),
UserID: 1,
},
want: &Activity{
Type: "Team",
Verb: "created",
Actor: ActivityEntity { 1, "user", "John Smith"},
Object: ActivityEntity { 10, "team", "TeamFoo"},
Target: ActivityEntity { 100, "foo", "TargetFoo"},
Published: time.Now(),
UserID: 1,
Type: "Team",
Verb: "created",
Actor: ActivityEntity{1, "user", "John Smith"},
Object: ActivityEntity{10, "team", "TeamFoo"},
Target: ActivityEntity{100, "foo", "TargetFoo"},
Published: time.Now(),
UserID: 1,
},
},
}
Expand Down
121 changes: 114 additions & 7 deletions models/tournament_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,136 @@ func TestDestroyTournament(t *testing.T) {
test := struct {
name string
tournament Tournament
want *Tournament
want *Tournament
}{
name: "destroy tournament",
tournament:Tournament{
tournament: Tournament{
Name: "Foo",
Description: "Foo description",
Start: time.Now(),
End: time.Now(),
AdminId: int64(0),
},
want:nil,
want: nil,
}

// create tournament
tournament, _ := CreateTournament(c, test.tournament.Name, test.tournament.Description, test.tournament.Start, test.tournament.End, test.tournament.AdminId)

// destory it
if got := tournament.Destroy(c); got != nil{
if got := tournament.Destroy(c); got != nil {
t.Errorf("TestDestroyTournament(%q): got %v wanted %v", test.name, got, test.want)
}

// make a query on datastore to be sure it is not there.
if got, err1 := TournamentById(c, tournament.Id); err1 == nil{
if got, err1 := TournamentById(c, tournament.Id); err1 == nil {
t.Errorf("TestDestroyTournament(%q): got %v wanted %v", test.name, got, test.want)
}
}

func TestFindTournaments(t *testing.T) {

c, err := aetest.NewContext(nil)
if err != nil {
t.Fatal(err)
}
defer c.Close()

log.Infof(c, "Test Find Tournament")

tournaments := []Tournament{
Tournament{
Name: "bar",
Description: "Foo description",
Start: time.Now(),
End: time.Now(),
AdminId: int64(0),
},
Tournament{
Name: "foobar",
Description: "foo description",
Start: time.Now(),
End: time.Now(),
AdminId: int64(0),
},
Tournament{
Name: "foobarfoo",
Description: "Foo description",
Start: time.Now(),
End: time.Now(),
AdminId: int64(0),
},
}

tests := []struct {
name string
tournaments []Tournament
queries []string
want struct {
Len int
Names []string
}
}{
{
name: "find tournaments in empty datastore",
tournaments: make([]Tournament, 0),
queries: []string{"foo"},
want: struct {
Len int
Names []string
}{
Len: int(0),
Names: make([]string, 0),
},
},
{
name: "find tournaments in full datastore",
tournaments: tournaments,
queries: []string{"bar", "foobar", "foobarfoo"},
want: struct {
Len int
Names []string
}{
Len: int(1),
Names: []string{"bar", "foobar", "foobarfoo"},
},
},
}
// create tournaments
for _, test := range tests {
for i, _ := range test.tournaments {
if _, err := CreateTournament(c, test.tournaments[i].Name, test.tournaments[i].Description, test.tournaments[i].Start, test.tournaments[i].End, test.tournaments[i].AdminId); err != nil {
t.Errorf("TestFindTournaments(%q): error creating tournaments", test.name)

}
}
}

// search tournaments
for _, test := range tests {
for _, query := range test.queries {
got := FindTournaments(c, "KeyName", query)
if test.want.Len != len(got) {
t.Errorf("TestFindTournaments(%q): got array of %v wanted %v: query:%v t:%v", test.name, len(got), test.want.Len, query, got)
}
for _, tour := range got {
var a arrayOfStrings
a = test.want.Names
if !a.Contains(tour.Name) {
t.Errorf("TestFindTournaments(%q): name not found. got %v wanted among %v", test.name, tour.Name, test.want.Names)
}
}
}
}
}

type arrayOfStrings []string

func (a arrayOfStrings) Contains(s string) bool {
for _, e := range a {
if e == s {
return true
}
}
return false
}

0 comments on commit 7331536

Please sign in to comment.