Skip to content

Instantly share code, notes, and snippets.

View PCreations's full-sized avatar

Pierre Criulanscy PCreations

View GitHub Profile
import axios from "axios";
const LATEST_ARTICLES_QUERY = `
query {
latestArticles {
publicationDate
title
url
}
}
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);
});
import axios from "axios";
const LATEST_ARTICLES_QUERY = `
query {
latestArticles {
publicationDate
title
url
}
}
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());
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) => {
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
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>`;
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({
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 { 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", () => {