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

SIMS-BIOHUB-8 #1024

Merged
merged 17 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
27 changes: 16 additions & 11 deletions api/src/json-schema/validation-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,24 @@ export const submissionValidationSchema = {
description: 'The validators that can be applied against a file/sheet within a submission file.',
anyOf: [
{
$ref: '#/$defs/file_required_columns_validator'
$ref: '#/$defs/file_required_columns_validator',
description: 'column header validator'
},
{
$ref: '#/$defs/file_recommended_columns_validator'
$ref: '#/$defs/file_recommended_columns_validator',
description: 'column header validator'
},
{
$ref: '#/$defs/file_duplicate_columns_validator'
$ref: '#/$defs/file_duplicate_columns_validator',
description: 'column header validator'
},
{
$ref: '#/$defs/file_valid_columns_validator'
$ref: '#/$defs/file_valid_columns_validator',
description: 'column header validator '
},
{
$ref: '#/$defs/file_column_unique_validator'
$ref: '#/$defs/file_column_unique_validator',
description: 'column cell validator '
}
]
},
Expand Down Expand Up @@ -239,7 +244,7 @@ export const submissionValidationSchema = {
additionalProperties: false
},
file_required_columns_validator: {
description: 'Validates that this file/sheet contains required columns',
description: 'Column header validator that checks whether the file/sheet contains required columns',
type: 'object',
properties: {
file_required_columns_validator: {
Expand All @@ -265,7 +270,7 @@ export const submissionValidationSchema = {
additionalProperties: false
},
file_recommended_columns_validator: {
description: 'Validates that this file/sheet contains recommended columns',
description: 'Column header validator that checks whether the file/sheet contains recommended columns',
type: 'object',
properties: {
file_recommended_columns_validator: {
Expand All @@ -291,7 +296,7 @@ export const submissionValidationSchema = {
additionalProperties: false
},
file_duplicate_columns_validator: {
description: 'Validates that this file/sheet contains recommended columns',
description: 'Column header validator that checks whether this file/sheet contains recommended columns',
type: 'object',
properties: {
file_duplicate_columns_validator: {
Expand All @@ -310,7 +315,7 @@ export const submissionValidationSchema = {
additionalProperties: false
},
file_valid_columns_validator: {
description: 'Validates that this file/sheet contains only valid (known) columns',
description: 'Column header validator that checks whether this file/sheet contains only valid (known) columns',
type: 'object',
properties: {
file_valid_columns_validator: {
Expand All @@ -335,7 +340,7 @@ export const submissionValidationSchema = {
additionalProperties: false
},
column_required_validator: {
description: 'Validates that this column value is not empty',
description: 'Column cell validator that checks that this column value is not empty.',
type: 'object',
properties: {
column_required_validator: {
Expand Down Expand Up @@ -452,7 +457,7 @@ export const submissionValidationSchema = {
additionalProperties: false
},
file_column_unique_validator: {
description: 'Validates that the column(s) are unique',
description: 'Column cell validator the checks that the column(s) are unique',
type: 'object',
properties: {
file_column_unique_validator: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export function getOccurrenceSubmission(): RequestHandler {
SUBMISSION_STATUS_TYPE.SYSTEM_ERROR,
SUBMISSION_STATUS_TYPE.FAILED_OCCURRENCE_PREPARATION,
SUBMISSION_STATUS_TYPE.FAILED_VALIDATION,
SUBMISSION_STATUS_TYPE.INVALID_MEDIA,
SUBMISSION_STATUS_TYPE.FAILED_TRANSFORMED,
SUBMISSION_STATUS_TYPE.FAILED_PROCESSING_OCCURRENCE_DATA,
SUBMISSION_STATUS_TYPE['AWAITING CURRATION'],
Expand Down
14 changes: 6 additions & 8 deletions api/src/services/validation-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ describe('ValidationService', () => {
expect(response.media_state.fileErrors).is.empty;
});

it('should throw Media is invalid error', async () => {
it('should return early if media_state is invalid', async () => {
const service = mockService();
const mockMediaState = {
fileName: 'test file',
Expand All @@ -1043,13 +1043,11 @@ describe('ValidationService', () => {

sinon.stub(XLSXCSV.prototype, 'getMediaState').returns(mockMediaState);

try {
await service.validateXLSX(xlsx, parser);
expect.fail();
} catch (error) {
expect(error).to.be.instanceOf(SubmissionError);
expect((error as SubmissionError).submissionMessages[0].type).to.be.eql(SUBMISSION_MESSAGE_TYPE.INVALID_MEDIA);
}
const result = await service.validateXLSX(xlsx, parser);

expect(result.csv_state).to.be.eql([]);
expect(result.media_state.fileName).to.be.eql(mockMediaState.fileName);
expect(result.media_state.isValid).to.be.eql(false);
});

it('should return valid state object with content errors', async () => {
Expand Down
17 changes: 10 additions & 7 deletions api/src/services/validation-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ export class ValidationService extends DBService {
file.validateMedia(parser);

const media_state = file.getMediaState();
anissa-agahchen marked this conversation as resolved.
Show resolved Hide resolved

if (!media_state.isValid) {
throw SubmissionErrorFromMessageType(SUBMISSION_MESSAGE_TYPE.INVALID_MEDIA);
return { csv_state: ([] as unknown) as ICsvState[], media_state };
anissa-agahchen marked this conversation as resolved.
Show resolved Hide resolved
}

// Run CSV content validations
Expand Down Expand Up @@ -401,7 +402,9 @@ export class ValidationService extends DBService {
const errors: MessageError[] = [];

mediaState.fileErrors?.forEach((fileError) => {
errors.push(new MessageError(SUBMISSION_MESSAGE_TYPE.INVALID_MEDIA, `${fileError}`, 'Miscellaneous'));
errors.push(
new MessageError(SUBMISSION_MESSAGE_TYPE.INVALID_MEDIA, `${fileError}`, SUBMISSION_MESSAGE_TYPE.INVALID_MEDIA)
);
});

csvState?.forEach((csvStateItem) => {
Expand Down Expand Up @@ -434,13 +437,13 @@ export class ValidationService extends DBService {
)
);
});

if (!mediaState.isValid || csvState?.some((item) => !item.isValid)) {
// At least 1 error exists, skip remaining steps
parseError = true;
}
});

if (mediaState.fileErrors?.length || csvState?.some((item) => !item.isValid)) {
// At least 1 error exists, skip remaining steps
parseError = true;
}

if (parseError) {
throw new SubmissionError({ messages: errors });
}
Expand Down