Skip to content

Commit 498a3a0

Browse files
authored
chore: test for notices that share the same issue number (#1001)
Just to make sure it works and keeps working --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent f17ac7a commit 498a3a0

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

packages/@aws-cdk/toolkit-lib/test/api/notices.test.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,101 @@ describe(Notices, () => {
752752
jest.restoreAllMocks();
753753
});
754754

755+
describe('filter', () => {
756+
test('can acknowledge two notices that share the same issue number', async () => {
757+
const data = [
758+
{
759+
title: 'notice1',
760+
issueNumber: 12345,
761+
overview: 'notice1-overview',
762+
components: [
763+
{
764+
name: 'cli',
765+
version: '>=2.0.0 <2.1100.0',
766+
},
767+
],
768+
schemaVersion: '1',
769+
},
770+
{
771+
title: 'notice2',
772+
issueNumber: 12345,
773+
overview: 'notice2-overview',
774+
components: [
775+
{
776+
name: 'cli',
777+
version: '>=2.0.0 <2.1100.0',
778+
},
779+
],
780+
schemaVersion: '1',
781+
},
782+
];
783+
784+
const notices = Notices.create({
785+
context: new Context({
786+
bag: new Settings({ 'acknowledged-issue-numbers': [12345] }),
787+
}),
788+
ioHost,
789+
cliVersion: '2.1034.0',
790+
});
791+
await notices.refresh({ dataSource: { fetch: async () => data } });
792+
const filtered = await notices.filter();
793+
794+
expect(filtered).toEqual([]);
795+
});
796+
797+
test('filters the correct notice when two notices share the same issue number', async () => {
798+
const data = [
799+
{
800+
title: 'notice1',
801+
issueNumber: 12345,
802+
overview: 'notice1-overview',
803+
components: [
804+
{
805+
name: 'cli',
806+
version: '>=2.0.0 <2.1100.0',
807+
},
808+
],
809+
schemaVersion: '1',
810+
},
811+
{
812+
title: 'notice2',
813+
issueNumber: 12345,
814+
overview: 'notice2-overview',
815+
components: [
816+
{
817+
name: 'cli',
818+
version: '^2.1100.0',
819+
},
820+
],
821+
schemaVersion: '1',
822+
},
823+
];
824+
825+
async function filterNotices(_cliVersion: string) {
826+
const notices = Notices.create({ context: new Context(), ioHost, cliVersion: _cliVersion });
827+
await notices.refresh({ dataSource: { fetch: async () => data } });
828+
return notices.filter();
829+
}
830+
831+
const testCases = [
832+
{ version: '2.1034.0', expectedCount: 1, expectedTitles: ['notice1'] },
833+
{ version: '2.1100.0', expectedCount: 1, expectedTitles: ['notice2'] },
834+
{ version: '2.1100.1', expectedCount: 1, expectedTitles: ['notice2'] },
835+
{ version: '1.1034.0', expectedCount: 0, expectedTitles: undefined },
836+
];
837+
838+
for (const { version, expectedCount, expectedTitles } of testCases) {
839+
const filtered = await filterNotices(version);
840+
expect(filtered.length).toEqual(expectedCount);
841+
842+
if (expectedTitles) {
843+
const actualTitles = new Set(filtered.map(n => n.notice.title));
844+
expect(actualTitles).toEqual(new Set(expectedTitles));
845+
}
846+
}
847+
});
848+
});
849+
755850
describe('addBootstrapVersion', () => {
756851
test('can add multiple values', async () => {
757852
const notices = Notices.create({ context: new Context(), ioHost, cliVersion });

0 commit comments

Comments
 (0)