Skip to content

Commit 2fe98c2

Browse files
committed
mid work
1 parent 6300d1f commit 2fe98c2

File tree

1 file changed

+96
-92
lines changed

1 file changed

+96
-92
lines changed

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

Lines changed: 96 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -609,98 +609,6 @@ describe(WebsiteNoticeDataSource, () => {
609609
await expect(result).rejects.toThrow(/DNS resolution failed/);
610610
});
611611

612-
test('can acknowledge two notices that share the same issue number', async () => {
613-
614-
const data = [
615-
{
616-
title: 'notice1',
617-
issueNumber: 12345,
618-
overview: 'notice1-overview',
619-
components: [
620-
{
621-
name: 'cli',
622-
version: '>=2.0.0 <2.1100.0',
623-
},
624-
],
625-
schemaVersion: '1',
626-
},
627-
{
628-
title: 'notice2',
629-
issueNumber: 12345,
630-
overview: 'notice2-overview',
631-
components: [
632-
{
633-
name: 'cli',
634-
version: '>=2.0.0 <2.1100.0',
635-
},
636-
],
637-
schemaVersion: '1',
638-
},
639-
];
640-
641-
const notices = Notices.create({
642-
context: new Context({
643-
bag: new Settings({ 'acknowledged-issue-numbers': [12345] }),
644-
}), ioHost, cliVersion: '2.1034.0'
645-
});
646-
await notices.refresh({ force: true, dataSource: { fetch: async () => data } });
647-
const filtered = await notices.filter();
648-
649-
expect(filtered).toEqual([]);
650-
651-
})
652-
653-
test('filters the correct notice when two notices share the same issue number', async () => {
654-
655-
const data = [
656-
{
657-
title: 'notice1',
658-
issueNumber: 12345,
659-
overview: 'notice1-overview',
660-
components: [
661-
{
662-
name: 'cli',
663-
version: '>=2.0.0 <2.1100.0',
664-
},
665-
],
666-
schemaVersion: '1',
667-
},
668-
{
669-
title: 'notice2',
670-
issueNumber: 12345,
671-
overview: 'notice2-overview',
672-
components: [
673-
{
674-
name: 'cli',
675-
version: '^2.1100.0',
676-
},
677-
],
678-
schemaVersion: '1',
679-
},
680-
];
681-
682-
async function filterNotices(cliVersion: string) {
683-
const notices = Notices.create({ context: new Context(), ioHost, cliVersion });
684-
await notices.refresh({ force: true, dataSource: { fetch: async () => data } });
685-
return await notices.filter();
686-
}
687-
688-
const testCases = [
689-
{ version: '2.1034.0', expectedCount: 1, expectedTitle: 'notice1' },
690-
{ version: '2.1100.0', expectedCount: 1, expectedTitle: 'notice2' },
691-
{ version: '2.1100.1', expectedCount: 1, expectedTitle: 'notice2' },
692-
{ version: '1.1034.0', expectedCount: 0, expectedTitle: undefined },
693-
];
694-
695-
for (const { version, expectedCount, expectedTitle } of testCases) {
696-
const filtered = await filterNotices(version);
697-
expect(filtered.length).toEqual(expectedCount);
698-
if (expectedTitle) {
699-
expect(filtered[0].notice.title).toEqual(expectedTitle);
700-
}
701-
}
702-
})
703-
704612
test('returns appropriate error when the connection stays idle for too long', async () => {
705613
nock('https://cli.cdk.dev-tools.aws.dev')
706614
.get('/notices.json')
@@ -844,6 +752,102 @@ describe(Notices, () => {
844752
jest.restoreAllMocks();
845753
});
846754

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

0 commit comments

Comments
 (0)