diff --git a/pkg/items/dummy.go b/pkg/items/dummy.go index 082f5c1f3760a7046332ce0b5eb8fe569a90ed35..a31b47c7095e29471321c90ef9b5307850147b73 100644 --- a/pkg/items/dummy.go +++ b/pkg/items/dummy.go @@ -31,3 +31,12 @@ func (d *DummyWithOptions) Find(_ context.Context, _, _, _ string, _ *Filter, op } return make([]*Item, limit), d.Total, nil } + +func (d *DummyWithOptions) FindPublished(_ context.Context, _, _, _ string, _ *Filter, opts ...*FindPublishedOptions) ([]*Item, int, error) { + fo := MergeFindPublishedOptions(opts...) + limit := fo.Limit + if limit == 0 { + limit = fo.PageSize + } + return make([]*Item, limit), d.Total, nil +} diff --git a/pkg/items/pagination_test.go b/pkg/items/pagination_test.go index c0985d33a6288ea11b69f809439729d4258e3973..6f36fc6d1cd7c4f9568cd68df1f81d2b7303ddcc 100644 --- a/pkg/items/pagination_test.go +++ b/pkg/items/pagination_test.go @@ -34,19 +34,14 @@ func TestBatchProcessor(t *testing.T) { assert.Equal(t, 0, counter) }) - t.Run("Success", func(t *testing.T) { + t.Run("With FindOptions", func(t *testing.T) { itemssvc := &DummyWithOptions{Items: nil, Total: 1000} b := &BatchProcessor{ Items: itemssvc, SpaceID: "sp", EnvID: environments.DefaultEnvironment, CollectionID: "col", - FindOptions: &FindOptions{ - Regular: true, - Hidden: true, - Templates: true, - FindOptions: *options.New(0, 25), - }, + FindOptions: &FindOptions{FindOptions: *options.New(0, 25)}, } var counter int @@ -54,4 +49,20 @@ func TestBatchProcessor(t *testing.T) { require.NoError(t, err) assert.Equal(t, 1000/25, counter) }) + + t.Run("With FindPublishedOptions", func(t *testing.T) { + itemssvc := &DummyWithOptions{Items: nil, Total: 60} + b := &BatchProcessor{ + Items: itemssvc, + SpaceID: "sp", + EnvID: environments.DefaultEnvironment, + CollectionID: "col", + FindPublishedOptions: &FindPublishedOptions{FindOptions: *options.New(0, 20)}, + } + + var counter int + _, err := b.Do(context.Background(), func(batch []*Item) error { counter++; return nil }) + require.NoError(t, err) + assert.Equal(t, 60/20, counter) + }) }