Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions workspaces/announcements/.changeset/grumpy-lions-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage-community/plugin-search-backend-module-announcements': minor
---

Inactive announcements are no longer indexed for search. This fixes an issue where inactive announcements were still being returned in search results.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @backstage-community/plugin-search-backend-module-announcements

The announcements backend module for the search plugin.
The announcements backend module for the search plugin. Only active announcements are indexed.

## Installation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { rest } from 'msw';
import { mockServices } from '@backstage/backend-test-utils';

const mockAnnouncements = {
count: 3,
count: 4,
results: [
{
id: '1',
Expand All @@ -31,6 +31,7 @@ const mockAnnouncements = {
body: 'body',
excerpt: 'excerpt',
created_at: 'created_at',
active: true,
},
{
id: '2',
Expand All @@ -39,6 +40,7 @@ const mockAnnouncements = {
body: 'body',
excerpt: 'excerpt',
created_at: 'created_at',
active: true,
},
{
id: '3',
Expand All @@ -47,6 +49,16 @@ const mockAnnouncements = {
body: 'body',
excerpt: 'excerpt',
created_at: 'created_at',
active: true,
},
{
id: '4',
title: 'inactive title',
publisher: 'publisher4',
body: 'body',
excerpt: 'excerpt',
created_at: 'created_at',
active: false,
},
],
};
Expand Down Expand Up @@ -85,12 +97,17 @@ describe('AnnouncementCollatorFactory', () => {
expect(collator).toBeInstanceOf(Readable);
});

it('runs against announcements', async () => {
it('runs against announcements, skipping inactive ones', async () => {
collator = await factory.getCollator();
const pipeline = TestPipeline.fromCollator(collator);
const { documents } = await pipeline.execute();
expect(mockDiscovery.getBaseUrl).toHaveBeenCalledWith('announcements');
expect(documents).toHaveLength(mockAnnouncements.results.length);
expect(documents).toHaveLength(3);
expect(documents).toEqual(
expect.not.arrayContaining([
expect.objectContaining({ location: '/announcements/view/4' }),
]),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export class AnnouncementCollatorFactory implements DocumentCollatorFactory {
this.logger.debug(`got ${results.length} announcements`);

for (const result of results) {
if (!result.active) {
continue;
}

yield this.getDocumentInfo(result);
}
}
Expand Down
Loading