Skip to content

Commit

Permalink
[ENG-4293] Fix node license validation (#1996)
Browse files Browse the repository at this point in the history
* fix node license validation

* remove comments

* add test

* revert changes to copyMetadataChangesToDraft
  • Loading branch information
adlius authored Sep 15, 2023
1 parent e497991 commit 5aba7e7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/packages/registration-schema/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function buildValidation(groups: SchemaBlockGroup[], node?: NodeModel | D
}

export function validateNodeLicense() {
return async (_: unknown, __: unknown, ___: unknown, changes: LicensedContent, content: LicensedContent) => {
return async (_: unknown, newValue: any, __: unknown, changes: LicensedContent, content: LicensedContent) => {
let validateLicenseTarget = await content.license;
let validateNodeLicenseTarget = content.nodeLicense;
if (changes?.license && Object.keys(changes.license).length
Expand Down Expand Up @@ -110,7 +110,7 @@ export function validateNodeLicense() {

const missingFieldsList: Array<keyof NodeLicense> = [];
for (const item of validateLicenseTarget.requiredFields) {
if (!validateNodeLicenseTarget || !validateNodeLicenseTarget[item]) {
if (!newValue || !newValue[item]) {
missingFieldsList.push(item);
}
}
Expand Down
39 changes: 39 additions & 0 deletions tests/engines/registries/acceptance/draft/draft-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,4 +1197,43 @@ module('Registries | Acceptance | draft form', hooks => {
assert.dom('[data-test-link="1-first-page-of-test-schema"] > [data-test-icon]')
.hasClass('fa-check-circle', 'page 1 is now valid');
});

// Test case for bug: ENG-4293
test('validations: year and copyrightHolder validation succeeds after navigating to the next page',async function(
this: DraftFormTestContext, assert,
) {
const initiator = server.create('user', 'loggedIn');
const registrationSchema = server.schema.registrationSchemas.find('testSchema');
const registration = server.create(
'draft-registration',
{
registrationSchema,
initiator,
branchedFrom: this.branchedFrom,
license: server.schema.licenses.findBy({ id: '5c252c8e0989e100220edb7d' }), // MIT License
nodeLicense: { year: '2023', copyrightHolders: 'OSF' },
},
);
const subjects = [server.create('subject')];
registration.update({ subjects });

await visit(`/registries/drafts/${registration.id}/metadata`);
await click('[data-test-metadata-tags]');
await fillIn('[data-test-metadata-tags] input', 'newjeans');
await triggerKeyEvent('[data-test-metadata-tags] input', 'keydown', 'Enter');
await click('[data-test-goto-next-page]');
assert.dom('[data-test-link="metadata"] > [data-test-icon]')
.hasClass('fa-check-circle', 'metadata page is marked valid');
await click('[data-test-goto-metadata]');
await fillIn('[data-test-required-field="copyrightHolders"]', '');
await blur('[data-test-required-field="copyrightHolders"]');
const validationErrorMsg = t('validationErrors.node_license_missing_fields',
{ missingFields: 'Copyright Holders', numOfFields: 1 }).toString();
assert.dom('[data-test-validation-errors="nodeLicense"]')
.containsText(validationErrorMsg,
'NodeLicense validation error when copyright holders is empty');
await click('[data-test-goto-next-page]');
assert.dom('[data-test-link="metadata"] > [data-test-icon]')
.hasClass('fa-exclamation-circle', 'metadata page is marked invalid');
});
});

0 comments on commit 5aba7e7

Please sign in to comment.