Skip to content

Commit

Permalink
Cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Tucker committed Jan 2, 2019
1 parent a117755 commit 0174e5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
13 changes: 7 additions & 6 deletions wantslistutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ func (s *Server) processWantLists(ctx context.Context) {
if err == nil {
toUpdateToWanted.Status = pb.WantListEntry_WANTED
}

}

for _, v := range list.Wants {
if v.Status == pb.WantListEntry_WANTED {
_, err := s.rcBridge.getRecord(ctx, v.Want)
if err == nil {
v.Status = pb.WantListEntry_IN_COLLECTION
if toUpdateToWanted == nil {
for _, v := range list.Wants {
if v.Status == pb.WantListEntry_WANTED {
_, err := s.rcBridge.getRecord(ctx, v.Want)
if err == nil {
v.Status = pb.WantListEntry_IN_COLLECTION
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions wantslistutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func InitTestServer() *Server {
s.SkipLog = true
s.GoServer.KSclient = *keystoreclient.GetTestClient(".test")
s.wantBridge = &testWantBridge{}
s.rcBridge = &testRcBridge{}
return s
}

Expand Down Expand Up @@ -82,3 +83,26 @@ func TestFirstEntryUpdated(t *testing.T) {
t.Errorf("Want has not been updated following first complete")
}
}

func TestFirstEntryUpdatedToCollection(t *testing.T) {
s := InitTestServer()
s.AddWantList(context.Background(), &pb.AddWantListRequest{
Add: &pb.WantList{
Name: "TestList",
Wants: []*pb.WantListEntry{
&pb.WantListEntry{Index: 1, Want: 123, Status: pb.WantListEntry_WANTED},
&pb.WantListEntry{Index: 2, Want: 125},
},
},
})

s.processWantLists(context.Background())

lists, err := s.GetWantList(context.Background(), &pb.GetWantListRequest{})
if err != nil {
t.Fatalf("Error getting wants: %v", err)
}
if lists.Lists[0].Wants[0].Status != pb.WantListEntry_IN_COLLECTION {
t.Errorf("Want has not been updated following first complete: %v", lists.Lists[0].Wants[0])
}
}

0 comments on commit 0174e5a

Please sign in to comment.