UNPKG

1.86 kBJavaScriptView Raw
1const moment = require("moment");
2const generate = require("./generate");
3
4describe("Generate", () => {
5 it("generates dummy xml", () => {
6 const baseUrl = "http://demo.com/";
7 const sections = ["demoSection"];
8 const title = "demo title";
9 const date = moment("2016-02-21", "YYYY-MM-DD")
10 .utcOffset(0)
11 .format();
12 const body = "demo";
13 const pages = {
14 demo: {
15 type: "page",
16 sectionName: "demoSection",
17 file: {
18 attributes: {
19 date,
20 title,
21 },
22 body,
23 },
24 },
25 };
26 const config = {
27 title: "Demo RSS",
28 author: "Demo Author",
29 };
30 const updated = moment().format();
31
32 const result = generate({
33 baseUrl,
34 sections,
35 updated,
36 pages,
37 config,
38 get: {
39 content: page => page.file.body,
40 date: page => page.file.attributes.date,
41 title: page => page.file.attributes.title,
42 },
43 });
44 const expected =
45 '<feed xmlns="http://www.w3.org/2005/Atom">' +
46 "<title>" +
47 config.title +
48 "</title>" +
49 '<link href="' +
50 baseUrl +
51 'atom.xml" rel="self"></link>' +
52 '<link href="' +
53 baseUrl +
54 '" rel=""></link>' +
55 "<updated>" +
56 updated +
57 "</updated>" +
58 "<id>" +
59 baseUrl +
60 "</id>" +
61 "<author><name>" +
62 config.author +
63 "</name><email></email></author>" +
64 "<entry>" +
65 "<title>" +
66 title +
67 "</title>" +
68 "<id>ademotitle" +
69 date.toLowerCase() +
70 "</id>" +
71 '<link href="' +
72 baseUrl +
73 'demo"></link>' +
74 "<updated>" +
75 date +
76 "</updated>" +
77 '<content type="html">' +
78 body +
79 "</content>" +
80 "</entry>" +
81 "</feed>";
82
83 expect(result).toEqual(expected);
84 });
85});