From b6e6a2c36ec23958f288da05eef5b0da1369b2e8 Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Tue, 5 Nov 2024 14:42:36 +0000 Subject: [PATCH] test: add for issue indexer sort by score --- .../indexer/issues/internal/tests/tests.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/indexer/issues/internal/tests/tests.go b/modules/indexer/issues/internal/tests/tests.go index a93b2913e9..e8e6a4e7d1 100644 --- a/modules/indexer/issues/internal/tests/tests.go +++ b/modules/indexer/issues/internal/tests/tests.go @@ -126,6 +126,7 @@ var cases = []*testIndexerCase{ }, SearchOptions: &internal.SearchOptions{ Keyword: "hello", + SortBy: internal.SortByCreatedDesc, }, ExpectedIDs: []int64{1002, 1001, 1000}, ExpectedTotal: 3, @@ -139,6 +140,7 @@ var cases = []*testIndexerCase{ }, SearchOptions: &internal.SearchOptions{ Keyword: "hello world", + SortBy: internal.SortByCreatedDesc, IsFuzzyKeyword: true, }, ExpectedIDs: []int64{1002, 1001, 1000}, @@ -157,6 +159,7 @@ var cases = []*testIndexerCase{ }, SearchOptions: &internal.SearchOptions{ Keyword: "hello", + SortBy: internal.SortByCreatedDesc, RepoIDs: []int64{1, 4}, }, ExpectedIDs: []int64{1006, 1002, 1001}, @@ -175,6 +178,7 @@ var cases = []*testIndexerCase{ }, SearchOptions: &internal.SearchOptions{ Keyword: "hello", + SortBy: internal.SortByCreatedDesc, RepoIDs: []int64{1, 4}, AllPublic: true, }, @@ -597,6 +601,22 @@ var cases = []*testIndexerCase{ } }, }, + { + Name: "SortByScore", + SearchOptions: &internal.SearchOptions{ + Paginator: &db.ListOptionsAll, + SortBy: internal.SortByScore, + }, + Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) { + assert.Equal(t, len(data), len(result.Hits)) + assert.Equal(t, len(data), int(result.Total)) + for i, v := range result.Hits { + if i < len(result.Hits)-1 { + assert.GreaterOrEqual(t, v.Score, result.Hits[i+1].Score) + } + } + }, + }, { Name: "SortByCreatedAsc", SearchOptions: &internal.SearchOptions{