Skip to content

Commit

Permalink
fix(validateQuote): allow author to be undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza committed Jan 18, 2024
1 parent b4f34cd commit c20a046
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ export function validateQuote(quote: unknown) {

const { author, categories, submitter, text } = quote as Record<string, unknown>

if (typeof author === "string") {
if (author.length < 1) {
if (typeof author === "string" || typeof author === "undefined") {
if (typeof author !== "undefined" && author.length < 1) {
errors.push({
expected: "string.length <= 1",
message: "Expected the author to be at least 1 character",
received: `${author.length}`,
})
}

if (author.length > 30) {
if (typeof author !== "undefined" && author.length > 30) {
errors.push({
expected: "string.length <= 30",
message: "Expected the author to be less than 30 characters",
Expand All @@ -62,8 +62,8 @@ export function validateQuote(quote: unknown) {
}
} else {
errors.push({
expected: "string",
message: `Expected the author to be a string, but received ${typeof author}`,
expected: "string | undefined",
message: `Expected the author to be a string or undefined, but received ${typeof author}`,
received: `${author}`,
})
}
Expand Down

0 comments on commit c20a046

Please sign in to comment.