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 axios from "axios"; | |
const LATEST_ARTICLES_QUERY = ` | |
query { | |
latestArticles { | |
publicationDate | |
title | |
url | |
} | |
} |
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 { createTestServer } from "./test-server"; | |
import { executeLatestArticlesQuery } from "../execute-latest-articles-query"; | |
import { createTestArticlePublishedOneDayAgo } from "./data/create-test-article"; | |
describe("executeLatestArticlesQuery", () => { | |
let testServer; | |
beforeAll((done) => { | |
testServer = createTestServer({ port: 4123 }); | |
testServer.listen(done); | |
}); |
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 axios from "axios"; | |
const LATEST_ARTICLES_QUERY = ` | |
query { | |
latestArticles { | |
publicationDate | |
title | |
url | |
} | |
} |
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 express from "express"; | |
import cors from "cors"; | |
export const createTestServer = ({ port }) => { | |
let server; | |
const lastSentRequest = {}; | |
const app = express(); | |
app.use(cors({ origin: "*" })); | |
app.use(express.json()); |
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 { createTestServer } from "./test-server"; | |
import { executeLatestArticlesQuery } from "../execute-latest-articles-query"; | |
describe("executeLatestArticlesQuery", () => { | |
let testServer; | |
beforeAll((done) => { | |
testServer = createTestServer({ port: 4123 }); | |
testServer.listen(done); | |
}); | |
afterAll((done) => { |
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
export const articleToXml = ({ language, article }) => | |
`<url><loc>${article.url}</loc><news:news><news:publication><news:name>My Website</news:name><news:language>${language}</news:language></news:publication><news:publication_date>${article.publicationDate}</news:publication_date><news:title>${article.title}</news:title></news:news></url>`; |
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 { articleToXml } from "../article-to-xml"; | |
const { | |
createTestArticlePublishedOneDayAgo, | |
} = require("./data/create-test-article"); | |
describe("articleToXml", () => { | |
it("generates the xml string representation of an article", () => { | |
// arrange | |
const today = new Date(); | |
const article = createTestArticlePublishedOneDayAgo({ |
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 { createIsRecentArticle } from "../is-recent-article"; | |
import { | |
createTestArticlePublishedOneDayAgo, | |
createTestArticlePublishedTwoDaysAgo, | |
createTestArticlePublishedThreeDaysAgo, | |
} from "./data/create-test-article"; | |
describe("isRecentArticle", () => { | |
const today = new Date("2020-09-01T12:07:23.997Z"); | |
it("returns true if the article is less than 2 days old", () => { |