Last active
September 7, 2020 08:37
-
-
Save PCreations/7f071edab435812f6b51dd7eec948759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createRecentArticlesSitemap } from "../recent-articles-sitemap"; | |
import { | |
createTestArticlePublishedOneDayAgo, | |
createTestArticlePublishedTwoDaysAgo, | |
createTestArticlePublishedThreeDaysAgo, | |
} from "./data/create-test-article"; | |
import { createFakeExecuteLatestArticlesQuery } from "../execute-latest-articles-query"; | |
import { createFakeS3xmlUploader } from "../s3-xml-uploader"; | |
describe("recentArticlesSitemap", () => { | |
it("generates the sitemap xml of the latest articles for a specific domain and language", async () => { | |
// arrange | |
const today = new Date("2020-09-01T12:07:23.997Z"); | |
const articles = [ | |
createTestArticlePublishedOneDayAgo({ today }), | |
createTestArticlePublishedTwoDaysAgo({ today }), | |
createTestArticlePublishedThreeDaysAgo({ today }), | |
]; | |
const domain = "wwww.my-website.co-uk"; | |
const language = "en-GB"; | |
const executeLatestArticlesQuery = createFakeExecuteLatestArticlesQuery({ | |
[domain]: articles, | |
}); | |
const s3xmlUploader = createFakeS3xmlUploader({ | |
bucketName: "test-bucket", | |
}); | |
const recentArticlesSitemap = createRecentArticlesSitemap({ | |
todayDate: today, | |
executeLatestArticlesQuery, | |
s3xmlUploader, | |
}); | |
// act | |
await recentArticlesSitemap({ domain, language }); | |
// assert | |
expect(s3xmlUploader.getLastPutObject().Body).toEqual( | |
`<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"><url><loc>${articles[0].url}</loc><news:news><news:publication><news:name>My Website</news:name><news:language>${language}</news:language></news:publication><news:publication_date>${articles[0].publicationDate}</news:publication_date><news:title>${articles[0].title}</news:title></news:news></url><url><loc>${articles[1].url}</loc><news:news><news:publication><news:name>My Website</news:name><news:language>${language}</news:language></news:publication><news:publication_date>${articles[1].publicationDate}</news:publication_date><news:title>${articles[1].title}</news:title></news:news></url></urlset>` | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment