Skip to content

Commit 524398a

Browse files
committed
feat: prefetch platinum sponsors
1 parent e453a17 commit 524398a

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

scripts/generateSponsorsFiles.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const BACKERS_FILE_PATH = '.vitepress/data/sponsors/backers.ts';
1919
const BRONZES_FILE_PATH = '.vitepress/data/sponsors/bronzes.ts';
2020
const SILVERS_FILE_PATH = '.vitepress/data/sponsors/silvers.ts';
2121
const GOLDS_FILE_PATH = '.vitepress/data/sponsors/golds.ts';
22+
const PLATINUMS_FILE_PATH = '.vitepress/data/sponsors/platinumSponsors.ts';
2223
const OPEN_COLLECTIVE_API_URL = 'https://opencollective.com/seed4j/members.json';
2324
const IMAGE_EXTENSION = '.png';
2425

@@ -42,12 +43,18 @@ const GOLDS_FILE_TEMPLATE = `import type { Sponsor } from './sponsors';
4243
export const gold: Sponsor[] = [{{CONTENT}}];
4344
`;
4445

46+
const PLATINUM_SPONSORS_FILE_TEMPLATE = `import type { Sponsor } from './sponsors';
47+
48+
export const platinum: Sponsor[] = [{{CONTENT}}];
49+
`;
50+
4551
export async function generate(): Promise<void> {
4652
return fetchSeed4jMembers().then(async seed4jMembers =>
4753
prefetchSponsors(seed4jMembers, 'backer', BACKERS_FILE_PATH, BACKERS_FILE_TEMPLATE)
4854
.then(() => prefetchSponsors(seed4jMembers, 'Bronze sponsor', BRONZES_FILE_PATH, BRONZES_FILE_TEMPLATE))
4955
.then(() => prefetchSponsors(seed4jMembers, 'Silver sponsor', SILVERS_FILE_PATH, SILVERS_FILE_TEMPLATE))
50-
.then(() => prefetchSponsors(seed4jMembers, 'Gold sponsor', GOLDS_FILE_PATH, GOLDS_FILE_TEMPLATE)),
56+
.then(() => prefetchSponsors(seed4jMembers, 'Gold sponsor', GOLDS_FILE_PATH, GOLDS_FILE_TEMPLATE))
57+
.then(() => prefetchSponsors(seed4jMembers, 'Platinum sponsor', PLATINUMS_FILE_PATH, PLATINUM_SPONSORS_FILE_TEMPLATE)),
5158
);
5259
}
5360

test/scripts/generateSponsorsFiles.spec.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ describe('Generate sponsors data', () => {
6767
return `import type { Sponsor } from './sponsors';\n\nexport const gold: Sponsor[] = [${golds.length > 0 ? '\n' + goldsArray + ',\n' : ''}];\n`;
6868
};
6969

70+
const createExpectedPlatinumSponsorsContent = (platinumSponsors: Array<{ name: string; url: string; img: string }>) => {
71+
const platinumSponsorsArray = platinumSponsors
72+
.map(
73+
platinumSponsor => ` {
74+
name: '${platinumSponsor.name}',
75+
url: '${platinumSponsor.url}',
76+
img: '${platinumSponsor.img}',
77+
}`,
78+
)
79+
.join(',\n');
80+
81+
return `import type { Sponsor } from './sponsors';\n\nexport const platinum: Sponsor[] = [${platinumSponsors.length > 0 ? '\n' + platinumSponsorsArray + ',\n' : ''}];\n`;
82+
};
83+
7084
it.each([
7185
{
7286
sponsorType: 'backers',
@@ -121,6 +135,18 @@ describe('Generate sponsors data', () => {
121135
},
122136
],
123137
},
138+
{
139+
sponsorType: 'platinum sponsors',
140+
filePath: '.vitepress/data/sponsors/platinumSponsors.ts',
141+
contentGenerator: createExpectedPlatinumSponsorsContent,
142+
expectedData: [
143+
{
144+
name: 'Kaelan Ryder',
145+
url: 'https://opencollective.com/kaelan-ryder',
146+
img: '/sponsors/kaelan-ryder.png',
147+
},
148+
],
149+
},
124150
])('should generate $sponsorType data from open collective api', async ({ filePath, contentGenerator, expectedData }) => {
125151
setupMocks();
126152
(global.fetch as any).mockImplementation(createMockFetchForMembers(seed4jMembersJson));
@@ -156,6 +182,12 @@ describe('Generate sponsors data', () => {
156182
filePath: '.vitepress/data/sponsors/golds.ts',
157183
contentGenerator: createExpectedGoldsContent,
158184
},
185+
{
186+
tierToFilter: 'Platinum sponsor',
187+
sponsorType: 'platinum sponsors',
188+
filePath: '.vitepress/data/sponsors/platinumSponsors.ts',
189+
contentGenerator: createExpectedPlatinumSponsorsContent,
190+
}
159191
])(
160192
'should generate empty $sponsorType when does not have sponsors for its specific tier',
161193
async ({ tierToFilter, filePath, contentGenerator }) => {
@@ -200,6 +232,12 @@ describe('Generate sponsors data', () => {
200232
filePath: '.vitepress/data/sponsors/golds.ts',
201233
contentGenerator: createExpectedGoldsContent,
202234
},
235+
{
236+
sponsorType: 'platinum sponsors',
237+
tier: 'Platinum sponsor',
238+
filePath: '.vitepress/data/sponsors/platinumSponsors.ts',
239+
contentGenerator: createExpectedPlatinumSponsorsContent,
240+
}
203241
])(
204242
'should give preference to use the user website instead of the open collective profile url for $sponsorType',
205243
async ({ tier, filePath, contentGenerator }) => {
@@ -274,6 +312,12 @@ describe('Generate sponsors data', () => {
274312
filePath: '.vitepress/data/sponsors/golds.ts',
275313
contentGenerator: createExpectedGoldsContent,
276314
},
315+
{
316+
sponsorType: 'platinum sponsors',
317+
tier: 'Platinum sponsor',
318+
filePath: '.vitepress/data/sponsors/platinumSponsors.ts',
319+
contentGenerator: createExpectedPlatinumSponsorsContent,
320+
}
277321
])('should download image from open collective api for $sponsorType', async ({ tier, filePath, contentGenerator }) => {
278322
setupMocks();
279323
const seed4jMembersWithImageJson: Seed4jMember[] = [
@@ -324,6 +368,7 @@ describe('Generate sponsors data', () => {
324368
{ sponsorType: 'bronzes', tier: 'Bronze sponsor' },
325369
{ sponsorType: 'silvers', tier: 'Silver sponsor' },
326370
{ sponsorType: 'golds', tier: 'Gold sponsor' },
371+
{ sponsorType: 'platinum sponsors', tier: 'Platinum sponsor' },
327372
])('should use the seed4j logo as a placeholder for open collective members without an image for $sponsorType', async ({ tier }) => {
328373
setupMocks();
329374
const seed4jMembersWithoutImageJson: Seed4jMember[] = [
@@ -366,6 +411,7 @@ describe('Generate sponsors data', () => {
366411
{ tier: 'Bronze sponsor', sponsorType: 'bronzes', filePath: '.vitepress/data/sponsors/bronzes.ts' },
367412
{ tier: 'Silver sponsor', sponsorType: 'silvers', filePath: '.vitepress/data/sponsors/silvers.ts' },
368413
{ tier: 'Gold sponsor', sponsorType: 'golds', filePath: '.vitepress/data/sponsors/golds.ts' },
414+
{ tier: 'Platinum sponsor', sponsorType: 'platinum sponsors', filePath: '.vitepress/data/sponsors/platinumSponsors.ts' },
369415
])(
370416
'should prevent overwriting an existing user image with seed4j logo even if the user does not have an image from the open collective api for $sponsorType',
371417
async ({ tier, filePath }) => {
@@ -648,5 +694,27 @@ describe('Generate sponsors data', () => {
648694
github: null,
649695
website: null,
650696
},
697+
{
698+
MemberId: 721012,
699+
createdAt: '2025-09-08 17:00',
700+
type: 'USER',
701+
role: 'BACKER',
702+
tier: 'Platinum sponsor',
703+
isActive: true,
704+
totalAmountDonated: 500,
705+
currency: 'USD',
706+
lastTransactionAt: '2025-09-08 17:00',
707+
lastTransactionAmount: 500,
708+
profile: 'https://opencollective.com/kaelan-ryder',
709+
name: 'Kaelan Ryder',
710+
company: null,
711+
description: null,
712+
image: null,
713+
email: null,
714+
newsletterOptIn: null,
715+
twitter: null,
716+
github: null,
717+
website: null,
718+
},
651719
];
652720
});

0 commit comments

Comments
 (0)