diff --git a/CHANGELOG.md b/CHANGELOG.md index 27a2e5287..f0cbea108 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased [patch] + +> Development of this release was supported by [Reset Tech](https://www.reset.tech). + +### Fixed + +- Fix declaration validation when a new service is added along with a filters file + ## 10.6.0 - 2026-01-26 > Development of this release was supported by [Reset Tech](https://www.reset.tech). diff --git a/scripts/declarations/utils/index.js b/scripts/declarations/utils/index.js index 6b3338a9c..ce9385aa5 100644 --- a/scripts/declarations/utils/index.js +++ b/scripts/declarations/utils/index.js @@ -50,6 +50,10 @@ export default class DeclarationUtils { if (modifiedFilePath.endsWith('.filters.js') || modifiedFilePath.endsWith('.filters.history.js')) { const declaration = await this.getJSONFromFile(this.defaultBranch, `declarations/${serviceId}.json`); + if (!declaration) { // Happens when the file declaration exists in the branch but not in the default branch + return; + } + servicesTermsTypes[serviceId] = Object.keys(declaration.terms); // Considering how rarely filters are used, simply return all term types that could potentially be impacted to spare implementing a function change check return; diff --git a/scripts/declarations/utils/index.test.js b/scripts/declarations/utils/index.test.js index c60babae0..2b26033b6 100644 --- a/scripts/declarations/utils/index.test.js +++ b/scripts/declarations/utils/index.test.js @@ -188,6 +188,23 @@ describe('DeclarationUtils', () => { }); }); + context('when a new declaration has been added along with a filters file', () => { + before(async () => { + await fs.writeFile(path.resolve(SUBJECT_PATH, COMMIT_PATHS.serviceB), JSON.stringify(FIXTURES.serviceB.content, null, 2)); + await fs.writeFile(path.resolve(SUBJECT_PATH, './declarations/ServiceB.filters.js'), 'module.exports = {};'); + await declarationUtils.git.add([ COMMIT_PATHS.serviceB, './declarations/ServiceB.filters.js' ]); + await declarationUtils.git.commit('Add declaration with filters for new service'); + }); + after(removeLatestCommit); + + it('returns the added service ID along with all its terms types', async () => { + expect(await declarationUtils.getModifiedServicesAndTermsTypes()).to.deep.equal({ + services: ['ServiceB'], + servicesTermsTypes: { ServiceB: ['Terms of Service'] }, + }); + }); + }); + context('when history file is modified without declaration changes', () => { before(() => commitChanges(COMMIT_PATHS.serviceAHistory, FIXTURES.serviceATermsUpdatedHistory.content)); after(removeLatestCommit);