Skip to content

Commit 5b0b309

Browse files
ZeroX-DGRokt33r
authored andcommitted
added test for getAttachmentsPathAndStatus
1 parent 0b84a37 commit 5b0b309

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tests/dataApi/attachmentManagement.test.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,72 @@ it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey,
578578
expect(fs.unlink).not.toHaveBeenCalled()
579579
})
580580

581+
it('should test that getAttachmentsPathAndStatus return null if noteKey, storageKey or noteContent was undefined', function () {
582+
const noteKey = undefined
583+
const storageKey = undefined
584+
const markdownContent = ''
585+
586+
const result = systemUnderTest.getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey)
587+
expect(result).toBeNull()
588+
})
589+
590+
it('should test that getAttachmentsPathAndStatus return null if noteKey, storageKey or noteContent was null', function () {
591+
const noteKey = null
592+
const storageKey = null
593+
const markdownContent = ''
594+
595+
const result = systemUnderTest.getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey)
596+
expect(result).toBeNull()
597+
})
598+
599+
it('should test that getAttachmentsPathAndStatus return the correct path and status for attachments', async function () {
600+
const dummyStorage = {path: 'dummyStoragePath'}
601+
const noteKey = 'noteKey'
602+
const storageKey = 'storageKey'
603+
const markdownContent =
604+
'Test input' +
605+
'![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + noteKey + path.win32.sep + 'file2.pdf](file2.pdf) \n'
606+
const dummyFilesInFolder = ['file1.txt', 'file2.pdf', 'file3.jpg']
607+
608+
findStorage.findStorage = jest.fn(() => dummyStorage)
609+
fs.existsSync = jest.fn(() => true)
610+
fs.readdir = jest.fn((paht, callback) => callback(undefined, dummyFilesInFolder))
611+
fs.unlink = jest.fn()
612+
613+
const targetStorage = findStorage.findStorage(storageKey)
614+
615+
const attachments = await systemUnderTest.getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey)
616+
expect(attachments.length).toBe(3)
617+
expect(attachments[0].isInUse).toBe(false)
618+
expect(attachments[1].isInUse).toBe(true)
619+
expect(attachments[2].isInUse).toBe(false)
620+
621+
expect(attachments[0].path).toBe(
622+
path.join(
623+
targetStorage.path,
624+
systemUnderTest.DESTINATION_FOLDER,
625+
noteKey,
626+
dummyFilesInFolder[0]
627+
)
628+
)
629+
expect(attachments[1].path).toBe(
630+
path.join(
631+
targetStorage.path,
632+
systemUnderTest.DESTINATION_FOLDER,
633+
noteKey,
634+
dummyFilesInFolder[1]
635+
)
636+
)
637+
expect(attachments[2].path).toBe(
638+
path.join(
639+
targetStorage.path,
640+
systemUnderTest.DESTINATION_FOLDER,
641+
noteKey,
642+
dummyFilesInFolder[2]
643+
)
644+
)
645+
})
646+
581647
it('should test that moveAttachments moves attachments only if the source folder existed', function () {
582648
fse.existsSync = jest.fn(() => false)
583649
fse.moveSync = jest.fn()

0 commit comments

Comments
 (0)