Skip to content

Commit df93bcb

Browse files
authored
feat: lower evergreen sitemap threshold (#3760)
1 parent 3e97f2f commit df93bcb

2 files changed

Lines changed: 234 additions & 60 deletions

File tree

__tests__/sitemaps.ts

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,38 @@ describe('GET /sitemaps/tags.xml', () => {
269269

270270
describe('GET /sitemaps/index.xml', () => {
271271
it('should return sitemap index xml with all paginated post sitemaps', async () => {
272+
const oldDate = new Date(now.getTime() - 91 * ONE_DAY_IN_SECONDS * 1000);
273+
274+
await con.getRepository(Post).insert([
275+
{
276+
id: 'evergreen-index-1',
277+
shortId: 'ei1',
278+
title: 'Evergreen Index 1',
279+
sourceId: 'a',
280+
createdAt: oldDate,
281+
type: PostType.Article,
282+
upvotes: 10,
283+
},
284+
{
285+
id: 'evergreen-index-2',
286+
shortId: 'ei2',
287+
title: 'Evergreen Index 2',
288+
sourceId: 'a',
289+
createdAt: new Date(oldDate.getTime() - 1000),
290+
type: PostType.Article,
291+
upvotes: 11,
292+
},
293+
{
294+
id: 'evergreen-index-3',
295+
shortId: 'ei3',
296+
title: 'Evergreen Index 3',
297+
sourceId: 'a',
298+
createdAt: new Date(oldDate.getTime() - 2000),
299+
type: PostType.Article,
300+
upvotes: 12,
301+
},
302+
]);
303+
272304
const res = await request(app.server)
273305
.get('/sitemaps/index.xml')
274306
.expect(200);
@@ -285,7 +317,10 @@ describe('GET /sitemaps/index.xml', () => {
285317
'<loc>http://localhost:5002/api/sitemaps/posts-2.xml</loc>',
286318
);
287319
expect(res.text).toContain(
288-
'<loc>http://localhost:5002/api/sitemaps/tags.xml</loc>',
320+
'<loc>http://localhost:5002/api/sitemaps/evergreen.xml</loc>',
321+
);
322+
expect(res.text).toContain(
323+
'<loc>http://localhost:5002/api/sitemaps/evergreen-2.xml</loc>',
289324
);
290325
expect(res.text).toContain(
291326
'<loc>http://localhost:5002/api/sitemaps/agents.xml</loc>',
@@ -296,6 +331,9 @@ describe('GET /sitemaps/index.xml', () => {
296331
expect(res.text).toContain(
297332
'<loc>http://localhost:5002/api/sitemaps/squads.xml</loc>',
298333
);
334+
expect(res.text).toContain(
335+
'<loc>http://localhost:5002/api/sitemaps/tags.xml</loc>',
336+
);
299337
});
300338
});
301339

@@ -431,6 +469,77 @@ describe('GET /sitemaps/squads.xml', () => {
431469
});
432470

433471
describe('GET /sitemaps/evergreen.xml', () => {
472+
it('should include posts with at least 10 upvotes and paginate older posts', async () => {
473+
const oldDate = new Date(now.getTime() - 91 * ONE_DAY_IN_SECONDS * 1000);
474+
475+
await con.getRepository(Post).insert([
476+
{
477+
id: 'evergreen-min-threshold',
478+
shortId: 'emt',
479+
title: 'Evergreen Min Threshold',
480+
sourceId: 'a',
481+
createdAt: oldDate,
482+
type: PostType.Article,
483+
upvotes: 10,
484+
},
485+
{
486+
id: 'evergreen-next-page',
487+
shortId: 'enp',
488+
title: 'Evergreen Next Page',
489+
sourceId: 'a',
490+
createdAt: new Date(oldDate.getTime() - 1000),
491+
type: PostType.Article,
492+
upvotes: 11,
493+
},
494+
{
495+
id: 'evergreen-third-page',
496+
shortId: 'etp',
497+
title: 'Evergreen Third Page',
498+
sourceId: 'a',
499+
createdAt: new Date(oldDate.getTime() - 2000),
500+
type: PostType.Article,
501+
upvotes: 12,
502+
},
503+
{
504+
id: 'evergreen-below-threshold',
505+
shortId: 'ebt',
506+
title: 'Evergreen Below Threshold',
507+
sourceId: 'a',
508+
createdAt: new Date(oldDate.getTime() - 3000),
509+
type: PostType.Article,
510+
upvotes: 9,
511+
},
512+
]);
513+
514+
const firstPage = await request(app.server)
515+
.get('/sitemaps/evergreen.xml')
516+
.expect(200);
517+
const secondPage = await request(app.server)
518+
.get('/sitemaps/evergreen-2.xml')
519+
.expect(200);
520+
521+
expect(firstPage.header['content-type']).toContain('application/xml');
522+
expect(firstPage.text).toContain(
523+
'/posts/evergreen-third-page-evergreen-third-page',
524+
);
525+
expect(firstPage.text).toContain(
526+
'/posts/evergreen-next-page-evergreen-next-page',
527+
);
528+
expect(firstPage.text).not.toContain(
529+
'/posts/evergreen-min-threshold-evergreen-min-threshold',
530+
);
531+
expect(firstPage.text).not.toContain(
532+
'/posts/evergreen-below-threshold-ebt',
533+
);
534+
535+
expect(secondPage.text).toContain(
536+
'/posts/evergreen-min-threshold-evergreen-min-threshold',
537+
);
538+
expect(secondPage.text).not.toContain(
539+
'/posts/evergreen-below-threshold-ebt',
540+
);
541+
});
542+
434543
it('should exclude posts by low-reputation authors', async () => {
435544
await con.getRepository(User).save({
436545
id: 'low-rep-sitemap',

0 commit comments

Comments
 (0)