Skip to content

Commit 1c11028

Browse files
committed
Add tests
1 parent 3bb2777 commit 1c11028

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

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)