Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

fix: tested and verified the article data transformation #317

Merged

Conversation

SidStraw
Copy link
Contributor

Added schema validation in dev, and when validation fails, access to the article page is denied.

@DanSnow DanSnow requested a review from arielllin January 11, 2024 01:22
Comment on lines 294 to 297
if (process.env.NODE_ENV === 'development') {
ArticleSchema.parse(document)
}
const article = normalizeArticle(document as TypesenseArticleLike)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果驗證失敗的話會導致沒有 return article 直接顯示 500 error,但這邊會不清楚是因為驗證失敗導致的,如果調整在 console 中顯示 error 呢

截圖 2024-01-12 上午11 06 40

Comment on lines 322 to 324
if (process.env.NODE_ENV === 'development') {
QueryArticleSchema.parse(data.article)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果驗證失敗的話會導致沒有 return article 直接顯示 500 error

Comment on lines 21 to 38
export const ArticleSchema = z.object({
authors: z.array(AuthorSchema),
blurb: z.string(),
cover: z.string(),
desk: DeskSchema,
featured: z.boolean(),
id: z.string(),
order: z.number(),
pathnames: z.array(z.string()),
plan: z.string(),
published_at: z.number(),
seo: z.string(),
slug: z.string(),
tags: z.array(DeskSchema),
title: z.string(),
updated_at: z.number(),
})
export type Article = z.infer<typeof ArticleSchema>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coverseo 有可能會是 null

Comment on lines 10 to 18
export const AuthorSchema = z.object({
avatar: z.string(),
bio: z.string(),
full_name: z.string(),
id: z.number(),
location: z.string(),
slug: z.string(),
socials: z.string(),
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

biolocationsocials 有可能會是 null

@SidStraw SidStraw requested a review from arielllin January 24, 2024 01:21
@DanSnow DanSnow changed the title chore: tested and verified the article data transformation fix: tested and verified the article data transformation Jan 24, 2024
@DanSnow DanSnow merged commit 29d6fac into main Jan 24, 2024
4 checks passed
@DanSnow DanSnow deleted the SPMVP-6969-add-unit-test-for-karbon-to-test-data-transform branch January 24, 2024 03:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants