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

[DUOS-2738][risk=no] Refactor dataset submission form validation #2358

Merged
merged 18 commits into from
Oct 23, 2023
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
10 changes: 10 additions & 0 deletions cypress/component/DataSubmission/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Data Submission Schema Validation Tests

Validation tests here rely on the fixture: `cypress/fixtures/dataset-registration-schema_v1.json` which is a copy of
what is stored in Consent: https://consent.dsde-dev.broadinstitute.org/schemas/dataset-registration/v1
If there are changes there, they need to be copied to this file for tests to reflect back end validation.

From project root, run:
```shell
curl -s -S -X 'GET' "https://consent.dsde-dev.broadinstitute.org/schemas/dataset-registration/v1" -H 'accept: application/json' -o ./cypress/fixtures/dataset-registration-schema_v1.json
```
2 changes: 1 addition & 1 deletion cypress/component/DataSubmission/consent_group.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
import React from 'react';
import ConsentGroupForm from '../../../src/components/data_submission/consent_group/ConsentGroupForm';
import ConsentGroupForm from '../../../src/pages/data_submission/consent_group/ConsentGroupForm';
import { cloneDeep } from 'lodash/fp';
import { mount } from 'cypress/react';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-undef */
import React from 'react';
import { DAC, User, Institution, Schema, Study } from '../../../src/libs/ajax';
import DataSubmissionForm from '../../../src/pages/DataSubmissionForm';
import {DAC, User, Institution, Schema, Study, DataSet} from '../../../src/libs/ajax';
import DataSubmissionForm from '../../../src/pages/data_submission/DataSubmissionForm';
import { mount } from 'cypress/react';

const dacs = [
Expand All @@ -23,6 +23,10 @@ beforeEach(() => {
cy.stub(Institution, 'list').returns([{name: 'Test Institution'}]);
cy.stub(Schema, 'datasetRegistrationV1').returns({});
cy.stub(Study, 'getStudyNames').returns([]);
cy.stub(DataSet, 'getDatasetNames').returns([]);
cy.fixture('dataset-registration-schema_v1').then(function (data) {
cy.stub(DataSet, 'getRegistrationSchema').returns(data);
});
});

describe('Data Access Governance', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from 'react';
import { mount } from 'cypress/react';
import { cloneDeep } from 'lodash/fp';
import NihAnvilUse, { YES_NHGRI_YES_PHS_ID } from '../../../src/components/data_submission/NihAnvilUse';
import NihAnvilUse, { YES_NHGRI_YES_PHS_ID } from '../../../src/pages/data_submission/NihAnvilUse';

let propCopy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { mount } from 'cypress/react';
import { cloneDeep } from 'lodash/fp';
import { User } from '../../../src/libs/ajax';
import DataSubmissionStudyInformation from '../../../src/components/data_submission/ds_study_information';
import DataSubmissionStudyInformation from '../../../src/pages/data_submission/ds_study_information';

let propCopy;
const user = {
Expand Down
108 changes: 108 additions & 0 deletions cypress/component/DataSubmission/registration_validation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* eslint-disable no-undef */
import {compileSchema, validateForm} from '../../../src/pages/data_submission/RegistrationValidation.js';

const formData = {
'studyType': 'Observational',
'studyName': 'name',
'studyDescription': 'description',
'dataTypes': ['types'],
'phenotypeIndication': 'phenotype',
'species': 'species',
'piName': 'PI Name',
'dataCustodianEmail': ['[email protected]'],
'publicVisibility': true,
'dataSubmitterUserId': 1,
'nihAnvilUse': 'I am not NHGRI funded and do not plan to store data in AnVIL',
'consentGroups': [{
'numberOfParticipants': 2,
'consentGroupName': 'name',
'generalResearchUse': true,
'dataAccessCommitteeId': 1,
'url': 'https://asdf.com'
}]
};

let schema = undefined;

beforeEach(function () {
cy.fixture('dataset-registration-schema_v1').then(function (data) {
schema = data;
});
});

describe('Dataset Registration Schema Validator', () => {

it('Compiles schema and generates a validate function', () => {
const validateFunction = compileSchema(schema);
expect(validateFunction).to.not.be.null;
});

it('Validates a valid instance of a schema', () => {
const [valid, validation] = validateForm(schema, formData);
expect(valid).to.be.true;
expect(validation).to.be.empty;
});

it('Invalidates an invalid instance of a schema', () => {
const [valid, validation] = validateForm(schema, {});
expect(valid).to.be.false;
expect(validation).to.not.be.empty;
});

it('Validates a valid date field', () => {
const form = Object.assign({}, formData, {targetDeliveryDate: '2021-01-01', targetPublicReleaseDate: '2021-01-01'});
const [valid, validation] = validateForm(schema, form);
expect(valid).to.be.true;
expect(validation).to.be.empty;
});

it('Invalidates an invalid date field', () => {
const form = Object.assign({}, formData, {targetDeliveryDate: '20210101', targetPublicReleaseDate: '20210101'});
const [valid, validation] = validateForm(schema, form);
expect(valid).to.be.false;
expect(validation).to.not.be.empty;
});

it('Validates a valid email field', () => {
const form = Object.assign({}, formData, {dataCustodianEmail: ['[email protected]']});
const [valid, validation] = validateForm(schema, form);
expect(valid).to.be.true;
expect(validation).to.be.empty;
});

it('Invalidates an invalid email field', () => {
const form = Object.assign({}, formData, {dataCustodianEmail: ['user']});
const [valid, validation] = validateForm(schema, form);
expect(valid).to.be.false;
expect(validation).to.not.be.empty;
});

it('Validates a valid uri field', () => {
const consentGroup = {
'numberOfParticipants': 2,
'consentGroupName': 'name',
'generalResearchUse': true,
'dataAccessCommitteeId': 1,
'url': 'https://some.site.org'
};
const form = Object.assign({}, formData, {consentGroups: [consentGroup]});
const [valid, validation] = validateForm(schema, form);
expect(valid).to.be.true;
expect(validation).to.be.empty;
});

it('Invalidates an invalid uri field', () => {
const consentGroup = {
'numberOfParticipants': 2,
'consentGroupName': 'name',
'generalResearchUse': true,
'dataAccessCommitteeId': 1,
'url': 'some place . org'
};
const form = Object.assign({}, formData, {consentGroups: [consentGroup]});
const [valid, validation] = validateForm(schema, form);
expect(valid).to.be.false;
expect(validation).to.not.be.empty;
});

});
204 changes: 0 additions & 204 deletions cypress/component/utils/json_schema.spec.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@
"type": "object",
"required": [
"consentGroupName",
"fileTypes",
"numberOfParticipants"
],
"allOf": [
Expand Down Expand Up @@ -681,7 +680,6 @@
},
"fileTypes": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/$defs/fileTypeObject"
},
Expand Down
Loading
Loading