Skip to content

Commit 2192140

Browse files
authored
Fix declaration validation when a new service is added along with a filters file (#1235)
2 parents 82238f4 + d9692ad commit 2192140

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
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).
44

5+
## Unreleased [patch]
6+
7+
> Development of this release was supported by [Reset Tech](https://www.reset.tech).
8+
9+
### Fixed
10+
11+
- Fix declaration validation when a new service is added along with a filters file
12+
513
## 10.6.0 - 2026-01-26
614

715
> Development of this release was supported by [Reset Tech](https://www.reset.tech).

scripts/declarations/utils/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export default class DeclarationUtils {
5050
if (modifiedFilePath.endsWith('.filters.js') || modifiedFilePath.endsWith('.filters.history.js')) {
5151
const declaration = await this.getJSONFromFile(this.defaultBranch, `declarations/${serviceId}.json`);
5252

53+
if (!declaration) { // Happens when the file declaration exists in the branch but not in the default branch
54+
return;
55+
}
56+
5357
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
5458

5559
return;

scripts/declarations/utils/index.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,23 @@ describe('DeclarationUtils', () => {
188188
});
189189
});
190190

191+
context('when a new declaration has been added along with a filters file', () => {
192+
before(async () => {
193+
await fs.writeFile(path.resolve(SUBJECT_PATH, COMMIT_PATHS.serviceB), JSON.stringify(FIXTURES.serviceB.content, null, 2));
194+
await fs.writeFile(path.resolve(SUBJECT_PATH, './declarations/ServiceB.filters.js'), 'module.exports = {};');
195+
await declarationUtils.git.add([ COMMIT_PATHS.serviceB, './declarations/ServiceB.filters.js' ]);
196+
await declarationUtils.git.commit('Add declaration with filters for new service');
197+
});
198+
after(removeLatestCommit);
199+
200+
it('returns the added service ID along with all its terms types', async () => {
201+
expect(await declarationUtils.getModifiedServicesAndTermsTypes()).to.deep.equal({
202+
services: ['ServiceB'],
203+
servicesTermsTypes: { ServiceB: ['Terms of Service'] },
204+
});
205+
});
206+
});
207+
191208
context('when history file is modified without declaration changes', () => {
192209
before(() => commitChanges(COMMIT_PATHS.serviceAHistory, FIXTURES.serviceATermsUpdatedHistory.content));
193210
after(removeLatestCommit);

0 commit comments

Comments
 (0)