-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for RDMPService assign permissions methods
Fix bug when assigning editor-only permissions.
- Loading branch information
Showing
2 changed files
with
447 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,389 @@ | ||
describe('The RDMPService', function () { | ||
const userAdminDefault = { | ||
type: 'local', | ||
name: 'admin', | ||
username: 'admin', | ||
password: 'rbadmin', | ||
email: "[email protected]" | ||
}; | ||
const userAdmin1 = { | ||
type: 'local', | ||
name: 'admin1', | ||
username: 'admin1', | ||
password: 'rbadmin1', | ||
email: "[email protected]" | ||
}; | ||
const userNotInDB1 = { | ||
type: 'local', | ||
name: 'standard1', | ||
username: 'standard1', | ||
password: 'rbstandard1', | ||
email: "[email protected]" | ||
}; | ||
const userNotInDB2 = { | ||
type: 'local', | ||
name: 'standard2', | ||
username: 'standard2', | ||
password: 'rbstandard2', | ||
email: "[email protected]" | ||
}; | ||
before(function () { | ||
// add another user | ||
return User.create(userAdmin1); | ||
}); | ||
after(function () { | ||
// remove the users added in `before` | ||
return User.destroyOne({name: userAdmin1.name}); | ||
}); | ||
describe('assign permissions as expected', function () { | ||
it('assignPermissions with no viewers or editors', function (done) { | ||
const oid = "assignPermissions-no-viewers-no-editors"; | ||
const record = { | ||
metaMetadata: {}, | ||
workflow: {}, | ||
authorization: { | ||
edit: [], | ||
view: [], | ||
editRoles: ['Admin'], | ||
viewRoles: ['Admin'], | ||
editPending: [], | ||
viewPending: [] | ||
}, | ||
metadata: { | ||
contributor_ci: { | ||
"text_full_name": "AAAA AAAA", | ||
"full_name_honorific": " AAAA AAAA", | ||
"email": [userAdminDefault.email], | ||
"orcid": "" | ||
} | ||
} | ||
}; | ||
const options = { | ||
"emailProperty": "email", | ||
"editContributorProperties": [ | ||
"metadata.contributor_data_manager", | ||
"metadata.dataowner_email" | ||
], | ||
"viewContributorProperties": [ | ||
"metadata.contributor_data_manager", | ||
"metadata.contributor_supervisor", | ||
"metadata.contributors" | ||
], | ||
"recordCreatorPermissions": "view&edit" | ||
}; | ||
RDMPService.assignPermissions(oid, record, options).subscribe(function (record) { | ||
expect(record.authorization.edit).to.be.empty; | ||
expect(record.authorization.view).to.be.empty; | ||
expect(record.authorization.editPending).to.be.empty; | ||
expect(record.authorization.viewPending).to.be.empty; | ||
User.count().then(function (count) { | ||
expect(count).equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('assignPermissions with only viewers', function (done) { | ||
const oid = "assignPermissions-has-viewers-no-editors"; | ||
const record = { | ||
metaMetadata: {}, | ||
workflow: {}, | ||
authorization: { | ||
edit: [], | ||
view: [], | ||
editRoles: ['Admin'], | ||
viewRoles: ['Admin'], | ||
editPending: [], | ||
viewPending: [] | ||
}, | ||
metadata: { | ||
contributor_ci: { | ||
"text_full_name": "AAAA AAAA", | ||
"full_name_honorific": " AAAA AAAA", | ||
"email": [userAdminDefault.email], | ||
"orcid": "" | ||
} | ||
} | ||
}; | ||
const options = { | ||
"emailProperty": "email", | ||
"editContributorProperties": [ | ||
"metadata.contributor_data_manager", | ||
"metadata.dataowner_email" | ||
], | ||
"viewContributorProperties": [ | ||
"metadata.contributor_ci", | ||
"metadata.contributor_data_manager", | ||
"metadata.contributor_supervisor", | ||
"metadata.contributors" | ||
], | ||
"recordCreatorPermissions": "view&edit" | ||
}; | ||
RDMPService.assignPermissions(oid, record, options).subscribe(function (record) { | ||
expect(record.authorization.edit).to.be.empty; | ||
expect(record.authorization.view).eql([userAdminDefault.name, undefined]); | ||
expect(record.authorization.editPending).to.be.empty; | ||
expect(record.authorization.viewPending).to.be.empty; | ||
User.count().then(function (count) { | ||
expect(count).equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('assignPermissions with only editors', function (done) { | ||
const oid = "assignPermissions-no-viewers-has-editors"; | ||
const record = { | ||
metaMetadata: {}, | ||
workflow: {}, | ||
authorization: { | ||
edit: [], | ||
view: [], | ||
editRoles: ['Admin'], | ||
viewRoles: ['Admin'], | ||
editPending: [], | ||
viewPending: [] | ||
}, | ||
metadata: { | ||
contributor_ci: { | ||
"text_full_name": "AAAA AAAA", | ||
"full_name_honorific": " AAAA AAAA", | ||
"email": [userAdminDefault.email], | ||
"orcid": "" | ||
} | ||
} | ||
}; | ||
const options = { | ||
"emailProperty": "email", | ||
"editContributorProperties": [ | ||
"metadata.contributor_ci", | ||
"metadata.contributor_data_manager", | ||
"metadata.dataowner_email" | ||
], | ||
"viewContributorProperties": [ | ||
"metadata.contributor_data_manager", | ||
"metadata.contributor_supervisor", | ||
"metadata.contributors" | ||
], | ||
"recordCreatorPermissions": "view&edit" | ||
}; | ||
RDMPService.assignPermissions(oid, record, options).subscribe(function (record) { | ||
expect(record.authorization.edit).eql([userAdminDefault.name, undefined]); | ||
expect(record.authorization.view).eql([undefined,undefined,undefined,undefined,undefined]); | ||
expect(record.authorization.editPending).to.be.empty; | ||
expect(record.authorization.viewPending).to.be.empty; | ||
User.count().then(function (count) { | ||
expect(count).equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('complex assign permissions as expected', function () { | ||
it('complexAssignPermissions with no viewers or editors', function (done) { | ||
const oid = "complexAssignPermissions-no-viewers-no-editors"; | ||
const record = { | ||
metaMetadata: {}, | ||
workflow: {}, | ||
authorization: { | ||
edit: [], | ||
view: [], | ||
editRoles: ['Admin'], | ||
viewRoles: ['Admin'], | ||
editPending: [], | ||
viewPending: [] | ||
}, | ||
metadata: { | ||
contributor_dmp_permissions: [ | ||
{ | ||
"text_full_name": "AAAA AAAA", | ||
"full_name_honorific": "AAAA AAAA", | ||
"email": [userAdminDefault.email], | ||
"role": "View&Edit" | ||
}, | ||
{ | ||
"text_full_name": "BBBB BBBB", | ||
"full_name_honorific": "", | ||
"email": [userAdmin1.email], | ||
"role": "View" | ||
} | ||
], | ||
contributor_ci: { | ||
"text_full_name": "AAAA AAAA", | ||
"full_name_honorific": " AAAA AAAA", | ||
"email": [userAdminDefault.email], | ||
"orcid": "", | ||
"role": "", | ||
} | ||
} | ||
}; | ||
const options = { | ||
"emailProperty": "email", | ||
"userProperties": [ | ||
"metadata.contributor_ci" | ||
], | ||
"editPermissionRule": "<%= role == 'View&Edit' %>", | ||
"viewPermissionRule": "<%= role == 'View&Edit' || role == 'View' %>", | ||
"recordCreatorPermissions": "view&edit" | ||
}; | ||
RDMPService.complexAssignPermissions(oid, record, options).subscribe(function (record) { | ||
expect(record.authorization.edit).to.be.empty; | ||
expect(record.authorization.view).to.be.empty; | ||
expect(record.authorization.editPending).to.be.empty; | ||
expect(record.authorization.viewPending).to.be.empty; | ||
User.count().then(function (count) { | ||
expect(count).equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('complexAssignPermissions with only editors', function (done) { | ||
const oid = "complexAssignPermissions-no-viewers-has-editors"; | ||
const record = { | ||
metaMetadata: {}, | ||
workflow: {}, | ||
authorization: { | ||
edit: [], | ||
view: [], | ||
editRoles: ['Admin'], | ||
viewRoles: ['Admin'], | ||
editPending: [], | ||
viewPending: [] | ||
}, | ||
metadata: { | ||
contributor_dmp_permissions: [ | ||
{ | ||
"text_full_name": "AAAA AAAA", | ||
"full_name_honorific": "AAAA AAAA", | ||
"email": [userAdminDefault.email], | ||
"role": "View&Edit" | ||
} | ||
] | ||
} | ||
}; | ||
const options = { | ||
"emailProperty": "email", | ||
"userProperties": [ | ||
"metadata.contributor_dmp_permissions" | ||
], | ||
"editPermissionRule": "<%= role == 'View&Edit' %>", | ||
"viewPermissionRule": "<%= role == 'View' %>", | ||
"recordCreatorPermissions": "view&edit" | ||
}; | ||
RDMPService.complexAssignPermissions(oid, record, options).subscribe(function (record) { | ||
expect(record.authorization.edit).to.eql([userAdminDefault.name, undefined]); | ||
expect(record.authorization.view).to.eql([undefined,undefined,undefined,undefined,undefined]); | ||
expect(record.authorization.editPending).to.be.empty; | ||
expect(record.authorization.viewPending).to.be.empty; | ||
User.count().then(function (count) { | ||
expect(count).equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('complexAssignPermissions with only viewers', function (done) { | ||
const oid = "complexAssignPermissions-has-viewers-no-editors"; | ||
const record = { | ||
metaMetadata: {}, | ||
workflow: {}, | ||
authorization: { | ||
edit: [], | ||
view: [], | ||
editRoles: ['Admin'], | ||
viewRoles: ['Admin'], | ||
editPending: [], | ||
viewPending: [] | ||
}, | ||
metadata: { | ||
contributor_dmp_permissions: [ | ||
{ | ||
"text_full_name": "BBBB BBBB", | ||
"full_name_honorific": "", | ||
"email": [userAdmin1.email], | ||
"role": "View" | ||
} | ||
] | ||
} | ||
}; | ||
const options = { | ||
"emailProperty": "email", | ||
"userProperties": [ | ||
"metadata.contributor_dmp_permissions" | ||
], | ||
"editPermissionRule": "<%= role == 'View&Edit' %>", | ||
"viewPermissionRule": "<%= role == 'View&Edit' || role == 'View' %>", | ||
"recordCreatorPermissions": "view&edit" | ||
}; | ||
RDMPService.complexAssignPermissions(oid, record, options).subscribe(function (record) { | ||
expect(record.authorization.edit).to.be.empty; | ||
expect(record.authorization.view).eql([userAdmin1.name, undefined]); | ||
expect(record.authorization.editPending).to.be.empty; | ||
expect(record.authorization.viewPending).to.be.empty; | ||
User.count().then(function (count) { | ||
expect(count).equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('complexAssignPermissions to expected users', function (done) { | ||
const oid = "complexAssignPermissions-to-expected-users"; | ||
const record = { | ||
metaMetadata: {}, | ||
workflow: {}, | ||
authorization: { | ||
edit: [], | ||
view: [], | ||
editRoles: ['Admin'], | ||
viewRoles: ['Admin'], | ||
editPending: [], | ||
viewPending: [] | ||
}, | ||
metadata: { | ||
contributor_dmp_permissions: [ | ||
{ | ||
"text_full_name": "AAAA AAAA", | ||
"full_name_honorific": "AAAA AAAA", | ||
"email": [userAdminDefault.email], | ||
"role": "View&Edit" | ||
}, | ||
{ | ||
"text_full_name": "BBBB BBBB", | ||
"full_name_honorific": "", | ||
"email": [userAdmin1.email], | ||
"role": "View" | ||
}, | ||
{ | ||
"text_full_name": "CCCC CCCC", | ||
"full_name_honorific": "", | ||
"email": [userNotInDB1.email], | ||
"role": "View&Edit" | ||
}, | ||
{ | ||
"text_full_name": "DDDD DDDD", | ||
"full_name_honorific": "", | ||
"email": [userNotInDB2.email], | ||
"role": "View" | ||
} | ||
] | ||
} | ||
}; | ||
const options = { | ||
"emailProperty": "email", | ||
"userProperties": [ | ||
"metadata.contributor_dmp_permissions" | ||
], | ||
"editPermissionRule": "<%= role == 'View&Edit' %>", | ||
"viewPermissionRule": "<%= role == 'View&Edit' || role == 'View' %>", | ||
"recordCreatorPermissions": "view&edit" | ||
}; | ||
RDMPService.complexAssignPermissions(oid, record, options).subscribe(function (record) { | ||
expect(record.authorization.edit).eql([userAdminDefault.name, undefined]); | ||
expect(record.authorization.view).eql([userAdminDefault.name, userAdmin1.name, undefined]); | ||
expect(record.authorization.editPending).eql([userNotInDB1.email]); | ||
expect(record.authorization.viewPending).eql([userNotInDB1.email, userNotInDB2.email]); | ||
User.count().then(function (count) { | ||
expect(count).equal(2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.