Skip to content

Commit 4bacea4

Browse files
authored
Fix declarations validation when filters history is modified (#1192)
2 parents 0790559 + 1c11028 commit 4bacea4

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

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 the [French Ministry for Foreign Affairs](https://www.diplomatie.gouv.fr/fr/politique-etrangere-de-la-france/diplomatie-numerique/) through its ministerial [State Startups incubator](https://beta.gouv.fr/startups/open-terms-archive.html) under the aegis of the Ambassador for Digital Affairs.
8+
9+
### Fixed
10+
11+
- Fix declarations validation when filters history is modified
12+
513
## 7.2.2 - 2025-09-16
614

715
_Full changeset and discussions: [#1191](https://github.com/OpenTermsArchive/engine/pull/1191)._

scripts/declarations/utils/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class DeclarationUtils {
99
}
1010

1111
static getServiceIdFromFilePath(filePath) {
12-
return path.parse(filePath.replace(/\.history|\.filters/, '')).name;
12+
return path.parse(filePath.replace(/\.history|\.filters/g, '')).name;
1313
}
1414

1515
async getJSONFromFile(ref, filePath) {
@@ -47,7 +47,7 @@ export default class DeclarationUtils {
4747
return; // Assuming history modifications imply corresponding changes in the service declaration and that the analysis of which terms types of this service have changed will be done when analysing the related declaration, no further action is required here
4848
}
4949

50-
if (modifiedFilePath.endsWith('.filters.js')) {
50+
if (modifiedFilePath.endsWith('.filters.js') || modifiedFilePath.endsWith('.filters.history.js')) {
5151
const declaration = await this.getJSONFromFile(this.defaultBranch, `declarations/${serviceId}.json`);
5252

5353
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

scripts/declarations/utils/index.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ const removeLatestCommit = async () => {
3939
};
4040

4141
describe('DeclarationUtils', () => {
42+
describe('#getServiceIdFromFilePath', () => {
43+
it('extracts service ID from regular file path', () => {
44+
expect(DeclarationUtils.getServiceIdFromFilePath('declarations/ServiceA.json')).to.equal('ServiceA');
45+
});
46+
47+
it('extracts service ID from history file path', () => {
48+
expect(DeclarationUtils.getServiceIdFromFilePath('declarations/ServiceA.history.json')).to.equal('ServiceA');
49+
});
50+
51+
it('extracts service ID from filters file path', () => {
52+
expect(DeclarationUtils.getServiceIdFromFilePath('declarations/ServiceA.filters.js')).to.equal('ServiceA');
53+
});
54+
55+
it('extracts service ID from filters history file path', () => {
56+
expect(DeclarationUtils.getServiceIdFromFilePath('declarations/ServiceA.filters.history.js')).to.equal('ServiceA');
57+
});
58+
});
59+
4260
describe('#getModifiedServicesAndTermsTypes', () => {
4361
before(async () => {
4462
await loadFixtures();
@@ -137,6 +155,50 @@ describe('DeclarationUtils', () => {
137155
});
138156
});
139157
});
158+
159+
context('when filters file is modified', () => {
160+
before(async () => {
161+
await fs.writeFile(path.resolve(SUBJECT_PATH, './declarations/ServiceA.filters.js'), 'module.exports = {};');
162+
await declarationUtils.git.add('./declarations/ServiceA.filters.js');
163+
await declarationUtils.git.commit('Add filters file', './declarations/ServiceA.filters.js');
164+
});
165+
after(removeLatestCommit);
166+
167+
it('returns all terms types from the service declaration', async () => {
168+
const result = await declarationUtils.getModifiedServicesAndTermsTypes();
169+
170+
expect(result.services).to.include('ServiceA');
171+
expect(result.servicesTermsTypes.ServiceA).to.have.members([ 'Privacy Policy', 'Terms of Service' ]);
172+
});
173+
});
174+
175+
context('when filters history file is modified', () => {
176+
before(async () => {
177+
await fs.writeFile(path.resolve(SUBJECT_PATH, './declarations/ServiceA.filters.history.js'), 'module.exports = {};');
178+
await declarationUtils.git.add('./declarations/ServiceA.filters.history.js');
179+
await declarationUtils.git.commit('Add filters history file', './declarations/ServiceA.filters.history.js');
180+
});
181+
after(removeLatestCommit);
182+
183+
it('returns all terms types from the service declaration', async () => {
184+
const result = await declarationUtils.getModifiedServicesAndTermsTypes();
185+
186+
expect(result.services).to.include('ServiceA');
187+
expect(result.servicesTermsTypes.ServiceA).to.have.members([ 'Privacy Policy', 'Terms of Service' ]);
188+
});
189+
});
190+
191+
context('when history file is modified without declaration changes', () => {
192+
before(() => commitChanges(COMMIT_PATHS.serviceAHistory, FIXTURES.serviceATermsUpdatedHistory.content));
193+
after(removeLatestCommit);
194+
195+
it('returns no services and no terms types', async () => {
196+
expect(await declarationUtils.getModifiedServicesAndTermsTypes()).to.deep.equal({
197+
services: [],
198+
servicesTermsTypes: {},
199+
});
200+
});
201+
});
140202
});
141203
});
142204

0 commit comments

Comments
 (0)