@@ -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
0 commit comments