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", () => { |
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 { createIsRecentArticle } from "./is-recent-article"; | |
import { articleToXml } from "./article-to-xml"; | |
import { createExecuteLatestArticlesQuery } from "./execute-latest-articles-query"; | |
export const createRecentArticlesSitemap = ({ | |
todayDate, | |
executeLatestArticlesQuery = createExecuteLatestArticlesQuery(), | |
}) => { | |
const isRecentArticle = createIsRecentArticle(todayDate); | |
return async ({ domain, language }) => { |
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"; | |
describe("recentArticlesSitemap", () => { | |
it("generates the sitemap xml of the latest articles for a specific domain and language", async () => { |
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 { createIsRecentArticle } from "./is-recent-article"; | |
import { articleToXml } from "./article-to-xml"; | |
export const createRecentArticlesSitemap = ({ | |
todayDate, | |
articles, | |
}) => { | |
const isRecentArticle = createIsRecentArticle(todayDate); | |
return async ({ domain, language }) => | |
`<?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">${articles |
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"; | |
describe("recentArticlesSitemap", () => { | |
it("generates the sitemap xml of the latest articles for a specific domain and language", async () => { | |
// arrange |
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"; | |
const ONE_DAY_IN_MS = 3600 * 24 * 1000; | |
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 oneDayAgo = new Date(+today - ONE_DAY_IN_MS); | |
const twoDaysAgo = new Date(+oneDayAgo - ONE_DAY_IN_MS); |
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 { createIsRecentArticle } from "./is-recent-article"; | |
export const createRecentArticlesSitemap = ({ | |
todayDate, | |
articles, | |
}) => { | |
const isRecentArticle = createIsRecentArticle(todayDate); | |
return async ({ domain, language }) => | |
`<?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">${articles | |
.filter(isRecentArticle) |
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
export const createRecentArticlesSitemap = ({ | |
articles, | |
}) => async ({ domain, language }) => `<?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>`; |
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"; | |
const ONE_DAY_IN_MS = 3600 * 24 * 1000; | |
describe("recentArticlesSitemap", () => { | |
it("generates the sitemap xml of the latest articles for a specific domain and language", async () => { | |
// arrange | |
const today = new Date(); | |
const oneDayAgo = new Date(+today - ONE_DAY_IN_MS); | |
const twoDaysAgo = new Date(+oneDayAgo - ONE_DAY_IN_MS); |
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 aws from "aws-sdk"; | |
aws.config.update({ | |
accessKeyId: process.env.ACCESS_KEY_ID, | |
secretAccessKey: process.env.SECRET_ACCESS_KEY, | |
region: process.env.REGION, | |
}); | |
export const createS3xmlUploader = ({ bucketName, s3 = new aws.S3() }) => { | |
let lastPutObject; |