Skip to content

Commit 46d2dcf

Browse files
committed
Fix validation for new declaration with filters
1 parent 82238f4 commit 46d2dcf

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,26 @@ describe('DeclarationUtils', () => {
188188
});
189189
});
190190

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

0 commit comments

Comments
 (0)