diff --git a/internal/infrastructure/mongo/asset_test.go b/internal/infrastructure/mongo/asset_test.go index 135683df..64fa8f26 100644 --- a/internal/infrastructure/mongo/asset_test.go +++ b/internal/infrastructure/mongo/asset_test.go @@ -7,6 +7,7 @@ import ( "github.com/reearth/reearth-backend/pkg/asset" "github.com/reearth/reearth-backend/pkg/id" + "github.com/reearth/reearth-backend/pkg/rerror" "github.com/stretchr/testify/assert" ) @@ -64,3 +65,55 @@ func TestFindByID(t *testing.T) { }) } } + +func TestRemove(t *testing.T) { + tests := []struct { + Name string + Expected struct { + Name string + Asset *asset.Asset + } + }{ + { + Expected: struct { + Name string + Asset *asset.Asset + }{ + Asset: asset.New(). + NewID(). + CreatedAt(time.Now()). + Team(id.NewTeamID()). + Name("name"). + Size(10). + URL("hxxps://https://reearth.io/"). + ContentType("json"). + MustBuild(), + }, + }, + } + + initDB := connect(t) + + for _, tc := range tests { + tc := tc + + t.Run(tc.Name, func(t *testing.T) { + t.Parallel() + + client, dropDB := initDB() + defer dropDB() + + repo := NewAsset(client) + ctx := context.Background() + err := repo.Save(ctx, tc.Expected.Asset) + assert.NoError(t, err) + + err = repo.Remove(ctx, tc.Expected.Asset.ID()) + assert.NoError(t, err) + + got, err := repo.FindByID(ctx, tc.Expected.Asset.ID()) + assert.Equal(t, err, rerror.ErrNotFound) + assert.Nil(t, got) + }) + } +}