-
Notifications
You must be signed in to change notification settings - Fork 14
MIG-109: split getStudyManifest function as per requirement #372
New issue
8000
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
Merged
nahueld
merged 6 commits into
Medable:develop
from
davideaquaro:task/MIG-109-split-getStudyManifest
May 19, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1edfd84
MIG-109: split getStudyManifest function as per requirement
davideaquaro 04ec941
refactor: removed unnecessary import
davideaquaro 156bf3f
MIG-109: fixed wrong path when reading ingestTransform and added test…
davideaquaro d1722e1
refactor: renamed function name to getFirstStudy
davideaquaro c41ee52
refactor: renamed function name to getFirstStudy
davideaquaro 76cac40
refactor: generalised code in getTaskManifest and getConsentManifest …
davideaquaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
243 changes: 243 additions & 0 deletions
243
packages/mdctl-axon-tools/__tests__/MIG-109/MIG-109.test.js
This file contains hidden or 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,243 @@ | ||
/* eslint-disable import/order */ | ||
|
||
jest.mock('@medable/mdctl-api-driver', () => ({ Driver: class {} }), { virtual: true }) | ||
jest.mock('@medable/mdctl-api-driver/lib/cortex.object', () => ({ Object: class {}, Org: class {} }), { virtual: true }) | ||
jest.mock('../../lib/mappings') | ||
|
||
const fs = require('fs'), | ||
StudyManifestTools = require('../../lib/StudyManifestTools') | ||
|
||
describe('MIG-109 - Test StudyManifestTools ', () => { | ||
|
||
let manifestTools | ||
const mockGetExportedObjects = jest.fn(() => []), | ||
existingStudy = { | ||
_id: '1', | ||
c_name: 'Study', | ||
c_key: 'abc' | ||
}, | ||
hasNextStudyMock = jest.fn(() => true), | ||
nextStudyMock = jest.fn(() => existingStudy), | ||
hasNextStudySchema = jest.fn(() => true), | ||
nextStudySchemaMock = jest.fn(() => ({ _id: '1', object: 'object', properties: [{ name: 'c_no_pii' }] })), | ||
entities = [{ | ||
_id: '615bcd016631cc0100d2766c', | ||
object: 'c_study', | ||
c_key: 'key-001' | ||
}, | ||
{ | ||
_id: '615b60d1bf2e4301008f4d68', | ||
object: 'c_dummy_object', | ||
c_key: 'key-002' | ||
}, | ||
{ | ||
_id: '619aaaafe44c6e01003f7313', | ||
object: 'c_task', | ||
c_key: 'key-003' | ||
}, | ||
{ | ||
_id: '61981246ca9563010037bfa8', | ||
object: 'c_task', | ||
c_key: 'key-004' | ||
}, | ||
{ | ||
_id: '61981246ca95714c14e61a8c', | ||
object: 'c_step', | ||
c_key: 'key-005' | ||
}, | ||
{ | ||
_id: '61981246ca966caef6108f28', | ||
object: 'c_step', | ||
c_key: 'key-006' | ||
}, | ||
{ | ||
_id: '61981246ca9592ee0e41a3dd', | ||
object: 'ec__document_template', | ||
c_key: 'key-007' | ||
}, | ||
{ | ||
_id: '61980eb292466ea32e087378', | ||
object: 'ec__document_template', | ||
c_key: 'key-008' | ||
}, | ||
{ | ||
_id: '6d525cf2e328e7300d97c399', | ||
object: 'ec__default_document_css', | ||
c_key: 'key-009' | ||
}, | ||
{ | ||
_id: '6d525cfe328e64ac0833baef', | ||
object: 'ec__knowledge_check', | ||
c_key: 'key-010' | ||
}, | ||
{ | ||
_id: '6d525f2e328e7f1e48262523', | ||
object: 'ec__knowledge_check', | ||
c_key: 'key-011' | ||
}], | ||
dummyReferences = [ | ||
{ | ||
name: 'c_study', | ||
array: false, | ||
object: 'c_study', | ||
type: 'Reference', | ||
required: false | ||
} | ||
], | ||
org = { | ||
objects: { | ||
c_study: { | ||
readOne: () => ({ | ||
skipAcl: () => ({ | ||
grant: () => ({ | ||
paths: () => ({ | ||
hasNext: hasNextStudyMock, | ||
next: nextStudyMock | ||
}) | ||
}) | ||
}) | ||
}) | ||
}, | ||
object: { | ||
find: () => ({ | ||
10000 skipAcl: () => ({ | ||
grant: () => ({ | ||
paths: () => ({ | ||
hasNext: hasNextStudySchema, | ||
next: nextStudySchemaMock | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
beforeAll(async() => { | ||
manifestTools = new StudyManifestTools({}) | ||
manifestTools.getExportObjects = mockGetExportedObjects | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('Test study manifest creation', async() => { | ||
const manifest = { | ||
object: 'manifest', | ||
dependencies: false, | ||
exportOwner: false, | ||
importOwner: false, | ||
c_study: { | ||
includes: [ | ||
'key-001' | ||
] | ||
}, | ||
c_dummy_object: { | ||
includes: [ | ||
'key-002' | ||
] | ||
}, | ||
c_task: { | ||
includes: [ | ||
'key-003', | ||
'key-004' | ||
] | ||
}, | ||
c_step: { | ||
includes: [ | ||
'key-005', | ||
'key-006' | ||
] | ||
} | ||
}, | ||
ingestTransform = fs.readFileSync(`${__dirname}/../../packageScripts/ingestTransform.js`).toString() | ||
|
||
jest.spyOn(StudyManifestTools.prototype, 'getFirstStudy').mockImplementation(() => org) | ||
jest.spyOn(StudyManifestTools.prototype, 'getOrgObjectInfo').mockImplementation(() => dummyReferences) | ||
jest.spyOn(StudyManifestTools.prototype, 'validateReferences').mockImplementation(() => entities) | ||
jest.spyOn(StudyManifestTools.prototype, 'createManifest').mockImplementation(() => manifest) | ||
|
||
// eslint-disable-next-line one-var | ||
const manifestAndDeps = await manifestTools.buildManifestAndDependencies() | ||
|
||
expect(manifestAndDeps.manifest) | ||
.toStrictEqual(manifest) | ||
expect(manifestAndDeps.removedEntities) | ||
.toBeUndefined() | ||
expect(manifestAndDeps.mappingScript) | ||
.toBeUndefined() | ||
expect(manifestAndDeps.ingestTransform) | ||
.toStrictEqual(ingestTransform) | ||
}) | ||
|
||
it('Test task manifest creation', async() => { | ||
const manifest = { | ||
object: 'manifest', | ||
dependencies: false, | ||
exportOwner: false, | ||
importOwner: false, | ||
c_task: { | ||
includes: [ | ||
'key-003', | ||
'key-004' | ||
] | ||
}, | ||
c_step: { | ||
includes: [ | ||
'key-005', | ||
'key-006' | ||
] | ||
} | ||
} | ||
|
||
jest.spyOn(StudyManifestTools.prototype, 'getOrgObjectInfo').mockImplementation(() => dummyReferences) | ||
jest.spyOn(StudyManifestTools.prototype, 'validateReferences').mockImplementation(() => entities) | ||
jest.spyOn(StudyManifestTools.prototype, 'createManifest').mockImplementation(() => manifest) | ||
|
||
// eslint-disable-next-line one-var | ||
const manifestAndDeps = await manifestTools.buildTaskManifestAndDependencies(['619aaaafe44c6e01003f7313', '61981246ca9563010037bfa8']) | ||
|
||
expect(manifestAndDeps.manifest) | ||
.toStrictEqual(manifest) | ||
expect(manifestAndDeps.removedEntities) | ||
.toBeUndefined() | ||
}) | ||
|
||
it('Test consent manifest creation', async() => { | ||
const manifest = { | ||
object: 'manifest', | ||
dependencies: false, | ||
exportOwner: false, | ||
importOwner: false, | ||
ec__document_template: { | ||
includes: [ | ||
'key-007', | ||
'key-008' | ||
] | ||
}, | ||
ec__default_document_css: { | ||
includes: [ | ||
'key-009' | ||
] | ||
}, | ||
ec__knowledge_check: { | ||
includes: [ | ||
'key-010', | ||
'key-011' | ||
] | ||
} | ||
} | ||
jest.spyOn(StudyManifestTools.prototype, 'getOrgObjectInfo').mockImplementation(() => dummyReferences) | ||
jest.spyOn(StudyManifestTools.prototype, 'validateReferences').mockImplementation(() => entities) | ||
jest.spyOn(StudyManifestTools.prototype, 'createManifest').mockImplementation(() => manifest) | ||
|
||
// eslint-disable-next-line one-var | ||
const manifestAndDeps = await manifestTools.buildConsentManifestAndDependencies(['61981246ca9592ee0e41a3dd', '61980eb292466ea32e087378']) | ||
|
||
expect(manifestAndDeps.manifest) | ||
.toStrictEqual(manifest) | ||
expect(manifestAndDeps.removedEntities) | ||
.toBeUndefined() | ||
}) | ||
}) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also noticed that we have some code duplication for the other mdctl tasks, check
For both cases we could split the logic too (that is have writing logic and processing logic decoupled), this will be really convenient for the next release that we are going to be using those other more granular exports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nahueld is it ok for you if I create another Jira to keep track of this as I guess we probably don't want to overlap with the original requirement?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok let's update the ticket to reflect this, given that this is an internal task we are ok adjusting the requirements