Skip to content

Commit

Permalink
Merge pull request #8 from katapod/tests_and_migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym authored Aug 11, 2024
2 parents 73c1ede + b8c5b76 commit 8e91ec6
Show file tree
Hide file tree
Showing 14 changed files with 3,924 additions and 3,601 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 22.2.0
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@
"eslint-plugin-tsdoc": "^0.2.17",
"jest": "^29.5.0",
"jest-junit": "^16.0.0",
"libxmljs": "^1.0.9",
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typedoc": "^0.24.7",
"typescript": "^5.0.4"
"typescript": "^5.0.4",
"xml-js": "^1.6.11"
},
"dependencies": {
"dom-parser": "^0.1.6"
}
},
"packageManager": "[email protected]+sha512.c2e60e7ed04e459591c982f2760cd8f7d1f48fe1ca4d46ccbbf8377df1eb2d077ace1e9d334b06250dddf23c03b4562858f77992b9a3bb4a93355aefd173df32"
}
3,753 changes: 3,753 additions & 0 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

102 changes: 69 additions & 33 deletions src/parser.test.ts → src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { generateObjectFromXML } from './parser';
import { generateXMLFromObject } from './builder';

const cleanXML = `<?xml version="1.0" encoding="UTF-8"?>
export const cleanXML = `<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://feeds.katapod.com/stylesheet.xsl" type="text/xsl"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://podcastindex.org/namespace/1.0">
<channel>
Expand Down Expand Up @@ -98,8 +95,74 @@ Website: https://auditorspodcast.katapod.com/1
</channel>
</rss>
`;

const targetJson = {
export const dirtyXML = `<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://feeds.katapod.com/stylesheet.xsl" type="text/xsl"?>
rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://podcastindex.org/namespace/1.0">
<channel>
<atom:link rel="self" type="application/atom+xml" href="https://feeds.katapod.com/auditors-of-the-outer-rim" title="MP3 Audio"/>
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com/"/>
<title>Auditors of the Outer Rim</title>
<generator>Katapod (https://katapod.com)</generator>
<itunes:new-feed-url>https://feeds.katapod.com/auditors-of-the-outer-rim</itunes:new-feed-url>
<copyright>© 2020-2021 Auditors of the Outer Rim</copyright>
<podcast:guid>00535402-5e2c-5454-a20a-7e0bf9ead225</podcast:guid>
<podcast:locked owner="[email protected]">no</podcast:locked>
<language>en</language>
<pubDate>Fri, 15 Apr 2022 04:01:45 +1000</pubDate>
<lastBuildDate>Thu, 01 Jun 2023 03:37:05 +1000</lastBuildDate>
<link>https://twitter.com/AuditorsPodcast</link>
<image>
<url>https://images.katapod.com/file/Katapod/images/show/16601/full_1606823271-artwork.jpg</url>
<title>Auditors of the Outer Rim</title>
<link>https://twitter.com/AuditorsPodcast</link>
</image>
<itunes:category text="Leisure">
<itunes:category text="Games"/>
</itunes:category>
<itunes:category text="Fiction">
<itunes:category text="Science Fiction"/>
</itunes:category>
<itunes:type>serial</itunes:type>
<itunes:author>Auditors of the Outer Rim</itunes:author>
<itunes:image href="https://images.katapod.com/file/Katapod/images/show/16601/full_1606823271-artwork.jpg"/>
<itunes:subtitle>A Star Wars roleplaying game featuring storytelling, adventure, chaos, and fun.</itunes:subtitle>
<itunes:keywords>star wars, rpg, tabletop, roleplay, story, dice, edge of the empire, empire, dnd, d&amp;d, adventure, improv, jedi, plot, homebrew, custom, investigation, mystery, discovery, intrigue </itunes:keywords>
<itunes:owner>
<itunes:name>Ryan Miller</itunes:name>
</itunes:owner>
<itunes:complete>No</itunes:complete>
<itunes:explicit>No</itunes:explicit>
<item>
<title>Episode 1: The Auditors Are Born</title>
<itunes:title>Episode 1: The Auditors Are Born</itunes:title>
<itunes:episodeType>full</itunes:episodeType>
<guid isPermaLink="false">727d6797-eab2-4aab-a0e6-cfe31a8d0c8a</guid>
<link>https://share.katapod.com/s/3712446a</link>
<description>
<![CDATA[<p>This is the first episode of Auditors of the Outer Rim. We're using the Star Wars RPG Edge of the Empire by Fantasy Flight with a focus on fun and story before rules. Find us on Twitter <a href="https://twitter.com/AuditorsPodcast">@AuditorsPodcast</a> and on all major podcasting platforms.</p><p><strong>Cast:</strong> Ryan (GM), Tom (Mi-Shaan Li), Dan (Xeth), Damo (E-1), Will (Dahc). </p><p><strong>Story so far: </strong>Coming together out of necessity, this group of renegades escaped the grasp of their Hutt crime lord, stole his ship, liberated his slaves, and returned to end his reign. Their final escape from Tatooine caught the eye of the empire; narrowly avoiding destruction, they returned to Ryloth to seek help from those they saved. In exchange for future employment, their ship, renamed to The Auditor, was repaired and remade. The Auditors were born.</p><p><strong>Intro Crawl:<br></strong>Violence in the outer rim!</p><p>On the twin-sunned planet of TATOOINE, 4 escapees flee the quiet town of MOS SHUUTA and its ruler, TEEMO THE HUTT. Stealing an old freighter named the KRAYT FANG, the group of rebellious upstarts made for the planet of RYLOTH in the company of a Twi’lek prisoner.</p><p>Once there, the group uncovered a sinister plot of the HUTT, utilising slaves to mine an illegal substance known as SPICE. In eliminating TEEMO’s illegal activities, the party found themselves once more the focus of the HUTT’s wrath, leaving them but one option; eliminate the HUTT entirely.</p><p>A daring breach into the heart of TEEMO’s empire saw the party, disguised as AUDITORS, download and flee with all TEEMO’s business records that, once leaked, revealed TEEMO as shorthanding other members of the HUTT CLAN, permanently severing TEEMO from the power of their CLAN.</p><p>And such, a legend was born, adopting the name of the role that bought them their freedom as they roam the galaxy in search of fame, adoration, and of course, credits. This is the start of the group that would come to be known simply as the Auditors.</p><p><br><strong>Check out our links: </strong></p><p>🔗 <a href="https://linktr.ee/AuditorsPodcast">https://linktr.ee/AuditorsPodcast</a></p><p>🐦 <a href="https://twitter.com/AuditorsPodcast">https://twitter.com/AuditorsPodcast</a></p><p>🎙️ <a href="https://open.spotify.com/show/0xEF4DiEIibOVgYC6PK7eP">https://open.spotify.com/show/0xEF4DiEIibOVgYC6PK7eP</a></p><p>🍎 <a href="https://podcasts.apple.com/au/podcast/auditors-of-the-outer-rim/id1543140409">https://podcasts.apple.com/au/podcast/auditors-of-the-outer-rim/id1543140409</a></p><p>📺 <a href="https://www.youtube.com/channel/UCQJaT5gVoalzBqlNhwq5T8Q">https://www.youtube.com/channel/UCQJaT5gVoalzBqlNhwq5T8Q</a></p><p>✉️ <a href="https://[email protected]"><span class="__cf_email__" data-cfemail="046561766d687d69666d7e446369656d682a676b69">[email&#160;protected]</span></a></p><p>Original music provided with licenced or permission by: </p><p>"Seatbelt On" - Brightarm Orchestra on Epidemic Sound - <a href="https://www.epidemicsound.com/track/LCZ68X6PLC/">https://www.epidemicsound.com/track/LCZ68X6PLC/</a></p><p>Unlisted music, sounds, artwork, and assets are created by the people in this podcast and are provided with permission for use in this podcast and any related official or approved content.</p><p>If anyone wishes to use any audio or visual elements from this podcast, they may do so with appropriate attribution. We encourage you to use our works, but please contact <a href="https://[email protected]"><span class="__cf_email__" data-cfemail="7e1f1b0c171207131c17043e19131f1712501d1113">[email&#160;protected]</span></a> if you wish to do so out of courtesy and to ensure it's ok.</p><p>© 2020-2021 Auditors of the Outer Rim</p>]]>
</description>
<content:encoded>
<![CDATA[<p>This is the first episode of Auditors of the Outer Rim. We're using the Star Wars RPG Edge of the Empire by Fantasy Flight with a focus on fun and story before rules. Find us on Twitter <a href="https://twitter.com/AuditorsPodcast">@AuditorsPodcast</a> and on all major podcasting platforms.</p><p><strong>Cast:</strong> Ryan (GM), Tom (Mi-Shaan Li), Dan (Xeth), Damo (E-1), Will (Dahc). </p><p><strong>Story so far: </strong>Coming together out of necessity, this group of renegades escaped the grasp of their Hutt crime lord, stole his ship, liberated his slaves, and returned to end his reign. Their final escape from Tatooine caught the eye of the empire; narrowly avoiding destruction, they returned to Ryloth to seek help from those they saved. In exchange for future employment, their ship, renamed to The Auditor, was repaired and remade. The Auditors were born.</p><p><strong>Intro Crawl:<br></strong>Violence in the outer rim!</p><p>On the twin-sunned planet of TATOOINE, 4 escapees flee the quiet town of MOS SHUUTA and its ruler, TEEMO THE HUTT. Stealing an old freighter named the KRAYT FANG, the group of rebellious upstarts made for the planet of RYLOTH in the company of a Twi’lek prisoner.</p><p>Once there, the group uncovered a sinister plot of the HUTT, utilising slaves to mine an illegal substance known as SPICE. In eliminating TEEMO’s illegal activities, the party found themselves once more the focus of the HUTT’s wrath, leaving them but one option; eliminate the HUTT entirely.</p><p>A daring breach into the heart of TEEMO’s empire saw the party, disguised as AUDITORS, download and flee with all TEEMO’s business records that, once leaked, revealed TEEMO as shorthanding other members of the HUTT CLAN, permanently severing TEEMO from the power of their CLAN.</p><p>And such, a legend was born, adopting the name of the role that bought them their freedom as they roam the galaxy in search of fame, adoration, and of course, credits. This is the start of the group that would come to be known simply as the Auditors.</p><p><br><strong>Check out our links: </strong></p><p>🔗 <a href="https://linktr.ee/AuditorsPodcast">https://linktr.ee/AuditorsPodcast</a></p><p>🐦 <a href="https://twitter.com/AuditorsPodcast">https://twitter.com/AuditorsPodcast</a></p><p>🎙️ <a href="https://open.spotify.com/show/0xEF4DiEIibOVgYC6PK7eP">https://open.spotify.com/show/0xEF4DiEIibOVgYC6PK7eP</a></p><p>🍎 <a href="https://podcasts.apple.com/au/podcast/auditors-of-the-outer-rim/id1543140409">https://podcasts.apple.com/au/podcast/auditors-of-the-outer-rim/id1543140409</a></p><p>📺 <a href="https://www.youtube.com/channel/UCQJaT5gVoalzBqlNhwq5T8Q">https://www.youtube.com/channel/UCQJaT5gVoalzBqlNhwq5T8Q</a></p><p>✉️ <a href="https://[email protected]"><span class="__cf_email__" data-cfemail="b1d0d4c3d8ddc8dcd3d8cbf1d6dcd0d8dd9fd2dedc">[email&#160;protected]</span></a></p><p>Original music provided with licenced or permission by: </p><p>"Seatbelt On" - Brightarm Orchestra on Epidemic Sound - <a href="https://www.epidemicsound.com/track/LCZ68X6PLC/">https://www.epidemicsound.com/track/LCZ68X6PLC/</a></p><p>Unlisted music, sounds, artwork, and assets are created by the people in this podcast and are provided with permission for use in this podcast and any related official or approved content.</p><p>If anyone wishes to use any audio or visual elements from this podcast, they may do so with appropriate attribution. We encourage you to use our works, but please contact <a href="https://[email protected]"><span class="__cf_email__" data-cfemail="036266716a6f7a6e616a7943646e626a6f2d606c6e">[email&#160;protected]</span></a> if you wish to do so out of courtesy and to ensure it's ok.</p><p>© 2020-2021 Auditors of the Outer Rim</p>]]>
</content:encoded>
<pubDate>Wed, 02 Dec 2020 01:59:54 +1100</pubDate>
<author>Auditors of the Outer Rim</author>
<enclosure url="https://media.katapod.com/3712446a/ece1bd1a.mp3" length="125885781" type="audio/mpeg"/>
<itunes:author>Auditors of the Outer Rim</itunes:author>
<itunes:image href="https://images.katapod.com/file/Katapod/images/show/16601/full_1606823271-artwork.jpg"/>
<itunes:duration>7863</itunes:duration>
<itunes:summary>Coming together out of necessity, this group of renegades escaped the grasp of their Hutt crime lord, stole his ship, liberated his slaves, and returned to end his reign. Their final escape from Tatooine caught the eye of the empire; narrowly avoiding destruction, they returned to Ryloth to seek help from those they saved. In exchange for future employment, their ship, renamed to The Auditor, was repaired and remade. The Auditors were born.
Show Notes: https://share.katapod.com/s/3712446a
Website: https://auditorspodcast.katapod.com/1
</itunes:summary>
<itunes:subtitle>Coming together out of necessity, this group of renegades escaped the grasp of their Hutt crime lord, stole his ship, liberated his slaves, and returned to end his reign. Their final escape from Tatooine caught the eye of the empire; narrowly avoiding des</itunes:subtitle>
<itunes:keywords>star wars, rpg, tabletop, roleplay, story, dice, edge of the empire, empire, dnd, d&amp;d, adventure, improv, jedi, plot, homebrew, custom, investigation, mystery, discovery, intrigue
</itunes:keywords>
<itunes:explicit>No</itunes:explicit>
</item>
</channel>
</rss>
`;
export const targetJson = {
'?xml-stylesheet': {
'@href': 'https://feeds.katapod.com/stylesheet.xsl',
'@type': 'text/xsl',
Expand Down Expand Up @@ -240,30 +303,3 @@ Website: https://auditorspodcast.katapod.com/1`,
},
},
};

describe('Parser Functionality', () => {
it('Creates JSON from real XML', async () => {
const json = generateObjectFromXML(cleanXML);

expect(json).toBeDefined();

const generatedJson = {
'?xml-stylesheet': {
'@href': 'https://feeds.katapod.com/stylesheet.xsl',
'@type': 'text/xsl',
},
rss: {
'@version': '2.0',
'@xmlns:dc': 'http://purl.org/dc/elements/1.1/',
'@xmlns:atom': 'http://www.w3.org/2005/Atom',
'@xmlns:sy': 'http://purl.org/rss/1.0/modules/syndication/',
'@xmlns:content': 'http://purl.org/rss/1.0/modules/content/',
'@xmlns:itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd',
'@xmlns:podcast': 'https://podcastindex.org/namespace/1.0',
channel: json,
},
};

expect(generatedJson).toStrictEqual(targetJson);
});
});
11 changes: 11 additions & 0 deletions src/tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { xml2json } from 'xml-js';

export const isValidXml = (xml: string) => {
try {
const res = xml2json(xml);

return !!(res && res.length > 0);
} catch (error) {
return false;
}
};
19 changes: 5 additions & 14 deletions src/builder.test.ts → tests/builder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateXMLFromObject, getElements } from './builder';
import libxmljs from 'libxmljs';
import { generateXMLFromObject, getElements } from '../src/builder';
import { isValidXml } from '../src/tests';

describe('Builder functionality', () => {
it('Creates empty XML from empty JSON', () => {
Expand Down Expand Up @@ -781,17 +781,8 @@ This
});
});

describe('XML validates against libxmljs', () => {
const isValidSyntaxStructure = function (text: string) {
try {
libxmljs.parseXml(text);
} catch (e) {
return false;
}

return true;
};
it('should validate XML against XSD', () => {
describe('XML validates against W3C', () => {
it('should validate XML', () => {
const json = {
root: {
'@att': 'val',
Expand All @@ -803,6 +794,6 @@ describe('XML validates against libxmljs', () => {
};

const generatedXML = generateXMLFromObject(json);
expect(isValidSyntaxStructure(generatedXML)).toEqual(true);
expect(isValidXml(generatedXML)).toEqual(true);
});
});
14 changes: 3 additions & 11 deletions tests/example.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { generateXMLFromObject } from '../src';
import libxmljs from 'libxmljs';
import { isValidXml } from '../src/tests';

describe('Builder can create examples', () => {
const isValidSyntaxStructure = function (text: string) {
try {
libxmljs.parseXml(text);
} catch (e) {
return false;
}
return true;
};
it('W3Schools RSS Feed', () => {
const exampleXML = `<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
Expand Down Expand Up @@ -55,7 +47,7 @@ describe('Builder can create examples', () => {

const generatedXML = generateXMLFromObject(json);
expect(generatedXML).toEqual(exampleXML);
expect(isValidSyntaxStructure(generatedXML)).toEqual(true);
expect(isValidXml(generatedXML)).toEqual(true);
});
it('xul.fr RSS Feed', () => {
const exampleXML = `<?xml version="1.0"?>
Expand Down Expand Up @@ -110,6 +102,6 @@ describe('Builder can create examples', () => {

const generatedXML = generateXMLFromObject(json, { indentSpaces: 4, excludeXMLEncoding: true });
expect(generatedXML).toEqual(exampleXML);
expect(isValidSyntaxStructure(generatedXML)).toEqual(true);
expect(isValidXml(generatedXML)).toEqual(true);
});
});
4 changes: 2 additions & 2 deletions src/index.test.ts → tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
describe('index', () => {
it('should export generateXMLFromObject', () => {
const { generateXMLFromObject } = require('./index');
const { generateXMLFromObject } = require('../src/index');
expect(generateXMLFromObject).toBeDefined();
});
it('should export generateObjectFromXML', () => {
const { generateObjectFromXML } = require('./index');
const { generateObjectFromXML } = require('../src/index');
expect(generateObjectFromXML).toBeDefined();
});
});
29 changes: 29 additions & 0 deletions tests/parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { generateObjectFromXML } from '../src/parser';
import { cleanXML, targetJson } from '../src/constants';

describe('Parser Functionality', () => {
it('Creates JSON from real XML', async () => {
const json = generateObjectFromXML(cleanXML);

expect(json).toBeDefined();

const generatedJson = {
'?xml-stylesheet': {
'@href': 'https://feeds.katapod.com/stylesheet.xsl',
'@type': 'text/xsl',
},
rss: {
'@version': '2.0',
'@xmlns:dc': 'http://purl.org/dc/elements/1.1/',
'@xmlns:atom': 'http://www.w3.org/2005/Atom',
'@xmlns:sy': 'http://purl.org/rss/1.0/modules/syndication/',
'@xmlns:content': 'http://purl.org/rss/1.0/modules/content/',
'@xmlns:itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd',
'@xmlns:podcast': 'https://podcastindex.org/namespace/1.0',
channel: json,
},
};

expect(generatedJson).toStrictEqual(targetJson);
});
});
Loading

0 comments on commit 8e91ec6

Please sign in to comment.