Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix createTagItem mutation (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
mimoham24 authored May 13, 2022
1 parent 89009ba commit b98406c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/usecase/interactor/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (i *Tag) CreateItem(ctx context.Context, inp interfaces.CreateTagItemParam,
}

if parent != nil {
parent.Tags().Add(item.ID())
parent.AddTag(item.ID())
}

itemt := tag.Tag(item)
Expand Down
7 changes: 7 additions & 0 deletions pkg/tag/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ func (g *Group) RemoveTag(ids ...ID) {
}
g.tags = g.tags.Delete(ids...)
}

func (g *Group) AddTag(ids ...ID) {
if g == nil {
return
}
g.tags = g.tags.Add(ids...)
}
53 changes: 53 additions & 0 deletions pkg/tag/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tag
import (
"testing"

"github.com/reearth/reearth-backend/pkg/id"

"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -107,3 +109,54 @@ func TestGroupBuilder_Build(t *testing.T) {
})
}
}

func TestGroup_AddTag(t *testing.T) {
sid := id.NewSceneID()
tid := id.NewTagID()
tests := []struct {
name string
tag *Group
input IDList
expected IDList
}{
{
name: "should add a tag",
tag: NewGroup().NewID().Scene(sid).Label("foo").MustBuild(),
input: IDList{tid},
expected: IDList{tid},
},
}
for _, tc := range tests {
t.Run(tc.name, func(tt *testing.T) {
tt.Parallel()
tc.tag.AddTag(tc.input...)
assert.Equal(tt, tc.tag.tags, tc.expected)
})
}
}

func TestGroup_RemoveTag(t *testing.T) {
sid := id.NewSceneID()
tid := id.NewTagID()
tid2 := id.NewTagID()
tests := []struct {
name string
tag *Group
input IDList
expected IDList
}{
{
name: "should remove a tag",
tag: NewGroup().NewID().Scene(sid).Label("foo").Tags(IDList{tid, tid2}).MustBuild(),
input: IDList{tid2},
expected: IDList{tid},
},
}
for _, tc := range tests {
t.Run(tc.name, func(tt *testing.T) {
tt.Parallel()
tc.tag.RemoveTag(tc.input...)
assert.Equal(tt, tc.tag.tags, tc.expected)
})
}
}

0 comments on commit b98406c

Please sign in to comment.