@opentermsarchive/engine 1.1.3 → 1.2.0

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.
@@ -7,26 +7,28 @@ const { expect } = chai;
7
7
 
8
8
  describe('Service', () => {
9
9
  let subject;
10
- const TERMS_TYPE = 'Terms of Service';
10
+ const TERMS_OF_SERVICE_TYPE = 'Terms of Service';
11
+ const PRIVACY_POLICY_TYPE = 'Privacy Policy';
12
+ const IMPRINT_TYPE = 'Imprint';
11
13
 
12
14
  describe('#addTerms', () => {
13
15
  let terms;
14
16
 
15
- before(async () => {
17
+ before(() => {
18
+ subject = new Service({ id: 'serviceID', name: 'serviceName' });
16
19
  terms = new Terms({
17
- type: TERMS_TYPE,
20
+ type: TERMS_OF_SERVICE_TYPE,
18
21
  service: subject,
19
22
  });
20
23
  });
21
24
 
22
25
  context('when terms have no validity date', () => {
23
- before(async () => {
24
- subject = new Service({ id: 'serviceID', name: 'serviceName' });
26
+ before(() => {
25
27
  subject.addTerms(terms);
26
28
  });
27
29
 
28
- it('adds the terms as the last valid terms', async () => {
29
- expect(subject.getTerms({ type: TERMS_TYPE })).to.deep.eql(terms);
30
+ it('adds the terms as the last valid terms', () => {
31
+ expect(subject.getTerms({ type: TERMS_OF_SERVICE_TYPE })).to.deep.eql(terms);
30
32
  });
31
33
  });
32
34
 
@@ -34,10 +36,9 @@ describe('Service', () => {
34
36
  let expiredTerms;
35
37
  const VALIDITY_DATE = new Date('2020-07-22T11:30:21.000Z');
36
38
 
37
- before(async () => {
38
- subject = new Service({ id: 'serviceID', name: 'serviceName' });
39
+ before(() => {
39
40
  expiredTerms = new Terms({
40
- type: TERMS_TYPE,
41
+ type: TERMS_OF_SERVICE_TYPE,
41
42
  service: subject,
42
43
  validUntil: VALIDITY_DATE,
43
44
  });
@@ -45,8 +46,8 @@ describe('Service', () => {
45
46
  subject.addTerms(terms);
46
47
  });
47
48
 
48
- it('adds the terms with the proper validity date', async () => {
49
- expect(subject.getTerms({ type: TERMS_TYPE, date: VALIDITY_DATE })).to.deep.eql(expiredTerms);
49
+ it('adds the terms with the proper validity date', () => {
50
+ expect(subject.getTerms({ type: TERMS_OF_SERVICE_TYPE, date: VALIDITY_DATE })).to.deep.eql(expiredTerms);
50
51
  });
51
52
  });
52
53
  });
@@ -58,15 +59,15 @@ describe('Service', () => {
58
59
  const DATE = '2020-07-22T11:30:21.000Z';
59
60
  const LATEST_DATE = '2020-08-21T11:30:21.000Z';
60
61
 
61
- const firstTermsOfService = new Terms({ type: TERMS_TYPE, validUntil: DATE });
62
+ const firstTermsOfService = new Terms({ type: TERMS_OF_SERVICE_TYPE, validUntil: DATE });
62
63
  const firstPrivacyPolicy = new Terms({ type: 'Privacy Policy', validUntil: DATE });
63
64
 
64
- const latestTermsOfService = new Terms({ type: TERMS_TYPE });
65
+ const latestTermsOfService = new Terms({ type: TERMS_OF_SERVICE_TYPE });
65
66
  const latestPrivacyPolicy = new Terms({ type: 'Privacy Policy' });
66
67
 
67
68
  const latestDeveloperTerms = new Terms({ type: 'Developer Terms' });
68
69
 
69
- before(async () => {
70
+ before(() => {
70
71
  subject = new Service({ id: 'serviceID', name: 'serviceName' });
71
72
  subject.addTerms(firstTermsOfService);
72
73
  subject.addTerms(firstPrivacyPolicy);
@@ -76,7 +77,7 @@ describe('Service', () => {
76
77
  });
77
78
 
78
79
  context('when no params are given', () => {
79
- it('returns all latest terms', async () => {
80
+ it('returns all latest terms', () => {
80
81
  expect(subject.getTerms()).to.deep.eql([ latestTermsOfService, latestPrivacyPolicy, latestDeveloperTerms ]);
81
82
  });
82
83
  });
@@ -84,45 +85,45 @@ describe('Service', () => {
84
85
  context('when a terms type is given', () => {
85
86
  context('when a date is given', () => {
86
87
  context('when the terms has no history', () => {
87
- it('returns the latest terms according to the given type', async () => {
88
+ it('returns the latest terms according to the given type', () => {
88
89
  expect(subject.getTerms({ type: 'Developer Terms', date: LATEST_DATE })).to.eql(latestDeveloperTerms);
89
90
  });
90
91
  });
91
92
 
92
93
  context('when the terms have a history', () => {
93
- it('returns the terms according to the given type and date', async () => {
94
- expect(subject.getTerms({ type: TERMS_TYPE, date: EARLIEST_DATE })).to.eql(firstTermsOfService);
94
+ it('returns the terms according to the given type and date', () => {
95
+ expect(subject.getTerms({ type: TERMS_OF_SERVICE_TYPE, date: EARLIEST_DATE })).to.eql(firstTermsOfService);
95
96
  });
96
97
 
97
98
  context('when the given date is strictly equal to a terms validity date', () => {
98
- it('returns the terms according to the given type with the validity date equal to the given date', async () => {
99
- expect(subject.getTerms({ type: TERMS_TYPE, date: DATE })).to.eql(firstTermsOfService);
99
+ it('returns the terms according to the given type with the validity date equal to the given date', () => {
100
+ expect(subject.getTerms({ type: TERMS_OF_SERVICE_TYPE, date: DATE })).to.eql(firstTermsOfService);
100
101
  });
101
102
  });
102
103
  });
103
104
  });
104
105
 
105
106
  context('without a given date', () => {
106
- it('returns the latest terms of given type', async () => {
107
- expect(subject.getTerms({ type: TERMS_TYPE })).to.eql(latestTermsOfService);
107
+ it('returns the latest terms of given type', () => {
108
+ expect(subject.getTerms({ type: TERMS_OF_SERVICE_TYPE })).to.eql(latestTermsOfService);
108
109
  });
109
110
  });
110
111
  });
111
112
 
112
113
  context('when only a date is given', () => {
113
114
  context('when there is no history', () => {
114
- it('returns all latest terms', async () => {
115
+ it('returns all latest terms', () => {
115
116
  expect(subject.getTerms({ date: LATEST_DATE })).to.deep.eql([ latestTermsOfService, latestPrivacyPolicy, latestDeveloperTerms ]);
116
117
  });
117
118
  });
118
119
 
119
120
  context('when the terms have a history', () => {
120
- it('returns all the terms according to the given date', async () => {
121
+ it('returns all the terms according to the given date', () => {
121
122
  expect(subject.getTerms({ date: EARLIEST_DATE })).to.deep.eql([ firstTermsOfService, firstPrivacyPolicy, latestDeveloperTerms ]);
122
123
  });
123
124
 
124
125
  context('when the given date is strictly equal to a terms validity date', () => {
125
- it('returns all the terms with the validity date equal to the given date', async () => {
126
+ it('returns all the terms with the validity date equal to the given date', () => {
126
127
  expect(subject.getTerms({ date: DATE })).to.deep.eql([ firstTermsOfService, firstPrivacyPolicy, latestDeveloperTerms ]);
127
128
  });
128
129
  });
@@ -131,29 +132,49 @@ describe('Service', () => {
131
132
  });
132
133
 
133
134
  describe('#getTermsTypes', () => {
134
- let subject;
135
135
  let termsOfService;
136
136
  let privacyPolicy;
137
137
 
138
- before(async () => {
138
+ before(() => {
139
139
  subject = new Service({ id: 'serviceID', name: 'serviceName' });
140
140
 
141
- termsOfService = new Terms({ type: TERMS_TYPE });
142
-
143
- privacyPolicy = new Terms({
144
- type: 'Privacy Policy',
145
- validUntil: '2020-07-22T11:30:21.000Z',
146
- });
141
+ termsOfService = new Terms({ type: TERMS_OF_SERVICE_TYPE });
142
+ privacyPolicy = new Terms({ type: PRIVACY_POLICY_TYPE, validUntil: '2020-07-22T11:30:21.000Z' });
147
143
 
148
144
  subject.addTerms(termsOfService);
149
145
  subject.addTerms(privacyPolicy);
150
146
  });
151
147
 
152
- it('returns the service terms types', async () => {
153
- expect(subject.getTermsTypes()).to.have.members([
154
- termsOfService.type,
155
- privacyPolicy.type,
156
- ]);
148
+ context('without any filter', () => {
149
+ it('returns all service terms types', () => {
150
+ expect(subject.getTermsTypes()).to.have.members([ TERMS_OF_SERVICE_TYPE, PRIVACY_POLICY_TYPE ]);
151
+ });
152
+ });
153
+
154
+ context('with a filter', () => {
155
+ it('returns filtered terms types', () => {
156
+ expect(subject.getTermsTypes([ PRIVACY_POLICY_TYPE, IMPRINT_TYPE ])).to.deep.equal([PRIVACY_POLICY_TYPE]);
157
+ });
158
+ });
159
+ });
160
+
161
+ describe('#getNumberOfTerms', () => {
162
+ before(() => {
163
+ subject = new Service({ id: 'serviceID', name: 'serviceName' });
164
+ subject.addTerms(new Terms({ type: TERMS_OF_SERVICE_TYPE }));
165
+ subject.addTerms(new Terms({ type: PRIVACY_POLICY_TYPE }));
166
+ });
167
+
168
+ context('without any filter', () => {
169
+ it('returns the number of all terms types', () => {
170
+ expect(subject.getNumberOfTerms()).to.equal(2);
171
+ });
172
+ });
173
+
174
+ context('with a filter', () => {
175
+ it('returns the number of terms matching the provided terms types', () => {
176
+ expect(subject.getNumberOfTerms([ TERMS_OF_SERVICE_TYPE, IMPRINT_TYPE ])).to.equal(1);
177
+ });
157
178
  });
158
179
  });
159
180
  });
@@ -30,7 +30,7 @@ const alignedWithColorsAndTime = combine(
30
30
  }),
31
31
  );
32
32
 
33
- const consoleTransport = new winston.transports.Console();
33
+ const consoleTransport = new winston.transports.Console(({ silent: process.env.NODE_ENV === 'test' }));
34
34
 
35
35
  const transports = [consoleTransport];
36
36
 
@@ -129,11 +129,11 @@ logger.onTrackingCompleted = (numberOfServices, numberOfTerms, extractOnly) => {
129
129
  };
130
130
 
131
131
  logger.onInaccessibleContent = ({ message }, terms) => {
132
- logger.warn({ message, serviceId: terms.serviceId, termsType: terms.type });
132
+ logger.warn({ message, serviceId: terms.service.id, termsType: terms.type });
133
133
  };
134
134
 
135
135
  logger.onError = (error, terms) => {
136
- logger.error({ message: error.stack, serviceId: terms.serviceId, termsType: terms.type });
136
+ logger.error({ message: error.stack, serviceId: terms.service.id, termsType: terms.type });
137
137
  };
138
138
 
139
139
  logger.onPluginError = (error, pluginName) => {
@@ -22,6 +22,8 @@ const ERROR_MESSAGE_TO_ISSUE_LABEL_MAP = {
22
22
  'unable to verify the first certificate': 'first certificate',
23
23
  'certificate has expired': 'certificate expired',
24
24
  'maximum redirect reached': 'redirects',
25
+ 'not a valid selector': 'invalid selector',
26
+ 'empty content': 'empty content',
25
27
  };
26
28
 
27
29
  function getLabelNameFromError(error) {
@@ -43,7 +45,7 @@ export default class Reporter {
43
45
  this.repositories = repositories;
44
46
  }
45
47
 
46
- async initialize() {
48
+ initialize() {
47
49
  return this.github.initialize();
48
50
  }
49
51
 
@@ -65,7 +67,7 @@ No changes were found in the last run, so no new version has been recorded.`,
65
67
  });
66
68
  }
67
69
 
68
- async onFirstVersionRecorded(version) {
70
+ onFirstVersionRecorded(version) {
69
71
  return this.onVersionRecorded(version);
70
72
  }
71
73
 
@@ -59,6 +59,11 @@
59
59
  "color": "0b08a0",
60
60
  "description": "Fetching fails with a timeout error"
61
61
  },
62
+ {
63
+ "name": "empty content",
64
+ "color": "0b08a0",
65
+ "description": "Fetching fails because the server returns an empty content"
66
+ },
62
67
  {
63
68
  "name": "to clarify",
64
69
  "color": "0496ff",
@@ -73,5 +78,10 @@
73
78
  "name": "location",
74
79
  "color": "FBCA04",
75
80
  "description": "Fetch location is outdated"
81
+ },
82
+ {
83
+ "name": "invalid selector",
84
+ "color": "FBCA04",
85
+ "description": "Some selectors cannot be understood by the engine"
76
86
  }
77
87
  ]