Skip to content

Commit

Permalink
Merge pull request #242 from derduher/test-org
Browse files Browse the repository at this point in the history
organize some tests into unit and integration tests
  • Loading branch information
derduher authored Sep 7, 2019
2 parents 2d1108f + d7ea6b4 commit aae23bc
Show file tree
Hide file tree
Showing 10 changed files with 1,694 additions and 1,012 deletions.
8 changes: 8 additions & 0 deletions lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ export class InvalidVideoDescription extends Error {
}
}

export class InvalidVideoRating extends Error {
constructor(message?: string) {
super(message || 'rating must be between 0 and 5');
this.name = 'InvalidVideoRating';
Error.captureStackTrace(this, InvalidVideoRating);
}
}

export class InvalidAttrValue extends Error {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(key: string, val: any, validator: RegExp) {
Expand Down
3 changes: 3 additions & 0 deletions lib/sitemap-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export async function parseSitemap (xml: Readable): Promise<ISitemapOptions> {
currentItem.news = newsTemplate();
}
})

saxStream.on('opentag', (tag): void => {
switch (tag.name) {
case "url":
Expand Down Expand Up @@ -155,6 +156,7 @@ export async function parseSitemap (xml: Readable): Promise<ISitemapOptions> {
break;
}
})

saxStream.on('text', (text): void => {
switch (currentTag) {
case "mobile:mobile":
Expand Down Expand Up @@ -327,6 +329,7 @@ export async function parseSitemap (xml: Readable): Promise<ISitemapOptions> {
break;
}
})

saxStream.on('attribute', (attr): void => {
switch (currentTag) {
case "urlset":
Expand Down
9 changes: 7 additions & 2 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
InvalidVideoDescription,
InvalidVideoDuration,
InvalidVideoFormat,
InvalidVideoRating,
NoURLError,
NoConfigError,
PriorityInvalidError
Expand Down Expand Up @@ -66,7 +67,7 @@ export function validateSMIOptions (conf: SitemapItemOptions, level = ErrorLevel
}

if (priority) {
if (!(priority >= 0.0 && priority <= 1.0) || typeof priority !== 'number') {
if (!(priority >= 0.0 && priority <= 1.0)) {
if (level === ErrorLevel.THROW) {
throw new PriorityInvalidError()
} else {
Expand Down Expand Up @@ -115,7 +116,11 @@ export function validateSMIOptions (conf: SitemapItemOptions, level = ErrorLevel
}
}
if (vid.rating !== undefined && (vid.rating < 0 || vid.rating > 5)) {
console.warn(`${url}: video ${vid.title} rating ${vid.rating} must be between 0 and 5 inclusive`)
if (level === ErrorLevel.THROW) {
throw new InvalidVideoRating()
} else {
console.warn(`${url}: video ${vid.title} rating ${vid.rating} must be between 0 and 5 inclusive`)
}
}

if (typeof (vid) !== 'object' || !vid.thumbnail_loc || !vid.title || !vid.description) {
Expand Down
Loading

0 comments on commit aae23bc

Please sign in to comment.