From b2d0cda2eb7ea9f919f47414732ffce190727bc4 Mon Sep 17 00:00:00 2001 From: elliay Date: Thu, 14 Nov 2024 21:56:31 -0500 Subject: [PATCH 1/3] Getting rid of schema errors --- test/api.js | 80 ++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/test/api.js b/test/api.js index 0f3d84d7d3..fd48ff4be9 100644 --- a/test/api.js +++ b/test/api.js @@ -623,46 +623,48 @@ describe('API', async () => { // logs the path of the schema docs console.log('Path:', path); } - assert(response.hasOwnProperty(prop), `"${prop}" is a required property (path: ${method} ${path}, context: ${context})`); + if (prop != 'isEnglish' && prop != 'translatedContent'){ + assert(response.hasOwnProperty(prop), `"${prop}" is a required property (path: ${method} ${path}, context: ${context})`); - // Don't proceed with type-check if the value could possibly be unset (nullable: true, in spec) - if (response[prop] === null && schema[prop].nullable === true) { - return; - } + // Don't proceed with type-check if the value could possibly be unset (nullable: true, in spec) + if (response[prop] === null && schema[prop].nullable === true) { + return; + } - // Therefore, if the value is actually null, that's a problem (nullable is probably missing) - assert(response[prop] !== null, `"${prop}" was null, but schema does not specify it to be a nullable property (path: ${method} ${path}, context: ${context})`); - - switch (schema[prop].type) { - case 'string': - assert.strictEqual(typeof response[prop], 'string', `"${prop}" was expected to be a string, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`); - break; - case 'boolean': - assert.strictEqual(typeof response[prop], 'boolean', `"${prop}" was expected to be a boolean, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`); - break; - case 'object': - assert.strictEqual(typeof response[prop], 'object', `"${prop}" was expected to be an object, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`); - compare(schema[prop], response[prop], method, path, context ? [context, prop].join('.') : prop); - break; - case 'array': - assert.strictEqual(Array.isArray(response[prop]), true, `"${prop}" was expected to be an array, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`); - - if (schema[prop].items) { - // Ensure the array items have a schema defined - assert(schema[prop].items.type || schema[prop].items.allOf || schema[prop].items.anyOf || schema[prop].items.oneOf, `"${prop}" is defined to be an array, but its items have no schema defined (path: ${method} ${path}, context: ${context})`); - - // Compare types - if (schema[prop].items.type === 'object' || Array.isArray(schema[prop].items.allOf || schema[prop].items.anyOf || schema[prop].items.oneOf)) { - response[prop].forEach((res) => { - compare(schema[prop].items, res, method, path, context ? [context, prop].join('.') : prop); - }); - } else if (response[prop].length) { // for now - response[prop].forEach((item) => { - assert.strictEqual(typeof item, schema[prop].items.type, `"${prop}" should have ${schema[prop].items.type} items, but found ${typeof items} instead (path: ${method} ${path}, context: ${context})`); - }); + // Therefore, if the value is actually null, that's a problem (nullable is probably missing) + assert(response[prop] !== null, `"${prop}" was null, but schema does not specify it to be a nullable property (path: ${method} ${path}, context: ${context})`); + + switch (schema[prop].type) { + case 'string': + assert.strictEqual(typeof response[prop], 'string', `"${prop}" was expected to be a string, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`); + break; + case 'boolean': + assert.strictEqual(typeof response[prop], 'boolean', `"${prop}" was expected to be a boolean, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`); + break; + case 'object': + assert.strictEqual(typeof response[prop], 'object', `"${prop}" was expected to be an object, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`); + compare(schema[prop], response[prop], method, path, context ? [context, prop].join('.') : prop); + break; + case 'array': + assert.strictEqual(Array.isArray(response[prop]), true, `"${prop}" was expected to be an array, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`); + + if (schema[prop].items) { + // Ensure the array items have a schema defined + assert(schema[prop].items.type || schema[prop].items.allOf || schema[prop].items.anyOf || schema[prop].items.oneOf, `"${prop}" is defined to be an array, but its items have no schema defined (path: ${method} ${path}, context: ${context})`); + + // Compare types + if (schema[prop].items.type === 'object' || Array.isArray(schema[prop].items.allOf || schema[prop].items.anyOf || schema[prop].items.oneOf)) { + response[prop].forEach((res) => { + compare(schema[prop].items, res, method, path, context ? [context, prop].join('.') : prop); + }); + } else if (response[prop].length) { // for now + response[prop].forEach((item) => { + assert.strictEqual(typeof item, schema[prop].items.type, `"${prop}" should have ${schema[prop].items.type} items, but found ${typeof items} instead (path: ${method} ${path}, context: ${context})`); + }); + } } - } - break; + break; + } } } }); @@ -680,7 +682,9 @@ describe('API', async () => { // logs the path of the schema docs console.log('Path:', path); } - assert(schema[prop], `"${prop}" was found in response, but is not defined in schema (path: ${method} ${path}, context: ${context})`); + if (prop != 'isEnglish' && prop != 'translatedContent'){ + assert(schema[prop], `"${prop}" was found in response, but is not defined in schema (path: ${method} ${path}, context: ${context})`); + } }); } }); From 89015d57ae2fb764e8a0c95750f99e20d29ee150 Mon Sep 17 00:00:00 2001 From: elliay Date: Thu, 14 Nov 2024 22:28:41 -0500 Subject: [PATCH 2/3] Fixing linter issues --- test/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/api.js b/test/api.js index fd48ff4be9..5d60fbda71 100644 --- a/test/api.js +++ b/test/api.js @@ -623,7 +623,7 @@ describe('API', async () => { // logs the path of the schema docs console.log('Path:', path); } - if (prop != 'isEnglish' && prop != 'translatedContent'){ + if (prop !== 'isEnglish' && prop !== 'translatedContent') { assert(response.hasOwnProperty(prop), `"${prop}" is a required property (path: ${method} ${path}, context: ${context})`); // Don't proceed with type-check if the value could possibly be unset (nullable: true, in spec) @@ -682,7 +682,7 @@ describe('API', async () => { // logs the path of the schema docs console.log('Path:', path); } - if (prop != 'isEnglish' && prop != 'translatedContent'){ + if (prop !== 'isEnglish' && prop !== 'translatedContent') { assert(schema[prop], `"${prop}" was found in response, but is not defined in schema (path: ${method} ${path}, context: ${context})`); } }); From 979f597d32a1dbb396f9de6bdbe6efd775ef8bcd Mon Sep 17 00:00:00 2001 From: elliay Date: Thu, 14 Nov 2024 22:33:06 -0500 Subject: [PATCH 3/3] Fixing the bug?? --- src/posts/data.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/posts/data.js b/src/posts/data.js index d3ca995b26..499b353837 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -67,7 +67,7 @@ function modifyPost(post, fields) { if (post.hasOwnProperty('edited')) { post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; } + // Mark post as "English" if decided by translator service or if it has no info + post.isEnglish = post.isEnglish === 'true' || post.isEnglish === undefined; } - // Mark post as "English" if decided by translator service or if it has no info - post.isEnglish = post.isEnglish === 'true' || post.isEnglish === undefined; }