Skip to content

Commit

Permalink
move e2e tests into their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
derduher committed Sep 2, 2019
1 parent 9678baf commit d7ea6b4
Show file tree
Hide file tree
Showing 8 changed files with 1,598 additions and 967 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
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 d7ea6b4

Please sign in to comment.