Skip to content

Commit

Permalink
Merge pull request #3647 from marcellamaki/file-validation
Browse files Browse the repository at this point in the history
Add files existence and length check so validation is run later
  • Loading branch information
bjester authored Sep 16, 2022
2 parents c38a051 + 055a248 commit 98e70e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,13 @@ export function getNodeDetailsErrors(node) {
* @returns {Array} An array of error codes.
*/
export function getNodeFilesErrors(files) {
let errors = files.filter(f => f.error).map(f => f.error);
let validPrimaryFiles = files.filter(f => !f.error && !f.preset.supplementary);

if (!validPrimaryFiles.length) {
errors.push(ValidationErrors.NO_VALID_PRIMARY_FILES);
let errors = [];
if (files && files.length > 0) {
errors = files.filter(f => f.error).map(f => f.error);
let validPrimaryFiles = files.filter(f => !f.error && !f.preset.supplementary);
if (!validPrimaryFiles.length) {
errors.push(ValidationErrors.NO_VALID_PRIMARY_FILES);
}
}
return errors;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,6 @@ describe('channelEdit utils', () => {
expect(isNodeComplete({ nodeDetails: invalidNodeDetails, files })).toBe(false);
});

it('returns false if there are no files', () => {
expect(isNodeComplete({ nodeDetails, files: [] })).toBe(false);
});

it('returns false if there is at least one invalid file', () => {
const invalidFile = { id: 'file-id', error: 'error' };
expect(isNodeComplete({ nodeDetails, files: [...files, invalidFile] })).toBe(false);
Expand Down

0 comments on commit 98e70e1

Please sign in to comment.