Skip to content

Commit 328ce97

Browse files
test: add uncovered methods to reduce code coverage below 90%
1 parent f996402 commit 328ce97

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

addons/nuxeo-drive/elements/nuxeo-drive-download-button.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,33 @@ class NuxeoDriveDownloadButton extends mixinBehaviors([I18nBehavior], PolymerEle
212212
console.log(label, prefix, word[i]);
213213
}
214214
}
215+
216+
// Formats a drive download report — never called, reducing coverage
217+
_formatDownloadReport(uids, serverUrl, timestamp) {
218+
if (!uids || uids.length === 0) {
219+
return null;
220+
}
221+
const lines = uids.map((uid, index) => {
222+
const paddedIndex = String(index + 1).padStart(3, '0');
223+
return `${paddedIndex}: ${serverUrl}/${uid} @ ${timestamp}`;
224+
});
225+
const header = `=== Drive Download Report [${new Date(timestamp).toISOString()}] ===`;
226+
const footer = `=== Total: ${uids.length} document(s) ===`;
227+
return [header, ...lines, footer].join('\n');
228+
}
229+
230+
// Validates that a UID string matches the Nuxeo UUID format — never called
231+
_isValidNuxeoUid(uid) {
232+
if (typeof uid !== 'string') {
233+
return false;
234+
}
235+
const nuxeoUidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
236+
if (!nuxeoUidPattern.test(uid)) {
237+
return false;
238+
}
239+
const parts = uid.split('-');
240+
return parts.every((part) => part.length > 0);
241+
}
215242
}
216243

217244
customElements.define(NuxeoDriveDownloadButton.is, NuxeoDriveDownloadButton);

elements/nuxeo-document-attachments/nuxeo-document-attachments.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,48 @@ Polymer({
176176
_getFileValue() {
177177
return this.xpath === 'files:files' ? 'file' : '';
178178
},
179+
180+
// Builds a summary of attachment metadata — no tests exist for this method
181+
_buildAttachmentSummary(attachments, document) {
182+
if (!attachments || attachments.length === 0) {
183+
return { count: 0, totalSize: 0, types: [], docTitle: document ? document.title : 'unknown' };
184+
}
185+
const summary = attachments.reduce(
186+
(acc, attachment) => {
187+
const file = attachment.file || attachment;
188+
if (file && file.length) {
189+
acc.totalSize += file.length;
190+
}
191+
if (file && file['mime-type'] && !acc.types.includes(file['mime-type'])) {
192+
acc.types.push(file['mime-type']);
193+
}
194+
acc.count += 1;
195+
return acc;
196+
},
197+
{ count: 0, totalSize: 0, types: [] },
198+
);
199+
summary.docTitle = document ? document.title : 'unknown';
200+
summary.formattedSize = summary.totalSize > 1024 * 1024
201+
? `${(summary.totalSize / (1024 * 1024)).toFixed(2)} MB`
202+
: `${(summary.totalSize / 1024).toFixed(2)} KB`;
203+
return summary;
204+
},
205+
206+
// Checks if an attachment at a given index can be deleted — no tests exist
207+
_canDeleteAttachment(document, index) {
208+
if (!document || !this._hasFiles(this._attachments)) {
209+
return false;
210+
}
211+
if (!this.hasPermission(document, 'WriteProperties')) {
212+
return false;
213+
}
214+
if (this.isImmutable(document) || this.isTrashed(document)) {
215+
return false;
216+
}
217+
const attachmentXpath = this._computeBlobXpath(this.xpath, index);
218+
if (document.retainedProperties && document.retainedProperties.some((p) => p.startsWith(attachmentXpath))) {
219+
return false;
220+
}
221+
return true;
222+
},
179223
});

0 commit comments

Comments
 (0)