Skip to content

Instantly share code, notes, and snippets.

View PCreations's full-sized avatar

Pierre Criulanscy PCreations

View GitHub Profile
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", () => {
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 }) => {
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 () => {
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
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
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);
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)
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>`;
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);
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;