diff --git a/scripts/db/validate.js b/scripts/db/validate.js index ec37fd63..496d5cb8 100644 --- a/scripts/db/validate.js +++ b/scripts/db/validate.js @@ -79,6 +79,10 @@ async function main() { for (const [i, row] of rows.entries()) { fileErrors = fileErrors.concat(validateCountryLanguage(row, i)) } + } else if (filename === 'subdivisions') { + for (const [i, row] of rows.entries()) { + fileErrors = fileErrors.concat(validateSubdivisionCountry(row, i)) + } } const schema = Joi.object(schemes[filename]) @@ -222,6 +226,18 @@ function validateCountryLanguage(row, i) { return errors } +function validateSubdivisionCountry(row, i) { + const errors = [] + if (!db.countries[row.country]) { + errors.push({ + line: i + 2, + message: `"${row.code}" has the wrong country "${row.country}"` + }) + } + + return errors +} + function handleError(message) { logger.error(chalk.red(`\n${message}`)) process.exit(1)