Skip to content
Snippets Groups Projects
Commit e8255714 authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

fix(mts): EQA and EQS get correct fragment files

parent 1b448e05
No related branches found
No related tags found
2 merge requests!34Sprint 17 features,!30fix(mts): EQA and EQS get correct fragment files
...@@ -17,30 +17,27 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => { ...@@ -17,30 +17,27 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => {
}) })
const s3 = new AWS.S3() const s3 = new AWS.S3()
const asyncGetObject = promisify(s3.getObject.bind(s3)) const asyncGetObject = promisify(s3.getObject.bind(s3))
const asyncListObjects = promisify(s3.listObjects.bind(s3))
return async ({ fragment, fileTypes, xmlFile, isEQA = false }) => { return async ({ fragment, fileTypes, xmlFile, isEQA = false }) => {
const { id } = fragment const { files = {} } = fragment
let packageName = get(xmlFile, 'name', '').replace('.xml', '') let packageName = get(xmlFile, 'name', '').replace('.xml', '')
if (isEQA) { if (isEQA) {
packageName = `ACCEPTED_${packageName}` packageName = `ACCEPTED_${packageName}`
} }
try { try {
const params = { const s3FileIDs = Object.values(files)
Bucket: s3Config.bucket, .reduce((acc, f) => [...acc, ...f], [])
Prefix: `${id}`, .map(f => f.id)
}
const s3Items = await asyncListObjects(params) if (s3FileIDs) {
if (s3Items) {
const s3Files = await Promise.all( const s3Files = await Promise.all(
s3Items.Contents.map(content => s3FileIDs.map(fileID =>
asyncGetObject({ asyncGetObject({
Bucket: s3Config.bucket, Bucket: s3Config.bucket,
Key: content.Key, Key: fileID,
}), }),
), ),
) )
if (s3Files) { if (s3Files) {
const packageOutput = fs.createWriteStream(`${packageName}.zip`) const packageOutput = fs.createWriteStream(`${packageName}.zip`)
const archive = archiver('zip') const archive = archiver('zip')
......
...@@ -27,7 +27,7 @@ describe('MTS integration', () => { ...@@ -27,7 +27,7 @@ describe('MTS integration', () => {
}) })
it('should contain configured journal name ', () => { it('should contain configured journal name ', () => {
const result = MTS.composeJson(mocks.fragment) const result = MTS.composeJson({ fragment: mocks.fragment })
expect(result).toHaveProperty( expect(result).toHaveProperty(
'article.front.journal-meta.journal-title-group.journal-title._text', 'article.front.journal-meta.journal-title-group.journal-title._text',
'Bioinorganic Chemistry and Applications', 'Bioinorganic Chemistry and Applications',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment