Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unexpected error when removing uploaded molecule file #158

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading