Skip to content

Commit

Permalink
Merge pull request #158 from i-VRESSE/157-cancel-file-upload
Browse files Browse the repository at this point in the history
fix: unexpected error when removing uploaded molecule file
  • Loading branch information
dmijatovic authored May 22, 2024
2 parents 26c1a49 + 30d68da commit 295878d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
69 changes: 69 additions & 0 deletions packages/core/src/molecule/addMoleculeValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,75 @@ describe('parseMolecules()', () => {
}
)
})

it('should not error on null values in molecules array', () => {
// when null value passed in array
const mockGlobalParameters = {
molecules: [null] as any
}
const mockGlobalSchema: JSONSchema7 = {
type: 'object',
properties: {
molecules: {
title: 'Input Molecules',
description: 'The input molecules that will be used for docking.',
$comment: 'Molecules must be provided in PDB format. These PDB files can be single molecules or ensembles using the MODEL/ENDMDL statements.',
type: 'array',
minItems: 1,
maxItems: 20,
items: {
type: 'string',
format: 'uri-reference'
},
format: 'moleculefilepaths'
}
},
additionalProperties: false
}
const mockFiles = {}

// return empty array
const actual1 = parseMolecules(
mockGlobalParameters,
mockGlobalSchema,
mockFiles
)
expect(actual1).toEqual([[], 'molecules'])
})
it('should not error on undefined values in molecules array', () => {
// when undefined value passed in array
const mockGlobalParameters = {
molecules: [undefined] as any
}
const mockGlobalSchema: JSONSchema7 = {
type: 'object',
properties: {
molecules: {
title: 'Input Molecules',
description: 'The input molecules that will be used for docking.',
$comment: 'Molecules must be provided in PDB format. These PDB files can be single molecules or ensembles using the MODEL/ENDMDL statements.',
type: 'array',
minItems: 1,
maxItems: 20,
items: {
type: 'string',
format: 'uri-reference'
},
format: 'moleculefilepaths'
}
},
additionalProperties: false
}
const mockFiles = {}

// return empty array
const actual1 = parseMolecules(
mockGlobalParameters,
mockGlobalSchema,
mockFiles
)
expect(actual1).toEqual([[], 'molecules'])
})
})

describe('addMoleculeValidation()', () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/molecule/addMoleculeValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function parseMolecules (
if (globalSchema.properties === undefined) {
return [[], undefined]
}

// find prop which has format:moleculefilepaths
const moleculesPropNameAndSchema = Object.entries(
globalSchema.properties
Expand All @@ -42,8 +43,13 @@ export function parseMolecules (
// find file of molecule path
// TODO check whether files are actually PDB files using uiSchema.molecules..items.ui:options.accept: .pdb
const moleculeFiles = moleculeFilePaths
// ignore undefined entries (invalid entries)
.filter(file => file !== undefined)
// ignore undefined/null entries (invalid entries)
.filter(file => {
// check on undefined value in array incl. string value
if (typeof file === 'undefined') return false
// check for null value
return file !== null
})
.map((p) => files[p])

// parse file
Expand Down

0 comments on commit 295878d

Please sign in to comment.