Moved db testing to a seperate page

This commit is contained in:
DrMint 2022-04-23 21:47:59 +02:00
parent 427e44cdf4
commit a87f8abdf0
9 changed files with 594 additions and 558 deletions

4
.gitignore vendored
View File

@ -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

View File

@ -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)

View File

@ -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
);
}
}
}
}

592
src/pages/dev/checkup.tsx Normal file
View File

@ -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 <AppLayout navTitle={"Checkup"} {...props} />;
}
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
);
}
});
}

View File

@ -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
);
}
}

View File

@ -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
);
}
});
}

View File

@ -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.", "");

View File