Path: blob/main/tests/unit/schema-validation/schema-schema.test.ts
6456 views
/*1* schema-schema.test.ts2*3* Copyright (C) 2022 Posit Software, PBC4*5*/67import { assert } from "testing/asserts";8import { schemaPath } from "../../../src/core/schema/utils.ts";9import { getSchemaSchemas } from "../../../src/core/lib/yaml-schema/from-yaml.ts";10import { yamlValidationUnitTest } from "./utils.ts";11import {12arraySchema,13idSchema,14refSchema,15} from "../../../src/core/lib/yaml-schema/common.ts";16import { readAndValidateYamlFromFile } from "../../../src/core/schema/validated-yaml.ts";17import { expandGlobSync } from "../../../src/core/deno/expand-glob.ts";18import { readAndValidateYamlFromMappedString } from "../../../src/core/lib/yaml-schema/validated-yaml.ts";19import { asMappedString } from "../../../src/core/lib/mapped-text.ts";2021yamlValidationUnitTest("schema-schema-enum", async () => {22const _d = getSchemaSchemas(); // this registers the schema schema23const schemaSchema = refSchema("schema/object", "");2425const yamlStrs = [26`27object:28closed: true29super:30resolveRef: schema/base31properties:32enum:33anyOf:34- arrayOf:35ref: schema/scalar36- object:37super:38resolveRef: schema/base39properties:40values:41arrayOf:42ref: schema/scalar43`,44`45object:46properties:47properties:48object:49additionalProperties:50ref: schema/schema51additionalProperties:52ref: schema/schema`,53`54object:55properties:56apiUrl:57string:58description: The base URL of the service API.59authority:60string:61description: The domain name which the annotation service is associated with.62grantToken:63string:64description: An OAuth 2 grant token which the client can send to the service in order to get an access token for making authenticated requests to the service.65allowLeavingGroups:66boolean:67default: true68description: A flag indicating whether users should be able to leave groups of which they are a member.69enableShareLinks:70boolean:71default: true72description: A flag indicating whether annotation cards should show links that take the user to see an annotation in context.73groups:74anyOf:75- enum: ["$rpc:requestGroups"]76- arrayOf: string77description: An array of Group IDs or the literal string \`$rpc:requestGroups\`78icon:79string:80description: The URL to an image for the annotation service. This image will appear to the left of the name of the currently selected group.81required: [apiUrl, authority, grantToken]`,82`83object:84properties:85accentColor:86string:87description: Secondary color for elements of the commenting UI.88appBackgroundColor:89string:90description: The main background color of the commenting UI.91ctaBackgroundColor:92string:93description: The background color for call to action buttons.94selectionFontFamily:95string:96description: The font family for selection text in the annotation card.97annotationFontFamily:98string:99description: The font family for the actual annotation value that the user writes about the page or selection.100description: Settings to adjust the commenting sidebar's look and feel.101`,102];103104for (const yamlStr of yamlStrs) {105const result = await readAndValidateYamlFromMappedString(106asMappedString(yamlStr),107schemaSchema,108);109assert(result.yamlValidationErrors.length === 0);110}111});112113yamlValidationUnitTest("schema-schema", async () => {114const _d = getSchemaSchemas(); // this registers the schema schema115const yamlSchemaArray = idSchema(116arraySchema(refSchema("schema/schema", "")),117"schema-array",118);119120await readAndValidateYamlFromFile(121schemaPath("schema.yml"),122yamlSchemaArray,123"schema schema validation",124);125126await readAndValidateYamlFromFile(127schemaPath("definitions.yml"),128yamlSchemaArray,129"schema definitions",130);131});132133yamlValidationUnitTest("quarto-schemas", async () => {134const _d = getSchemaSchemas(); // this registers the schema schema135const schema = idSchema(136arraySchema(refSchema("schema/schema-field", "")),137"schema-field-array",138);139for (140const walk of expandGlobSync(schemaPath("{project,{cell,document}-*}.yml"))141) {142await readAndValidateYamlFromFile(143walk.path,144schema,145walk.path,146);147}148});149150151