|
| 1 | +import test from 'ava' |
| 2 | +import { parseAtom, parseXML } from './parsers' |
| 3 | + |
| 4 | +test('#parseAtom handles missing entry field gracefully', async (t) => { |
| 5 | + const xml = { |
| 6 | + feed: { |
| 7 | + title: ['Test Feed'], |
| 8 | + subtitle: ['Test subtitle'], |
| 9 | + link: [{ $: { rel: 'alternate', href: 'https://example.com' } }], |
| 10 | + updated: ['2024-01-01T00:00:00Z'], |
| 11 | + generator: ['test'] |
| 12 | + // Note: entry field is missing |
| 13 | + } |
| 14 | + } |
| 15 | + |
| 16 | + const site = parseAtom('Test Feed', xml) |
| 17 | + t.truthy(site) |
| 18 | + t.is(site.entries.length, 0) |
| 19 | +}) |
| 20 | + |
| 21 | +test('#parseAtom handles empty date fields gracefully', async (t) => { |
| 22 | + const xml = { |
| 23 | + feed: { |
| 24 | + title: ['Test Feed'], |
| 25 | + subtitle: ['Test subtitle'], |
| 26 | + link: [{ $: { rel: 'alternate', href: 'https://example.com' } }], |
| 27 | + updated: [''], |
| 28 | + generator: ['test'], |
| 29 | + entry: [ |
| 30 | + { |
| 31 | + title: ['Test Entry'], |
| 32 | + link: [{ $: { rel: 'alternate', href: 'https://example.com/entry' } }], |
| 33 | + published: [''], |
| 34 | + updated: [''], |
| 35 | + content: [{ _: 'Test content' }] |
| 36 | + } |
| 37 | + ] |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + const site = parseAtom('Test Feed', xml) |
| 42 | + t.truthy(site) |
| 43 | + t.false(isNaN(site.updatedAt)) |
| 44 | + t.is(site.entries.length, 1) |
| 45 | + t.false(isNaN(site.entries[0].date)) |
| 46 | +}) |
| 47 | + |
| 48 | +test('#parseAtom handles invalid date fields gracefully', async (t) => { |
| 49 | + const xml = { |
| 50 | + feed: { |
| 51 | + title: ['Test Feed'], |
| 52 | + subtitle: ['Test subtitle'], |
| 53 | + link: [{ $: { rel: 'alternate', href: 'https://example.com' } }], |
| 54 | + updated: ['not a valid date'], |
| 55 | + generator: ['test'], |
| 56 | + entry: [ |
| 57 | + { |
| 58 | + title: ['Test Entry'], |
| 59 | + link: [{ $: { rel: 'alternate', href: 'https://example.com/entry' } }], |
| 60 | + published: ['invalid'], |
| 61 | + content: [{ _: 'Test content' }] |
| 62 | + } |
| 63 | + ] |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + const site = parseAtom('Test Feed', xml) |
| 68 | + t.truthy(site) |
| 69 | + t.false(isNaN(site.updatedAt)) |
| 70 | + t.is(site.entries.length, 1) |
| 71 | + t.false(isNaN(site.entries[0].date)) |
| 72 | +}) |
| 73 | + |
| 74 | +test('#parseAtom handles empty entry array', async (t) => { |
| 75 | + const xml = { |
| 76 | + feed: { |
| 77 | + title: ['Test Feed'], |
| 78 | + subtitle: ['Test subtitle'], |
| 79 | + link: [{ $: { rel: 'alternate', href: 'https://example.com' } }], |
| 80 | + updated: ['2024-01-01T00:00:00Z'], |
| 81 | + generator: ['test'], |
| 82 | + entry: [] |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + const site = parseAtom('Test Feed', xml) |
| 87 | + t.truthy(site) |
| 88 | + t.is(site.entries.length, 0) |
| 89 | +}) |
| 90 | + |
| 91 | +test('#parseAtom handles missing link in entry', async (t) => { |
| 92 | + const xml = { |
| 93 | + feed: { |
| 94 | + title: ['Test Feed'], |
| 95 | + subtitle: ['Test subtitle'], |
| 96 | + link: [{ $: { rel: 'alternate', href: 'https://example.com' } }], |
| 97 | + updated: ['2024-01-01T00:00:00Z'], |
| 98 | + generator: ['test'], |
| 99 | + entry: [ |
| 100 | + { |
| 101 | + title: ['Test Entry'], |
| 102 | + // Note: link field is missing |
| 103 | + published: ['2024-01-01T00:00:00Z'], |
| 104 | + content: [{ _: 'Test content' }] |
| 105 | + } |
| 106 | + ] |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + const site = parseAtom('Test Feed', xml) |
| 111 | + t.truthy(site) |
| 112 | + t.is(site.entries.length, 1) |
| 113 | + t.is(site.entries[0].link, '') |
| 114 | +}) |
| 115 | + |
| 116 | +test('#parseAtom handles empty link array in entry', async (t) => { |
| 117 | + const xml = { |
| 118 | + feed: { |
| 119 | + title: ['Test Feed'], |
| 120 | + subtitle: ['Test subtitle'], |
| 121 | + link: [{ $: { rel: 'alternate', href: 'https://example.com' } }], |
| 122 | + updated: ['2024-01-01T00:00:00Z'], |
| 123 | + generator: ['test'], |
| 124 | + entry: [ |
| 125 | + { |
| 126 | + title: ['Test Entry'], |
| 127 | + link: [], // Empty link array |
| 128 | + published: ['2024-01-01T00:00:00Z'], |
| 129 | + content: [{ _: 'Test content' }] |
| 130 | + } |
| 131 | + ] |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + const site = parseAtom('Test Feed', xml) |
| 136 | + t.truthy(site) |
| 137 | + t.is(site.entries.length, 1) |
| 138 | + t.is(site.entries[0].link, '') |
| 139 | +}) |
| 140 | + |
0 commit comments