Skip to content

Commit

Permalink
refactors to correctly check if dates are equal
Browse files Browse the repository at this point in the history
  • Loading branch information
utanapishtim committed Aug 12, 2024
1 parent 9e5dfcd commit ade3127
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/mixins/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ export default {

/** check two embedded file metadata objects for equality */
function isEqual(a, b) {
return (
const result = (
a.Subtype === b.Subtype &&
a.Params.CheckSum.toString() === b.Params.CheckSum.toString() &&
a.Params.Size === b.Params.Size &&
a.Params.CreationDate === b.Params.CreationDate &&
a.Params.ModDate === b.Params.ModDate
a.Params.CreationDate.toISOString() === b.Params.CreationDate.toISOString() &&
a.Params.ModDate.toISOString() === b.Params.ModDate.toISOString()
);
console.log('isEqual', result);
return result;
}
36 changes: 36 additions & 0 deletions tests/unit/attachments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ describe('file', () => {

test('attach multiple files', () => {
const docData = logData(document);
const duplicateDate = new Date(date)

document.file(Buffer.from('example text'), {
name: 'file1.txt',
Expand All @@ -192,6 +193,41 @@ describe('file', () => {
(file2.txt) 11 0 R
]
>>
>>`
]);
});

test('attach the same file multiple times', () => {
const docData = logData(document);

document.file(Buffer.from('example text'), {
name: 'file1.txt',
creationDate: date,
modifiedDate: date
});
document.file(Buffer.from('example text'), {
name: 'file1.txt',
creationDate: new Date(date),
modifiedDate: new Date(date)
});
document.end();

const numFiles = docData.filter((str) => typeof str === 'string' && str.startsWith('<<\n/Type /EmbeddedFile\n'))

expect(numFiles.length).toEqual(1)

expect(docData).toContainChunk([
`2 0 obj`,
`<<
/Dests <<
/Names [
]
>>
/EmbeddedFiles <<
/Names [
(file1.txt) 10 0 R
]
>>
>>`
]);
});
Expand Down

0 comments on commit ade3127

Please sign in to comment.