From a87f8abdf059f331562d4be71ab8b5b738fca6fa Mon Sep 17 00:00:00 2001 From: DrMint Date: Sat, 23 Apr 2022 21:47:59 +0200 Subject: [PATCH] Moved db testing to a seperate page --- .gitignore | 4 - run_accords_testing.sh | 2 - src/pages/contents/[slug]/index.tsx | 104 +---- src/pages/dev/checkup.tsx | 592 ++++++++++++++++++++++++++++ src/pages/{ => dev}/editor.tsx | 0 src/pages/library/[slug]/index.tsx | 321 --------------- src/pages/wiki/chronology.tsx | 81 +--- src/queries/helpers.ts | 48 --- testing_logs/.gitkeep | 0 9 files changed, 594 insertions(+), 558 deletions(-) delete mode 100755 run_accords_testing.sh create mode 100644 src/pages/dev/checkup.tsx rename src/pages/{ => dev}/editor.tsx (100%) delete mode 100644 testing_logs/.gitkeep diff --git a/.gitignore b/.gitignore index d145973..c1491a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -/testing_logs/* - # Generated content src/graphql/generated.ts diff --git a/run_accords_testing.sh b/run_accords_testing.sh deleted file mode 100755 index 16243bf..0000000 --- a/run_accords_testing.sh +++ /dev/null @@ -1,2 +0,0 @@ -export ENABLE_TESTING_LOG=true -npx next build 2> >(tee ./testing_logs/$(date +"%Y-%m-%d---%H-%M-%S").stderr.tsv) 1> >(tee ./testing_logs/$(date +"%Y-%m-%d---%H-%M-%S").stdout.tsv) diff --git a/src/pages/contents/[slug]/index.tsx b/src/pages/contents/[slug]/index.tsx index cf6073e..16d50fb 100644 --- a/src/pages/contents/[slug]/index.tsx +++ b/src/pages/contents/[slug]/index.tsx @@ -29,8 +29,6 @@ import { prettyinlineTitle, prettyLanguage, prettySlug, - prettyTestError, - prettyTestWarning, } from "queries/helpers"; import { useEffect, useMemo, useState } from "react"; @@ -46,7 +44,6 @@ interface Props extends AppStaticProps { } export default function Content(props: Props): JSX.Element { - useTesting(props); const { langui, content, languages } = props; const router = useRouter(); const appLayout = useAppLayout(); @@ -316,7 +313,7 @@ export async function getStaticProps( context: GetStaticPropsContext ): Promise<{ notFound: boolean } | { props: Props }> { const sdk = getReadySdk(); - const slug = context.params?.slug?.toString() ?? ""; + const slug = context.params?.slug ? context.params.slug.toString() : ""; const content = await sdk.getContentText({ slug: slug, language_code: context.locale ?? "en", @@ -351,102 +348,3 @@ export async function getStaticPaths( fallback: "blocking", }; } - -function useTesting(props: Props) { - const router = useRouter(); - const { content, contentId } = props; - - const contentURL = `/admin/content-manager/collectionType/api::content.content/${contentId}`; - - if (router.locale === "en") { - if (content?.categories?.data.length === 0) { - prettyTestError(router, "Missing categories", ["content"], contentURL); - } - } - - if (content?.ranged_contents?.data.length === 0) { - prettyTestWarning( - router, - "Unconnected to any source", - ["content"], - contentURL - ); - } - - if (content?.text_set?.length === 0) { - prettyTestWarning( - router, - "Has no textset, nor audioset, nor videoset", - ["content"], - contentURL - ); - } - - if (content?.text_set && content.text_set.length > 1) { - prettyTestError( - router, - "More than one textset for this language", - ["content", "text_set"], - contentURL - ); - } - - if (content?.text_set?.length === 1) { - const textset = content.text_set[0]; - - if (!textset?.text) { - prettyTestError( - router, - "Missing text", - ["content", "text_set"], - contentURL - ); - } - if (!textset?.source_language?.data) { - prettyTestError( - router, - "Missing source language", - ["content", "text_set"], - contentURL - ); - } else if ( - textset.source_language.data.attributes?.code === router.locale - ) { - // This is a transcript - if (textset.transcribers?.data.length === 0) { - prettyTestError( - router, - "Missing transcribers attribution", - ["content", "text_set"], - contentURL - ); - } - if (textset.translators && textset.translators.data.length > 0) { - prettyTestError( - router, - "Transcripts shouldn't have translators", - ["content", "text_set"], - contentURL - ); - } - } else { - // This is a translation - if (textset.translators?.data.length === 0) { - prettyTestError( - router, - "Missing translators attribution", - ["content", "text_set"], - contentURL - ); - } - if (textset.transcribers && textset.transcribers.data.length > 0) { - prettyTestError( - router, - "Translations shouldn't have transcribers", - ["content", "text_set"], - contentURL - ); - } - } - } -} diff --git a/src/pages/dev/checkup.tsx b/src/pages/dev/checkup.tsx new file mode 100644 index 0000000..b4e78e2 --- /dev/null +++ b/src/pages/dev/checkup.tsx @@ -0,0 +1,592 @@ +import AppLayout from "components/AppLayout"; +import { + GetChronologyItemsQuery, + GetContentTextQuery, + GetErasQuery, + GetLibraryItemQuery, +} from "graphql/generated"; +import { GetStaticPropsContext } from "next"; +import { NextRouter, useRouter } from "next/router"; +import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps"; +import { sortContent } from "queries/helpers"; + +interface Props extends AppStaticProps {} + +export default function Checkup(props: Props): JSX.Element { + return ; +} + +export async function getStaticProps( + context: GetStaticPropsContext +): Promise<{ notFound: boolean } | { props: Props }> { + const props: Props = { + ...(await getAppStaticProps(context)), + }; + return { + props: props, + }; +} + +function prettyTestWarning( + router: NextRouter, + message: string, + subCategory: string[], + url: string +): void { + prettyTestWritter(TestingLevel.Warning, router, message, subCategory, url); +} + +function prettyTestError( + router: NextRouter, + message: string, + subCategory: string[], + url: string +): void { + prettyTestWritter(TestingLevel.Error, router, message, subCategory, url); +} + +enum TestingLevel { + Warning = "warn", + Error = "error", +} + +function prettyTestWritter( + level: TestingLevel, + { asPath, locale }: NextRouter, + message: string, + subCategory: string[], + url: string +): void { + const line = [ + level, + `${process.env.NEXT_PUBLIC_URL_SELF}/${locale}${asPath}`, + locale, + subCategory?.join(" -> "), + message, + process.env.NEXT_PUBLIC_URL_CMS + url, + ]; + + if (process.env.ENABLE_TESTING_LOG) { + if (level === TestingLevel.Warning) { + console.warn(line.join("\t")); + } else { + console.error(line.join("\t")); + } + } +} + +function useTestingContent(props: { + content: Exclude< + GetContentTextQuery["contents"], + null | undefined + >["data"][number]["attributes"]; + contentId: Exclude< + GetContentTextQuery["contents"], + null | undefined + >["data"][number]["id"]; +}) { + const router = useRouter(); + const { content, contentId } = props; + + const contentURL = `/admin/content-manager/collectionType/api::content.content/${contentId}`; + + if (router.locale === "en") { + if (content?.categories?.data.length === 0) { + prettyTestError(router, "Missing categories", ["content"], contentURL); + } + } + + if (content?.ranged_contents?.data.length === 0) { + prettyTestWarning( + router, + "Unconnected to any source", + ["content"], + contentURL + ); + } + + if (content?.text_set?.length === 0) { + prettyTestWarning( + router, + "Has no textset, nor audioset, nor videoset", + ["content"], + contentURL + ); + } + + if (content?.text_set && content.text_set.length > 1) { + prettyTestError( + router, + "More than one textset for this language", + ["content", "text_set"], + contentURL + ); + } + + if (content?.text_set?.length === 1) { + const textset = content.text_set[0]; + + if (!textset?.text) { + prettyTestError( + router, + "Missing text", + ["content", "text_set"], + contentURL + ); + } + if (!textset?.source_language?.data) { + prettyTestError( + router, + "Missing source language", + ["content", "text_set"], + contentURL + ); + } else if ( + textset.source_language.data.attributes?.code === router.locale + ) { + // This is a transcript + if (textset.transcribers?.data.length === 0) { + prettyTestError( + router, + "Missing transcribers attribution", + ["content", "text_set"], + contentURL + ); + } + if (textset.translators && textset.translators.data.length > 0) { + prettyTestError( + router, + "Transcripts shouldn't have translators", + ["content", "text_set"], + contentURL + ); + } + } else { + // This is a translation + if (textset.translators?.data.length === 0) { + prettyTestError( + router, + "Missing translators attribution", + ["content", "text_set"], + contentURL + ); + } + if (textset.transcribers && textset.transcribers.data.length > 0) { + prettyTestError( + router, + "Translations shouldn't have transcribers", + ["content", "text_set"], + contentURL + ); + } + } + } +} + +function useTestingLibrary(props: { + item: Exclude< + GetLibraryItemQuery["libraryItems"], + null | undefined + >["data"][number]["attributes"]; + itemId: Exclude< + GetLibraryItemQuery["libraryItems"], + null | undefined + >["data"][number]["id"]; +}) { + const { item, itemId } = props; + const router = useRouter(); + + const libraryItemURL = `/admin/content-manager/collectionType/api::library-item.library-item/${itemId}`; + + sortContent(item?.contents); + + if (router.locale === "en") { + if (!item?.thumbnail?.data) { + prettyTestError( + router, + "Missing thumbnail", + ["libraryItem"], + libraryItemURL + ); + } + if (item?.metadata?.length === 0) { + prettyTestError( + router, + "Missing metadata", + ["libraryItem"], + libraryItemURL + ); + } else if ( + item?.metadata?.[0]?.__typename === "ComponentMetadataGroup" && + (item.metadata[0].subtype?.data?.attributes?.slug === "relation-set" || + item.metadata[0].subtype?.data?.attributes?.slug === "variant-set") + ) { + // This is a group type item + if (item.price) { + prettyTestError( + router, + "Group-type items shouldn't have price", + ["libraryItem"], + libraryItemURL + ); + } + if (item.size) { + prettyTestError( + router, + "Group-type items shouldn't have size", + ["libraryItem"], + libraryItemURL + ); + } + if (item.release_date) { + prettyTestError( + router, + "Group-type items shouldn't have release_date", + ["libraryItem"], + libraryItemURL + ); + } + if (item.contents && item.contents.data.length > 0) { + prettyTestError( + router, + "Group-type items shouldn't have contents", + ["libraryItem"], + libraryItemURL + ); + } + if (item.subitems && item.subitems.data.length === 0) { + prettyTestError( + router, + "Group-type items should have subitems", + ["libraryItem"], + libraryItemURL + ); + } + } else { + // This is a normal item + + if (item?.metadata?.[0]?.__typename === "ComponentMetadataGroup") { + if (item.subitems?.data.length === 0) { + prettyTestError( + router, + "Group-type item should have subitems", + ["libraryItem"], + libraryItemURL + ); + } + } + + if (item?.price) { + if (!item.price.amount) { + prettyTestError( + router, + "Missing amount", + ["libraryItem", "price"], + libraryItemURL + ); + } + if (!item.price.currency) { + prettyTestError( + router, + "Missing currency", + ["libraryItem", "price"], + libraryItemURL + ); + } + } else { + prettyTestWarning( + router, + "Missing price", + ["libraryItem"], + libraryItemURL + ); + } + + if (!item?.digital) { + if (item?.size) { + if (!item.size.width) { + prettyTestWarning( + router, + "Missing width", + ["libraryItem", "size"], + libraryItemURL + ); + } + if (!item.size.height) { + prettyTestWarning( + router, + "Missing height", + ["libraryItem", "size"], + libraryItemURL + ); + } + if (!item.size.thickness) { + prettyTestWarning( + router, + "Missing thickness", + ["libraryItem", "size"], + libraryItemURL + ); + } + } else { + prettyTestWarning( + router, + "Missing size", + ["libraryItem"], + libraryItemURL + ); + } + } + + if (item?.release_date) { + if (!item.release_date.year) { + prettyTestError( + router, + "Missing year", + ["libraryItem", "release_date"], + libraryItemURL + ); + } + if (!item.release_date.month) { + prettyTestError( + router, + "Missing month", + ["libraryItem", "release_date"], + libraryItemURL + ); + } + if (!item.release_date.day) { + prettyTestError( + router, + "Missing day", + ["libraryItem", "release_date"], + libraryItemURL + ); + } + } else { + prettyTestWarning( + router, + "Missing release_date", + ["libraryItem"], + libraryItemURL + ); + } + + if (item?.contents?.data.length === 0) { + prettyTestWarning( + router, + "Missing contents", + ["libraryItem"], + libraryItemURL + ); + } else { + let currentRangePage = 0; + item?.contents?.data.map((content) => { + const contentURL = `/admin/content-manager/collectionType/api::content.content/${content.id}`; + + if (content.attributes?.scan_set?.length === 0) { + prettyTestWarning( + router, + "Missing scan_set", + ["libraryItem", "content", content.id ?? ""], + contentURL + ); + } + if (content.attributes?.range.length === 0) { + prettyTestWarning( + router, + "Missing range", + ["libraryItem", "content", content.id ?? ""], + contentURL + ); + } else if ( + content.attributes?.range[0]?.__typename === + "ComponentRangePageRange" + ) { + if ( + content.attributes.range[0].starting_page < + currentRangePage + 1 + ) { + prettyTestError( + router, + `Overlapping pages ${content.attributes.range[0].starting_page} to ${currentRangePage}`, + ["libraryItem", "content", content.id ?? "", "range"], + libraryItemURL + ); + } else if ( + content.attributes.range[0].starting_page > + currentRangePage + 1 + ) { + prettyTestError( + router, + `Missing pages ${currentRangePage + 1} to ${ + content.attributes.range[0].starting_page - 1 + }`, + ["libraryItem", "content", content.id ?? "", "range"], + libraryItemURL + ); + } + + if (!content.attributes.content?.data) { + prettyTestWarning( + router, + "Missing content", + ["libraryItem", "content", content.id ?? "", "range"], + libraryItemURL + ); + } + + currentRangePage = content.attributes.range[0].ending_page; + } + }); + + if (item?.metadata?.[0]?.__typename === "ComponentMetadataBooks") { + if (item.metadata[0].languages?.data.length === 0) { + prettyTestWarning( + router, + "Missing language", + ["libraryItem", "metadata"], + libraryItemURL + ); + } + + if (item.metadata[0].page_count) { + if (currentRangePage < item.metadata[0].page_count) { + prettyTestError( + router, + `Missing pages ${currentRangePage + 1} to ${ + item.metadata[0].page_count + }`, + ["libraryItem", "content"], + libraryItemURL + ); + } else if (currentRangePage > item.metadata[0].page_count) { + prettyTestError( + router, + `Page overflow, content references pages up to ${currentRangePage} when the highest expected was ${item.metadata[0].page_count}`, + ["libraryItem", "content"], + libraryItemURL + ); + } + } else { + prettyTestWarning( + router, + "Missing page_count", + ["libraryItem", "metadata"], + libraryItemURL + ); + } + } + } + } + + if (!item?.root_item && item?.subitem_of?.data.length === 0) { + prettyTestError( + router, + "This item is inaccessible (not root item and not subitem of another item)", + ["libraryItem"], + libraryItemURL + ); + } + + if (item?.gallery?.data.length === 0) { + prettyTestWarning( + router, + "Missing gallery", + ["libraryItem"], + libraryItemURL + ); + } + } + + if (item?.descriptions?.length === 0) { + prettyTestWarning( + router, + "Missing description", + ["libraryItem"], + libraryItemURL + ); + } +} + +function useTestingChronology(props: { + chronologyItems: Exclude< + GetChronologyItemsQuery["chronologyItems"], + null | undefined + >["data"]; + chronologyEras: Exclude< + GetErasQuery["chronologyEras"], + null | undefined + >["data"]; +}) { + const router = useRouter(); + const { chronologyItems, chronologyEras } = props; + chronologyEras.map((era) => { + const chronologyErasURL = `/admin/content-manager/collectionType/api::chronology-era.chronology-era/${chronologyItems[0].id}`; + + if (era.attributes?.title?.length === 0) { + prettyTestError( + router, + "Missing translation for title and description, using slug instead", + ["chronologyEras", era.attributes.slug], + chronologyErasURL + ); + } else if (era.attributes?.title && era.attributes.title.length > 1) { + prettyTestError( + router, + "More than one title and description", + ["chronologyEras", era.attributes.slug], + chronologyErasURL + ); + } else { + if (!era.attributes?.title?.[0]?.title) + prettyTestError( + router, + "Missing title, using slug instead", + ["chronologyEras", era.attributes?.slug ?? ""], + chronologyErasURL + ); + if (!era.attributes?.title?.[0]?.description) + prettyTestError( + router, + "Missing description", + ["chronologyEras", era.attributes?.slug ?? ""], + chronologyErasURL + ); + } + }); + + chronologyItems.map((item) => { + const chronologyItemsURL = `/admin/content-manager/collectionType/api::chronology-item.chronology-item/${chronologyItems[0].id}`; + + const date = `${item.attributes?.year}/${item.attributes?.month}/${item.attributes?.day}`; + + if (item.attributes?.events && item.attributes.events.length > 0) { + item.attributes.events.map((event) => { + if (!event?.source?.data) { + prettyTestError( + router, + "No source for this event", + ["chronologyItems", date, event?.id ?? ""], + chronologyItemsURL + ); + } + if (!(event?.translations && event.translations.length > 0)) { + prettyTestWarning( + router, + "No translation for this event", + ["chronologyItems", date, event?.id ?? ""], + chronologyItemsURL + ); + } + }); + } else { + prettyTestError( + router, + "No events for this date", + ["chronologyItems", date], + chronologyItemsURL + ); + } + }); +} diff --git a/src/pages/editor.tsx b/src/pages/dev/editor.tsx similarity index 100% rename from src/pages/editor.tsx rename to src/pages/dev/editor.tsx diff --git a/src/pages/library/[slug]/index.tsx b/src/pages/library/[slug]/index.tsx index b840117..b1e4fb9 100644 --- a/src/pages/library/[slug]/index.tsx +++ b/src/pages/library/[slug]/index.tsx @@ -27,7 +27,6 @@ import { GetStaticPathsResult, GetStaticPropsContext, } from "next"; -import { useRouter } from "next/router"; import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps"; import { convertMmToInch, @@ -36,8 +35,6 @@ import { prettyItemSubType, prettyItemType, prettyPrice, - prettyTestError, - prettyTestWarning, prettyURL, sortContent, } from "queries/helpers"; @@ -55,7 +52,6 @@ interface Props extends AppStaticProps { } export default function LibrarySlug(props: Props): JSX.Element { - useTesting(props); const { item, langui, currencies } = props; const appLayout = useAppLayout(); @@ -541,320 +537,3 @@ export async function getStaticPaths( fallback: "blocking", }; } - -function useTesting(props: Props) { - const { item, itemId } = props; - const router = useRouter(); - - const libraryItemURL = `/admin/content-manager/collectionType/api::library-item.library-item/${itemId}`; - - sortContent(item?.contents); - - if (router.locale === "en") { - if (!item?.thumbnail?.data) { - prettyTestError( - router, - "Missing thumbnail", - ["libraryItem"], - libraryItemURL - ); - } - if (item?.metadata?.length === 0) { - prettyTestError( - router, - "Missing metadata", - ["libraryItem"], - libraryItemURL - ); - } else if ( - item?.metadata?.[0]?.__typename === "ComponentMetadataGroup" && - (item.metadata[0].subtype?.data?.attributes?.slug === "relation-set" || - item.metadata[0].subtype?.data?.attributes?.slug === "variant-set") - ) { - // This is a group type item - if (item.price) { - prettyTestError( - router, - "Group-type items shouldn't have price", - ["libraryItem"], - libraryItemURL - ); - } - if (item.size) { - prettyTestError( - router, - "Group-type items shouldn't have size", - ["libraryItem"], - libraryItemURL - ); - } - if (item.release_date) { - prettyTestError( - router, - "Group-type items shouldn't have release_date", - ["libraryItem"], - libraryItemURL - ); - } - if (item.contents && item.contents.data.length > 0) { - prettyTestError( - router, - "Group-type items shouldn't have contents", - ["libraryItem"], - libraryItemURL - ); - } - if (item.subitems && item.subitems.data.length === 0) { - prettyTestError( - router, - "Group-type items should have subitems", - ["libraryItem"], - libraryItemURL - ); - } - } else { - // This is a normal item - - if (item?.metadata?.[0]?.__typename === "ComponentMetadataGroup") { - if (item.subitems?.data.length === 0) { - prettyTestError( - router, - "Group-type item should have subitems", - ["libraryItem"], - libraryItemURL - ); - } - } - - if (item?.price) { - if (!item.price.amount) { - prettyTestError( - router, - "Missing amount", - ["libraryItem", "price"], - libraryItemURL - ); - } - if (!item.price.currency) { - prettyTestError( - router, - "Missing currency", - ["libraryItem", "price"], - libraryItemURL - ); - } - } else { - prettyTestWarning( - router, - "Missing price", - ["libraryItem"], - libraryItemURL - ); - } - - if (!item?.digital) { - if (item?.size) { - if (!item.size.width) { - prettyTestWarning( - router, - "Missing width", - ["libraryItem", "size"], - libraryItemURL - ); - } - if (!item.size.height) { - prettyTestWarning( - router, - "Missing height", - ["libraryItem", "size"], - libraryItemURL - ); - } - if (!item.size.thickness) { - prettyTestWarning( - router, - "Missing thickness", - ["libraryItem", "size"], - libraryItemURL - ); - } - } else { - prettyTestWarning( - router, - "Missing size", - ["libraryItem"], - libraryItemURL - ); - } - } - - if (item?.release_date) { - if (!item.release_date.year) { - prettyTestError( - router, - "Missing year", - ["libraryItem", "release_date"], - libraryItemURL - ); - } - if (!item.release_date.month) { - prettyTestError( - router, - "Missing month", - ["libraryItem", "release_date"], - libraryItemURL - ); - } - if (!item.release_date.day) { - prettyTestError( - router, - "Missing day", - ["libraryItem", "release_date"], - libraryItemURL - ); - } - } else { - prettyTestWarning( - router, - "Missing release_date", - ["libraryItem"], - libraryItemURL - ); - } - - if (item?.contents?.data.length === 0) { - prettyTestWarning( - router, - "Missing contents", - ["libraryItem"], - libraryItemURL - ); - } else { - let currentRangePage = 0; - item?.contents?.data.map((content) => { - const contentURL = `/admin/content-manager/collectionType/api::content.content/${content.id}`; - - if (content.attributes?.scan_set?.length === 0) { - prettyTestWarning( - router, - "Missing scan_set", - ["libraryItem", "content", content.id ?? ""], - contentURL - ); - } - if (content.attributes?.range.length === 0) { - prettyTestWarning( - router, - "Missing range", - ["libraryItem", "content", content.id ?? ""], - contentURL - ); - } else if ( - content.attributes?.range[0]?.__typename === - "ComponentRangePageRange" - ) { - if ( - content.attributes.range[0].starting_page < - currentRangePage + 1 - ) { - prettyTestError( - router, - `Overlapping pages ${content.attributes.range[0].starting_page} to ${currentRangePage}`, - ["libraryItem", "content", content.id ?? "", "range"], - libraryItemURL - ); - } else if ( - content.attributes.range[0].starting_page > - currentRangePage + 1 - ) { - prettyTestError( - router, - `Missing pages ${currentRangePage + 1} to ${ - content.attributes.range[0].starting_page - 1 - }`, - ["libraryItem", "content", content.id ?? "", "range"], - libraryItemURL - ); - } - - if (!content.attributes.content?.data) { - prettyTestWarning( - router, - "Missing content", - ["libraryItem", "content", content.id ?? "", "range"], - libraryItemURL - ); - } - - currentRangePage = content.attributes.range[0].ending_page; - } - }); - - if (item?.metadata?.[0]?.__typename === "ComponentMetadataBooks") { - if (item.metadata[0].languages?.data.length === 0) { - prettyTestWarning( - router, - "Missing language", - ["libraryItem", "metadata"], - libraryItemURL - ); - } - - if (item.metadata[0].page_count) { - if (currentRangePage < item.metadata[0].page_count) { - prettyTestError( - router, - `Missing pages ${currentRangePage + 1} to ${ - item.metadata[0].page_count - }`, - ["libraryItem", "content"], - libraryItemURL - ); - } else if (currentRangePage > item.metadata[0].page_count) { - prettyTestError( - router, - `Page overflow, content references pages up to ${currentRangePage} when the highest expected was ${item.metadata[0].page_count}`, - ["libraryItem", "content"], - libraryItemURL - ); - } - } else { - prettyTestWarning( - router, - "Missing page_count", - ["libraryItem", "metadata"], - libraryItemURL - ); - } - } - } - } - - if (!item?.root_item && item?.subitem_of?.data.length === 0) { - prettyTestError( - router, - "This item is inaccessible (not root item and not subitem of another item)", - ["libraryItem"], - libraryItemURL - ); - } - - if (item?.gallery?.data.length === 0) { - prettyTestWarning( - router, - "Missing gallery", - ["libraryItem"], - libraryItemURL - ); - } - } - - if (item?.descriptions?.length === 0) { - prettyTestWarning( - router, - "Missing description", - ["libraryItem"], - libraryItemURL - ); - } -} diff --git a/src/pages/wiki/chronology.tsx b/src/pages/wiki/chronology.tsx index 8d46fe7..6fcbe6b 100644 --- a/src/pages/wiki/chronology.tsx +++ b/src/pages/wiki/chronology.tsx @@ -11,13 +11,8 @@ import { useAppLayout } from "contexts/AppLayoutContext"; import { GetChronologyItemsQuery, GetErasQuery } from "graphql/generated"; import { getReadySdk } from "graphql/sdk"; import { GetStaticPropsContext } from "next"; -import { useRouter } from "next/router"; import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps"; -import { - prettySlug, - prettyTestError, - prettyTestWarning, -} from "queries/helpers"; +import { prettySlug } from "queries/helpers"; interface Props extends AppStaticProps { chronologyItems: Exclude< @@ -31,7 +26,6 @@ interface Props extends AppStaticProps { } export default function Chronology(props: Props): JSX.Element { - useTesting(props); const { chronologyItems, chronologyEras, langui } = props; const appLayout = useAppLayout(); @@ -177,76 +171,3 @@ export async function getStaticProps( props: props, }; } - -function useTesting(props: Props) { - const router = useRouter(); - const { chronologyItems, chronologyEras } = props; - chronologyEras.map((era) => { - const chronologyErasURL = `/admin/content-manager/collectionType/api::chronology-era.chronology-era/${chronologyItems[0].id}`; - - if (era.attributes?.title?.length === 0) { - prettyTestError( - router, - "Missing translation for title and description, using slug instead", - ["chronologyEras", era.attributes.slug], - chronologyErasURL - ); - } else if (era.attributes?.title && era.attributes.title.length > 1) { - prettyTestError( - router, - "More than one title and description", - ["chronologyEras", era.attributes.slug], - chronologyErasURL - ); - } else { - if (!era.attributes?.title?.[0]?.title) - prettyTestError( - router, - "Missing title, using slug instead", - ["chronologyEras", era.attributes?.slug ?? ""], - chronologyErasURL - ); - if (!era.attributes?.title?.[0]?.description) - prettyTestError( - router, - "Missing description", - ["chronologyEras", era.attributes?.slug ?? ""], - chronologyErasURL - ); - } - }); - - chronologyItems.map((item) => { - const chronologyItemsURL = `/admin/content-manager/collectionType/api::chronology-item.chronology-item/${chronologyItems[0].id}`; - - const date = `${item.attributes?.year}/${item.attributes?.month}/${item.attributes?.day}`; - - if (item.attributes?.events && item.attributes.events.length > 0) { - item.attributes.events.map((event) => { - if (!event?.source?.data) { - prettyTestError( - router, - "No source for this event", - ["chronologyItems", date, event?.id ?? ""], - chronologyItemsURL - ); - } - if (!(event?.translations && event.translations.length > 0)) { - prettyTestWarning( - router, - "No translation for this event", - ["chronologyItems", date, event?.id ?? ""], - chronologyItemsURL - ); - } - }); - } else { - prettyTestError( - router, - "No events for this date", - ["chronologyItems", date], - chronologyItemsURL - ); - } - }); -} diff --git a/src/queries/helpers.ts b/src/queries/helpers.ts index d67ab32..3e4d0a9 100644 --- a/src/queries/helpers.ts +++ b/src/queries/helpers.ts @@ -286,54 +286,6 @@ export function prettyLanguageToCode( return result; } -export function prettyTestWarning( - router: NextRouter, - message: string, - subCategory: string[], - url: string -): void { - prettyTestWritter(TestingLevel.Warning, router, message, subCategory, url); -} - -export function prettyTestError( - router: NextRouter, - message: string, - subCategory: string[], - url: string -): void { - prettyTestWritter(TestingLevel.Error, router, message, subCategory, url); -} - -enum TestingLevel { - Warning = "warn", - Error = "error", -} - -function prettyTestWritter( - level: TestingLevel, - { asPath, locale }: NextRouter, - message: string, - subCategory: string[], - url: string -): void { - const line = [ - level, - `${process.env.NEXT_PUBLIC_URL_SELF}/${locale}${asPath}`, - locale, - subCategory?.join(" -> "), - message, - process.env.NEXT_PUBLIC_URL_CMS + url, - ]; - - if (process.env.ENABLE_TESTING_LOG) { - if (level === TestingLevel.Warning) { - console.warn(line.join("\t")); - } else { - console.error(line.join("\t")); - } - } -} - export function prettyURL(url: string): string { let domain = new URL(url); return domain.hostname.replace("www.", ""); diff --git a/testing_logs/.gitkeep b/testing_logs/.gitkeep deleted file mode 100644 index e69de29..0000000