Skip to content

Commit b4afd81

Browse files
committed
Add ConsentDocuments.imdi to non-files export
1 parent 89a237f commit b4afd81

2 files changed

Lines changed: 92 additions & 66 deletions

File tree

src/export/ImdiBundler.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,17 @@ export default class ImdiBundler {
111111
copyInProjectFiles
112112
);
113113

114-
// I'm thinking, this only makes sense if we're going to provide the files
115-
if (copyInProjectFiles) {
116-
await this.addConsentBundle(
117-
project,
118-
rootDirectory,
119-
secondLevel,
120-
childrenSubpaths,
121-
imdiMode,
122-
copyInProjectFiles,
123-
folderFilter,
124-
omitNamespaces
125-
);
126-
}
114+
// ELAR wants an IMDI for consent files even if we aren't copying them in
115+
await this.addConsentBundle(
116+
project,
117+
rootDirectory,
118+
secondLevel,
119+
childrenSubpaths,
120+
imdiMode,
121+
copyInProjectFiles,
122+
folderFilter,
123+
omitNamespaces
124+
);
127125

128126
//---- Sessions ----
129127

src/export/consentImdi.spec.ts

Lines changed: 81 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,63 +15,15 @@ import { Contribution } from "../model/file/File";
1515

1616
// find the the temp directory of this computer
1717

18-
describe("Consent Form Inclusion", () => {
18+
describe("Consent in OPEX+Files export", () => {
1919
let thisRunDir: string;
2020
let targetDir: string;
21-
afterAll(() => {
22-
if (thisRunDir) {
23-
// fs.rmdirSync(thisRunDir, { recursive: true });
24-
}
25-
});
2621
beforeAll(async () => {
27-
const thisSpecDir = Path.join(os.tmpdir(), "consent imdi bundler tests");
28-
fs.mkdirSync(thisSpecDir, { recursive: true });
29-
const randomStringForFileName = Math.random().toString(36).substring(7);
30-
thisRunDir = Path.join(thisSpecDir, "run-" + randomStringForFileName);
31-
fs.mkdirSync(thisRunDir);
32-
const projectDir = Path.join(thisRunDir, "projectDir");
33-
fs.mkdirSync(projectDir);
34-
targetDir = Path.join(thisRunDir, "target");
35-
fs.mkdirSync(targetDir);
36-
37-
const project = Project.fromDirectory(projectDir);
38-
39-
// NB: this is to test the access protocol used for consent bundles,
40-
// which has a hard-coded knowledge of the access protocol used for
41-
// ELAR currently. If/when we add knowledge of what other archives
42-
// would want, this will have to become more complicated if we wnat
43-
// to unit test ones other than ELAR.
44-
project.properties.setText("accessProtocol", "ELAR");
45-
46-
const person1 = project.addPerson("Person 1");
47-
await person1.addFileForTestAsync("Person 1_Consent.JPG");
48-
const person2 = project.addPerson("Person 2");
49-
await person2.addFileForTestAsync("Person 2_Consent.JPG");
50-
const person3 = project.addPerson("Person 3");
51-
// person 3 has no consent form
52-
53-
const session = project.addSession();
54-
session.addContribution(
55-
new Contribution(person1.getIdToUseForReferences(), "Consultant", "blah")
56-
);
57-
session.addContribution(
58-
new Contribution(person2.getIdToUseForReferences(), "Speaker", "blah")
59-
);
60-
session.addContribution(
61-
new Contribution(person3.getIdToUseForReferences(), "Translator", "blah")
62-
);
63-
64-
await ImdiBundler.addConsentBundle(
65-
project,
66-
targetDir, // review is it this or targetDir?
67-
"",
68-
[],
69-
IMDIMode.OPEX,
70-
true, //<-- copy in files
71-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
72-
(f) => true,
73-
true
22+
const thisSpecDir = Path.join(
23+
os.tmpdir(),
24+
"consent opex+files bundler tests"
7425
);
26+
[thisRunDir, targetDir] = await doExport(IMDIMode.OPEX, thisSpecDir, true);
7527
const xml = fs.readFileSync(
7628
Path.join(targetDir, "ConsentDocuments", "ConsentDocuments.opex"),
7729
"utf8"
@@ -129,3 +81,79 @@ describe("Consent Form Inclusion", () => {
12981
);
13082
});
13183
});
84+
85+
describe("Consent in IMDI-only export", () => {
86+
let thisRunDir: string;
87+
let targetDir: string;
88+
beforeAll(async () => {
89+
const thisSpecDir = Path.join(os.tmpdir(), "consent imdi bundler tests");
90+
fs.mkdirSync(thisSpecDir, { recursive: true });
91+
[thisRunDir, targetDir] = await doExport(
92+
IMDIMode.RAW_IMDI,
93+
thisSpecDir,
94+
false
95+
);
96+
});
97+
it("The file ConsentDocuments.imdi should exist", () => {
98+
expect(
99+
fs.existsSync(Path.join(targetDir, "ConsentDocuments.imdi"))
100+
).toBeTruthy();
101+
});
102+
});
103+
104+
async function doExport(
105+
imdiMode: IMDIMode,
106+
thisSpecDir: string,
107+
includeFiles: boolean
108+
): Promise<[thisRunDir: string, targetDir: string]> {
109+
let thisRunDir: string;
110+
let targetDir: string;
111+
fs.mkdirSync(thisSpecDir, { recursive: true });
112+
const randomStringForFileName = Math.random().toString(36).substring(7);
113+
thisRunDir = Path.join(thisSpecDir, "run-" + randomStringForFileName);
114+
fs.mkdirSync(thisRunDir);
115+
const projectDir = Path.join(thisRunDir, "projectDir");
116+
fs.mkdirSync(projectDir);
117+
targetDir = Path.join(thisRunDir, "target");
118+
fs.mkdirSync(targetDir);
119+
120+
const project = Project.fromDirectory(projectDir);
121+
122+
// NB: this is to test the access protocol used for consent bundles,
123+
// which has a hard-coded knowledge of the access protocol used for
124+
// ELAR currently. If/when we add knowledge of what other archives
125+
// would want, this will have to become more complicated if we wnat
126+
// to unit test ones other than ELAR.
127+
project.properties.setText("accessProtocol", "ELAR");
128+
129+
const person1 = project.addPerson("Person 1");
130+
await person1.addFileForTestAsync("Person 1_Consent.JPG");
131+
const person2 = project.addPerson("Person 2");
132+
await person2.addFileForTestAsync("Person 2_Consent.JPG");
133+
const person3 = project.addPerson("Person 3");
134+
// person 3 has no consent form
135+
136+
const session = project.addSession();
137+
session.addContribution(
138+
new Contribution(person1.getIdToUseForReferences(), "Consultant", "blah")
139+
);
140+
session.addContribution(
141+
new Contribution(person2.getIdToUseForReferences(), "Speaker", "blah")
142+
);
143+
session.addContribution(
144+
new Contribution(person3.getIdToUseForReferences(), "Translator", "blah")
145+
);
146+
147+
await ImdiBundler.addConsentBundle(
148+
project,
149+
targetDir, // review is it this or targetDir?
150+
"",
151+
[],
152+
imdiMode,
153+
includeFiles,
154+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
155+
(f) => true,
156+
true
157+
);
158+
return [thisRunDir, targetDir];
159+
}

0 commit comments

Comments
 (0)