@opentermsarchive/engine 7.2.2 → 7.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentermsarchive/engine",
3
- "version": "7.2.2",
3
+ "version": "7.2.3",
4
4
  "description": "Tracks and makes visible changes to the terms of online services",
5
5
  "homepage": "https://opentermsarchive.org",
6
6
  "bugs": {
@@ -9,7 +9,7 @@ export default class DeclarationUtils {
9
9
  }
10
10
 
11
11
  static getServiceIdFromFilePath(filePath) {
12
- return path.parse(filePath.replace(/\.history|\.filters/, '')).name;
12
+ return path.parse(filePath.replace(/\.history|\.filters/g, '')).name;
13
13
  }
14
14
 
15
15
  async getJSONFromFile(ref, filePath) {
@@ -47,7 +47,7 @@ export default class DeclarationUtils {
47
47
  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
48
48
  }
49
49
 
50
- if (modifiedFilePath.endsWith('.filters.js')) {
50
+ if (modifiedFilePath.endsWith('.filters.js') || modifiedFilePath.endsWith('.filters.history.js')) {
51
51
  const declaration = await this.getJSONFromFile(this.defaultBranch, `declarations/${serviceId}.json`);
52
52
 
53
53
  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
@@ -39,6 +39,24 @@ const removeLatestCommit = async () => {
39
39
  };
40
40
 
41
41
  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
+
42
60
  describe('#getModifiedServicesAndTermsTypes', () => {
43
61
  before(async () => {
44
62
  await loadFixtures();
@@ -137,6 +155,50 @@ describe('DeclarationUtils', () => {
137
155
  });
138
156
  });
139
157
  });
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
+ });
140
202
  });
141
203
  });
142
204