This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
167 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const moment = require('moment'); | ||
|
||
function fileVersionFilter(outputFile, version, oldestDate) { | ||
const regex = new RegExp(`^${outputFile}-(\\d{8}).*-${version}.json`); | ||
return (file) => { | ||
const match = regex.exec(file.name); | ||
if (match && match[1]) { | ||
const date = moment(match[1], 'YYYYMMDD'); | ||
return date.isBefore(oldestDate); | ||
} | ||
return false; | ||
}; | ||
} | ||
|
||
module.exports = fileVersionFilter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const chai = require('chai'); | ||
const moment = require('moment'); | ||
const createFilter = require('../../lib/createExpiredFileFilter'); | ||
|
||
const expect = chai.expect; | ||
|
||
describe('create createExpiredFileFilter', () => { | ||
it('should return filenames earlier than provided oldest date', () => { | ||
const oldestDate = moment('2018-05-08'); | ||
const expired1 = 'test-data-20180319-0.1.json'; | ||
const expired2 = 'test-data-20180501-0.1.json'; | ||
const files = [ | ||
{ name: expired1 }, | ||
{ name: expired2 }, | ||
{ name: 'test-data-20180508-0.1.json' }, | ||
{ name: 'test-data-20180515-0.1.json' }, | ||
]; | ||
|
||
const filter = createFilter('test-data', '0.1', oldestDate); | ||
const result = files.filter(filter); | ||
expect(result.length).to.be.equal(2); | ||
expect(result[0].name).to.be.equal(expired1); | ||
expect(result[1].name).to.be.equal(expired2); | ||
}); | ||
|
||
it('should return no files if all in date', () => { | ||
const oldestDate = moment('2018-05-08'); | ||
const files = [ | ||
{ name: 'test-data-20180508-0.1.json' }, | ||
{ name: 'test-data-20180515-0.1.json' }, | ||
]; | ||
|
||
const filter = createFilter('test-data', '0.1', oldestDate); | ||
const result = files.filter(filter); | ||
expect(result.length).to.be.equal(0); | ||
}); | ||
|
||
it('should ignore non date files', () => { | ||
const oldestDate = moment('2018-05-15'); | ||
const expiredFile = 'test-data-20180508-0.1.json'; | ||
const files = [ | ||
{ name: 'test-data.json' }, | ||
{ name: expiredFile }, | ||
{ name: 'test-data-20180515-0.1.json' }, | ||
]; | ||
|
||
const filter = createFilter('test-data', '0.1', oldestDate); | ||
const result = files.filter(filter); | ||
expect(result.length).to.equal(1); | ||
expect(result[0].name).to.equal(expiredFile); | ||
}); | ||
}); |