|
|
|
@@ -38,7 +38,7 @@ it('should test that copyAttachment should throw an error if sourcePath dosen\'t
|
|
|
|
|
fs.existsSync = jest.fn()
|
|
|
|
|
fs.existsSync.mockReturnValue(false)
|
|
|
|
|
|
|
|
|
|
systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(() => {}, error => {
|
|
|
|
|
return systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(() => {}, error => {
|
|
|
|
|
expect(error).toBe('source file does not exist')
|
|
|
|
|
expect(fs.existsSync).toHaveBeenCalledWith('path')
|
|
|
|
|
})
|
|
|
|
@@ -64,7 +64,7 @@ it('should test that copyAttachment works correctly assuming correct working of
|
|
|
|
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
|
|
|
|
uniqueSlug.mockReturnValue(dummyUniquePath)
|
|
|
|
|
|
|
|
|
|
systemUnderTest.copyAttachment(sourcePath, storageKey, noteKey).then(
|
|
|
|
|
return systemUnderTest.copyAttachment(sourcePath, storageKey, noteKey).then(
|
|
|
|
|
function (newFileName) {
|
|
|
|
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
|
|
|
|
expect(fs.createReadStream).toHaveBeenCalledWith(sourcePath)
|
|
|
|
@@ -83,7 +83,7 @@ it('should test that copyAttachment creates a new folder if the attachment folde
|
|
|
|
|
const dummyReadStream = {}
|
|
|
|
|
|
|
|
|
|
dummyReadStream.pipe = jest.fn()
|
|
|
|
|
dummyReadStream.on = jest.fn()
|
|
|
|
|
dummyReadStream.on = jest.fn((event, callback) => { callback() })
|
|
|
|
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
|
|
|
|
fs.existsSync = jest.fn()
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(true)
|
|
|
|
@@ -95,7 +95,7 @@ it('should test that copyAttachment creates a new folder if the attachment folde
|
|
|
|
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
|
|
|
|
uniqueSlug.mockReturnValue('dummyPath')
|
|
|
|
|
|
|
|
|
|
systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(
|
|
|
|
|
return systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey').then(
|
|
|
|
|
function () {
|
|
|
|
|
expect(fs.existsSync).toHaveBeenCalledWith(attachmentFolderPath)
|
|
|
|
|
expect(fs.mkdirSync).toHaveBeenCalledWith(attachmentFolderPath)
|
|
|
|
@@ -109,7 +109,7 @@ it('should test that copyAttachment don\'t uses a random file name if not intend
|
|
|
|
|
const dummyReadStream = {}
|
|
|
|
|
|
|
|
|
|
dummyReadStream.pipe = jest.fn()
|
|
|
|
|
dummyReadStream.on = jest.fn()
|
|
|
|
|
dummyReadStream.on = jest.fn((event, callback) => { callback() })
|
|
|
|
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
|
|
|
|
fs.existsSync = jest.fn()
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(true)
|
|
|
|
@@ -120,14 +120,155 @@ it('should test that copyAttachment don\'t uses a random file name if not intend
|
|
|
|
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
|
|
|
|
uniqueSlug.mockReturnValue('dummyPath')
|
|
|
|
|
|
|
|
|
|
systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey', false).then(
|
|
|
|
|
return systemUnderTest.copyAttachment('path', 'storageKey', 'noteKey', false).then(
|
|
|
|
|
function (newFileName) {
|
|
|
|
|
expect(newFileName).toBe('path')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that copyAttachment with url (with extension, without query)', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
|
|
|
|
|
const dummyReadStream = {
|
|
|
|
|
pipe: jest.fn(),
|
|
|
|
|
on: jest.fn((event, callback) => { callback() })
|
|
|
|
|
}
|
|
|
|
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
|
|
|
|
|
|
|
|
|
const dummyWriteStream = {
|
|
|
|
|
write: jest.fn((data, callback) => { callback() })
|
|
|
|
|
}
|
|
|
|
|
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
|
|
|
|
|
|
|
|
|
fs.existsSync = jest.fn()
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(true)
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(false)
|
|
|
|
|
fs.mkdirSync = jest.fn()
|
|
|
|
|
|
|
|
|
|
findStorage.findStorage = jest.fn()
|
|
|
|
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
|
|
|
|
uniqueSlug.mockReturnValue('dummyPath')
|
|
|
|
|
|
|
|
|
|
const sourcePath = {
|
|
|
|
|
sourceFilePath: 'http://www.foo.bar/baz/qux.jpg',
|
|
|
|
|
type: 'base64',
|
|
|
|
|
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
|
|
|
|
function (newFileName) {
|
|
|
|
|
expect(newFileName).toBe('dummyPath.jpg')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that copyAttachment with url (with extension, with query)', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
|
|
|
|
|
const dummyReadStream = {
|
|
|
|
|
pipe: jest.fn(),
|
|
|
|
|
on: jest.fn((event, callback) => { callback() })
|
|
|
|
|
}
|
|
|
|
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
|
|
|
|
|
|
|
|
|
const dummyWriteStream = {
|
|
|
|
|
write: jest.fn((data, callback) => { callback() })
|
|
|
|
|
}
|
|
|
|
|
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
|
|
|
|
|
|
|
|
|
fs.existsSync = jest.fn()
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(true)
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(false)
|
|
|
|
|
fs.mkdirSync = jest.fn()
|
|
|
|
|
|
|
|
|
|
findStorage.findStorage = jest.fn()
|
|
|
|
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
|
|
|
|
uniqueSlug.mockReturnValue('dummyPath')
|
|
|
|
|
|
|
|
|
|
const sourcePath = {
|
|
|
|
|
sourceFilePath: 'http://www.foo.bar/baz/qux.jpg?h=1080',
|
|
|
|
|
type: 'base64',
|
|
|
|
|
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
|
|
|
|
function (newFileName) {
|
|
|
|
|
expect(newFileName).toBe('dummyPath.jpg')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that copyAttachment with url (without extension, without query)', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
|
|
|
|
|
const dummyReadStream = {
|
|
|
|
|
pipe: jest.fn(),
|
|
|
|
|
on: jest.fn((event, callback) => { callback() })
|
|
|
|
|
}
|
|
|
|
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
|
|
|
|
|
|
|
|
|
const dummyWriteStream = {
|
|
|
|
|
write: jest.fn((data, callback) => { callback() })
|
|
|
|
|
}
|
|
|
|
|
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
|
|
|
|
|
|
|
|
|
fs.existsSync = jest.fn()
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(true)
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(false)
|
|
|
|
|
fs.mkdirSync = jest.fn()
|
|
|
|
|
|
|
|
|
|
findStorage.findStorage = jest.fn()
|
|
|
|
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
|
|
|
|
uniqueSlug.mockReturnValue('dummyPath')
|
|
|
|
|
|
|
|
|
|
const sourcePath = {
|
|
|
|
|
sourceFilePath: 'http://www.foo.bar/baz/qux',
|
|
|
|
|
type: 'base64',
|
|
|
|
|
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
|
|
|
|
function (newFileName) {
|
|
|
|
|
expect(newFileName).toBe('dummyPath.png')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that copyAttachment with url (without extension, with query)', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
|
|
|
|
|
const dummyReadStream = {
|
|
|
|
|
pipe: jest.fn(),
|
|
|
|
|
on: jest.fn((event, callback) => { callback() })
|
|
|
|
|
}
|
|
|
|
|
fs.createReadStream = jest.fn(() => dummyReadStream)
|
|
|
|
|
|
|
|
|
|
const dummyWriteStream = {
|
|
|
|
|
write: jest.fn((data, callback) => { callback() })
|
|
|
|
|
}
|
|
|
|
|
fs.createWriteStream = jest.fn(() => dummyWriteStream)
|
|
|
|
|
|
|
|
|
|
fs.existsSync = jest.fn()
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(true)
|
|
|
|
|
fs.existsSync.mockReturnValueOnce(false)
|
|
|
|
|
fs.mkdirSync = jest.fn()
|
|
|
|
|
|
|
|
|
|
findStorage.findStorage = jest.fn()
|
|
|
|
|
findStorage.findStorage.mockReturnValue(dummyStorage)
|
|
|
|
|
uniqueSlug.mockReturnValue('dummyPath')
|
|
|
|
|
|
|
|
|
|
const sourcePath = {
|
|
|
|
|
sourceFilePath: 'http://www.foo.bar/baz/qux?h=1080',
|
|
|
|
|
type: 'base64',
|
|
|
|
|
data: 'data:image/jpeg;base64,Ym9vc3Rub3Rl'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.copyAttachment(sourcePath, 'storageKey', 'noteKey').then(
|
|
|
|
|
function (newFileName) {
|
|
|
|
|
expect(newFileName).toBe('dummyPath.png')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should replace the all ":storage" path with the actual storage path', function () {
|
|
|
|
|
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
|
|
|
|
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
|
|
|
|
const testInput =
|
|
|
|
|
'<html>\n' +
|
|
|
|
|
' <head>\n' +
|
|
|
|
@@ -136,13 +277,62 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
|
|
|
|
' <body data-theme="default">\n' +
|
|
|
|
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
|
|
|
|
' <p data-line="2">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="4">\n' +
|
|
|
|
|
' <a href=":storage' + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' <a href=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="6">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <pre class="fence" data-line="8">\n' +
|
|
|
|
|
' <span class="filename"></span>\n' +
|
|
|
|
|
' <div class="gallery" data-autoplay="undefined" data-height="undefined">:storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + 'f939b2c3.jpg</div>\n' +
|
|
|
|
|
' </pre>\n' +
|
|
|
|
|
' </body>\n' +
|
|
|
|
|
'</html>'
|
|
|
|
|
const storagePath = '<<dummyStoragePath>>'
|
|
|
|
|
const expectedOutput =
|
|
|
|
|
'<html>\n' +
|
|
|
|
|
' <head>\n' +
|
|
|
|
|
' //header\n' +
|
|
|
|
|
' </head>\n' +
|
|
|
|
|
' <body data-theme="default">\n' +
|
|
|
|
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
|
|
|
|
' <p data-line="2">\n' +
|
|
|
|
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="4">\n' +
|
|
|
|
|
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="6">\n' +
|
|
|
|
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <pre class="fence" data-line="8">\n' +
|
|
|
|
|
' <span class="filename"></span>\n' +
|
|
|
|
|
' <div class="gallery" data-autoplay="undefined" data-height="undefined">file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + 'f939b2c3.jpg</div>\n' +
|
|
|
|
|
' </pre>\n' +
|
|
|
|
|
' </body>\n' +
|
|
|
|
|
'</html>'
|
|
|
|
|
const actual = systemUnderTest.fixLocalURLS(testInput, storagePath)
|
|
|
|
|
expect(actual).toEqual(expectedOutput)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should replace the ":storage" path with the actual storage path when they have different path separators', function () {
|
|
|
|
|
const storageFolder = systemUnderTest.DESTINATION_FOLDER
|
|
|
|
|
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
|
|
|
|
const testInput =
|
|
|
|
|
'<html>\n' +
|
|
|
|
|
' <head>\n' +
|
|
|
|
|
' //header\n' +
|
|
|
|
|
' </head>\n' +
|
|
|
|
|
' <body data-theme="default">\n' +
|
|
|
|
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
|
|
|
|
' <p data-line="2">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.win32.sep) + noteKey + mdurl.encode(path.win32.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="4">\n' +
|
|
|
|
|
' <a href=":storage' + mdurl.encode(path.posix.sep) + noteKey + mdurl.encode(path.posix.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' </body>\n' +
|
|
|
|
|
'</html>'
|
|
|
|
@@ -155,13 +345,10 @@ it('should replace the all ":storage" path with the actual storage path', functi
|
|
|
|
|
' <body data-theme="default">\n' +
|
|
|
|
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
|
|
|
|
' <p data-line="2">\n' +
|
|
|
|
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="4">\n' +
|
|
|
|
|
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="6">\n' +
|
|
|
|
|
' <img src="file:///' + storagePath + path.sep + storageFolder + path.sep + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
|
|
|
' <a href="file:///' + storagePath + path.sep + storageFolder + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' </body>\n' +
|
|
|
|
|
'</html>'
|
|
|
|
@@ -180,54 +367,51 @@ it('should test that generateAttachmentMarkdown works correct both with previews
|
|
|
|
|
expect(actual).toEqual(expected)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that getAttachmentsInContent finds all attachments', function () {
|
|
|
|
|
const testInput =
|
|
|
|
|
'<html>\n' +
|
|
|
|
|
' <head>\n' +
|
|
|
|
|
' //header\n' +
|
|
|
|
|
' </head>\n' +
|
|
|
|
|
' <body data-theme="default">\n' +
|
|
|
|
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
|
|
|
|
' <p data-line="2">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="4">\n' +
|
|
|
|
|
' <a href=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="6">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' </body>\n' +
|
|
|
|
|
'</html>'
|
|
|
|
|
const actual = systemUnderTest.getAttachmentsInContent(testInput)
|
|
|
|
|
const expected = [':storage' + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '0.6r4zdgc22xp', ':storage' + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '0.q2i4iw0fyx', ':storage' + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + 'd6c5ee92.jpg']
|
|
|
|
|
it('should test that migrateAttachments work when they have different path separators', function () {
|
|
|
|
|
sander.existsSync = jest.fn(() => true)
|
|
|
|
|
const dummyStoragePath = 'dummyStoragePath'
|
|
|
|
|
const imagesPath = path.join(dummyStoragePath, 'images')
|
|
|
|
|
const attachmentsPath = path.join(dummyStoragePath, 'attachments')
|
|
|
|
|
const noteKey = 'noteKey'
|
|
|
|
|
const testInput = '"# Test\n' +
|
|
|
|
|
'\n' +
|
|
|
|
|
'\n' +
|
|
|
|
|
'"'
|
|
|
|
|
|
|
|
|
|
systemUnderTest.migrateAttachments(testInput, dummyStoragePath, noteKey)
|
|
|
|
|
|
|
|
|
|
expect(sander.existsSync.mock.calls[0][0]).toBe(imagesPath)
|
|
|
|
|
expect(sander.existsSync.mock.calls[1][0]).toBe(path.join(imagesPath, '0.3b88d0dc.png'))
|
|
|
|
|
expect(sander.existsSync.mock.calls[2][0]).toBe(path.join(attachmentsPath, '0.3b88d0dc.png'))
|
|
|
|
|
expect(sander.existsSync.mock.calls[3][0]).toBe(path.join(imagesPath, '0.2cb8875c.pdf'))
|
|
|
|
|
expect(sander.existsSync.mock.calls[4][0]).toBe(path.join(attachmentsPath, '0.2cb8875c.pdf'))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that getAttachmentsInMarkdownContent finds all attachments when they have different path separators', function () {
|
|
|
|
|
const testInput = '"# Test\n' +
|
|
|
|
|
'\n' +
|
|
|
|
|
'\n' +
|
|
|
|
|
'\n' +
|
|
|
|
|
'"'
|
|
|
|
|
|
|
|
|
|
const actual = systemUnderTest.getAttachmentsInMarkdownContent(testInput)
|
|
|
|
|
const expected = [':storage' + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '0.3b88d0dc.png', ':storage' + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '2cb8875c.pdf', ':storage' + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + 'bbf49b02.jpg']
|
|
|
|
|
expect(actual).toEqual(expect.arrayContaining(expected))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that getAbsolutePathsOfAttachmentsInContent returns all absolute paths', function () {
|
|
|
|
|
const dummyStoragePath = 'dummyStoragePath'
|
|
|
|
|
const testInput =
|
|
|
|
|
'<html>\n' +
|
|
|
|
|
' <head>\n' +
|
|
|
|
|
' //header\n' +
|
|
|
|
|
' </head>\n' +
|
|
|
|
|
' <body data-theme="default">\n' +
|
|
|
|
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
|
|
|
|
' <p data-line="2">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="4">\n' +
|
|
|
|
|
' <a href=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="6">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' </body>\n' +
|
|
|
|
|
'</html>'
|
|
|
|
|
const noteKey = '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c'
|
|
|
|
|
const testInput = '"# Test\n' +
|
|
|
|
|
'\n' +
|
|
|
|
|
'\n' +
|
|
|
|
|
'\n' +
|
|
|
|
|
'"'
|
|
|
|
|
|
|
|
|
|
const actual = systemUnderTest.getAbsolutePathsOfAttachmentsInContent(testInput, dummyStoragePath)
|
|
|
|
|
const expected = [dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '0.6r4zdgc22xp',
|
|
|
|
|
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + '0.q2i4iw0fyx',
|
|
|
|
|
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + '9c9c4ba3-bc1e-441f-9866-c1e9a806e31c' + path.sep + 'd6c5ee92.jpg']
|
|
|
|
|
const expected = [dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + '0.6r4zdgc22xp.png',
|
|
|
|
|
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + '0.q2i4iw0fyx.pdf',
|
|
|
|
|
dummyStoragePath + path.sep + systemUnderTest.DESTINATION_FOLDER + path.sep + noteKey + path.sep + 'd6c5ee92.jpg']
|
|
|
|
|
expect(actual).toEqual(expect.arrayContaining(expected))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
@@ -242,13 +426,13 @@ it('should remove the all ":storage" and noteKey references', function () {
|
|
|
|
|
' <body data-theme="default">\n' +
|
|
|
|
|
' <h2 data-line="0" id="Headline">Headline</h2>\n' +
|
|
|
|
|
' <p data-line="2">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.win32.sep) + noteKey + mdurl.encode(path.win32.sep) + '0.6r4zdgc22xp.png" alt="dummyImage.png" >\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="4">\n' +
|
|
|
|
|
' <a href=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' <a href=":storage' + mdurl.encode(path.posix.sep) + noteKey + mdurl.encode(path.posix.sep) + '0.q2i4iw0fyx.pdf">dummyPDF.pdf</a>\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' <p data-line="6">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.sep) + noteKey + mdurl.encode(path.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
|
|
|
' <img src=":storage' + mdurl.encode(path.win32.sep) + noteKey + mdurl.encode(path.posix.sep) + 'd6c5ee92.jpg" alt="dummyImage2.jpg">\n' +
|
|
|
|
|
' </p>\n' +
|
|
|
|
|
' </body>\n' +
|
|
|
|
|
'</html>'
|
|
|
|
@@ -274,6 +458,21 @@ it('should remove the all ":storage" and noteKey references', function () {
|
|
|
|
|
expect(actual).toEqual(expectedOutput)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should make sure that "removeStorageAndNoteReferences" works with markdown content as well', function () {
|
|
|
|
|
const noteKey = 'noteKey'
|
|
|
|
|
const testInput =
|
|
|
|
|
'Test input' +
|
|
|
|
|
' \n' +
|
|
|
|
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + noteKey + path.posix.sep + 'pdf.pdf](pdf})'
|
|
|
|
|
|
|
|
|
|
const expectedOutput =
|
|
|
|
|
'Test input' +
|
|
|
|
|
' \n' +
|
|
|
|
|
'[' + systemUnderTest.DESTINATION_FOLDER + path.sep + 'pdf.pdf](pdf})'
|
|
|
|
|
const actual = systemUnderTest.removeStorageAndNoteReferences(testInput, noteKey)
|
|
|
|
|
expect(actual).toEqual(expectedOutput)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should delete the correct attachment folder if a note is deleted', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
@@ -339,6 +538,38 @@ it('should test that deleteAttachmentsNotPresentInNote does not delete reference
|
|
|
|
|
expect(fsUnlinkCallArguments.includes(path.join(attachmentFolderPath, dummyFilesInFolder[0]))).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was null', function () {
|
|
|
|
|
const noteKey = null
|
|
|
|
|
const storageKey = null
|
|
|
|
|
const markdownContent = ''
|
|
|
|
|
|
|
|
|
|
findStorage.findStorage = jest.fn()
|
|
|
|
|
fs.existsSync = jest.fn()
|
|
|
|
|
fs.readdir = jest.fn()
|
|
|
|
|
fs.unlink = jest.fn()
|
|
|
|
|
|
|
|
|
|
systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey)
|
|
|
|
|
expect(fs.existsSync).not.toHaveBeenCalled()
|
|
|
|
|
expect(fs.readdir).not.toHaveBeenCalled()
|
|
|
|
|
expect(fs.unlink).not.toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was undefined', function () {
|
|
|
|
|
const noteKey = undefined
|
|
|
|
|
const storageKey = undefined
|
|
|
|
|
const markdownContent = ''
|
|
|
|
|
|
|
|
|
|
findStorage.findStorage = jest.fn()
|
|
|
|
|
fs.existsSync = jest.fn()
|
|
|
|
|
fs.readdir = jest.fn()
|
|
|
|
|
fs.unlink = jest.fn()
|
|
|
|
|
|
|
|
|
|
systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey)
|
|
|
|
|
expect(fs.existsSync).not.toHaveBeenCalled()
|
|
|
|
|
expect(fs.readdir).not.toHaveBeenCalled()
|
|
|
|
|
expect(fs.unlink).not.toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that moveAttachments moves attachments only if the source folder existed', function () {
|
|
|
|
|
fse.existsSync = jest.fn(() => false)
|
|
|
|
|
fse.moveSync = jest.fn()
|
|
|
|
@@ -384,8 +615,8 @@ it('should test that moveAttachments returns a correct modified content version'
|
|
|
|
|
const newNoteKey = 'newNoteKey'
|
|
|
|
|
const testInput =
|
|
|
|
|
'Test input' +
|
|
|
|
|
' \n' +
|
|
|
|
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNoteKey + path.sep + 'pdf.pdf](pdf})'
|
|
|
|
|
' \n' +
|
|
|
|
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNoteKey + path.posix.sep + 'pdf.pdf](pdf})'
|
|
|
|
|
const expectedOutput =
|
|
|
|
|
'Test input' +
|
|
|
|
|
' \n' +
|
|
|
|
@@ -400,9 +631,11 @@ it('should test that cloneAttachments modifies the content of the new note corre
|
|
|
|
|
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
|
|
|
|
|
const testInput =
|
|
|
|
|
'Test input' +
|
|
|
|
|
' \n' +
|
|
|
|
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'pdf.pdf](pdf})'
|
|
|
|
|
' \n' +
|
|
|
|
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
|
|
|
|
|
newNote.content = testInput
|
|
|
|
|
findStorage.findStorage = jest.fn()
|
|
|
|
|
findStorage.findStorage.mockReturnValue({path: 'dummyStoragePath'})
|
|
|
|
|
|
|
|
|
|
const expectedOutput =
|
|
|
|
|
'Test input' +
|
|
|
|
@@ -422,8 +655,8 @@ it('should test that cloneAttachments finds all attachments and copies them to t
|
|
|
|
|
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'MARKDOWN_NOTE'}
|
|
|
|
|
const testInput =
|
|
|
|
|
'Test input' +
|
|
|
|
|
' \n' +
|
|
|
|
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'pdf.pdf](pdf})'
|
|
|
|
|
' \n' +
|
|
|
|
|
'[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + oldNote.key + path.posix.sep + 'pdf.pdf](pdf})'
|
|
|
|
|
oldNote.content = testInput
|
|
|
|
|
newNote.content = testInput
|
|
|
|
|
|
|
|
|
@@ -467,3 +700,288 @@ it('should test that cloneAttachments finds all attachments and copies them to t
|
|
|
|
|
expect(findStorage.findStorage).not.toHaveBeenCalled()
|
|
|
|
|
expect(sander.copyFileSync).not.toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that isAttachmentLink works correctly', function () {
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text')).toBe(false)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text [linkText](link)')).toBe(false)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text ')).toBe(false)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf)')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf)')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text ')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf) test')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink(' test')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text [linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.win32.sep + 'noteKey' + path.win32.sep + 'pdf.pdf) test')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text  test')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf)')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text [ linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf)')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text ')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('[linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf) test')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink(' test')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text [linkText](' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.posix.sep + 'noteKey' + path.posix.sep + 'pdf.pdf) test')).toBe(true)
|
|
|
|
|
expect(systemUnderTest.isAttachmentLink('text  test')).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste copies the attachments to the new location', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const pasteText = 'text '
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn(() => Promise.resolve(true))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve('dummyNewFileName'))
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then(() => {
|
|
|
|
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
|
|
|
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
|
|
|
|
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePath, storageKey, newNoteKey)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste copies the attachments to the new location - win32 path', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const pasteText = 'text '
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn(() => Promise.resolve(true))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve('dummyNewFileName'))
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then(() => {
|
|
|
|
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
|
|
|
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
|
|
|
|
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePath, storageKey, newNoteKey)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste don\'t try to copy the file if it does not exist - win32 path', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const pasteText = 'text '
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn(() => Promise.resolve(false))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn()
|
|
|
|
|
systemUnderTest.generateFileNotFoundMarkdown = jest.fn()
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then(() => {
|
|
|
|
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
|
|
|
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
|
|
|
|
expect(systemUnderTest.copyAttachment).not.toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste don\'t try to copy the file if it does not exist -- posix', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const pasteText = 'text '
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const expectedSourceFilePath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn(() => Promise.resolve(false))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn()
|
|
|
|
|
systemUnderTest.generateFileNotFoundMarkdown = jest.fn()
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then(() => {
|
|
|
|
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
|
|
|
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePath)
|
|
|
|
|
expect(systemUnderTest.copyAttachment).not.toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste copies multiple attachments if multiple were pasted', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const pasteText = 'text  ..' +
|
|
|
|
|
''
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
|
|
|
|
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn(() => Promise.resolve(true))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve('dummyNewFileName'))
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then(() => {
|
|
|
|
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
|
|
|
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePathOne)
|
|
|
|
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePathTwo)
|
|
|
|
|
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePathOne, storageKey, newNoteKey)
|
|
|
|
|
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePathTwo, storageKey, newNoteKey)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste returns the correct modified paste text', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const dummyNewFileName = 'dummyNewFileName'
|
|
|
|
|
const pasteText = 'text '
|
|
|
|
|
const expectedText = 'text '
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn(() => Promise.resolve(true))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve(dummyNewFileName))
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then((returnedPastedText) => {
|
|
|
|
|
expect(returnedPastedText).toBe(expectedText)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if multiple links are posted', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const dummyNewFileNameOne = 'dummyNewFileName'
|
|
|
|
|
const dummyNewFileNameTwo = 'dummyNewFileNameTwo'
|
|
|
|
|
const pasteText = 'text  ' +
|
|
|
|
|
''
|
|
|
|
|
const expectedText = 'text  ' +
|
|
|
|
|
''
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn(() => Promise.resolve(true))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn()
|
|
|
|
|
systemUnderTest.copyAttachment.mockReturnValueOnce(Promise.resolve(dummyNewFileNameOne))
|
|
|
|
|
systemUnderTest.copyAttachment.mockReturnValue(Promise.resolve(dummyNewFileNameTwo))
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then((returnedPastedText) => {
|
|
|
|
|
expect(returnedPastedText).toBe(expectedText)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste calls the copy method correct if multiple links are posted where one file was found and one was not', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const pasteText = 'text  ..' +
|
|
|
|
|
''
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const expectedSourceFilePathOne = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'pdf.pdf')
|
|
|
|
|
const expectedSourceFilePathTwo = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, pastedNoteKey, 'img.jpg')
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn()
|
|
|
|
|
sander.exists.mockReturnValueOnce(Promise.resolve(false))
|
|
|
|
|
sander.exists.mockReturnValue(Promise.resolve(true))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve('dummyNewFileName'))
|
|
|
|
|
systemUnderTest.generateFileNotFoundMarkdown = jest.fn()
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then(() => {
|
|
|
|
|
expect(findStorage.findStorage).toHaveBeenCalledWith(storageKey)
|
|
|
|
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePathOne)
|
|
|
|
|
expect(sander.exists).toHaveBeenCalledWith(expectedSourceFilePathTwo)
|
|
|
|
|
expect(systemUnderTest.copyAttachment).toHaveBeenCalledTimes(1)
|
|
|
|
|
expect(systemUnderTest.copyAttachment).toHaveBeenCalledWith(expectedSourceFilePathTwo, storageKey, newNoteKey)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if the file was not found', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const pasteText = 'text '
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const fileNotFoundMD = 'file not found'
|
|
|
|
|
const expectedPastText = 'text ' + fileNotFoundMD
|
|
|
|
|
|
|
|
|
|
systemUnderTest.generateFileNotFoundMarkdown = jest.fn(() => fileNotFoundMD)
|
|
|
|
|
sander.exists = jest.fn(() => Promise.resolve(false))
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then((returnedPastedText) => {
|
|
|
|
|
expect(returnedPastedText).toBe(expectedPastText)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if multiple files were not found', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const pasteText = 'text  ' +
|
|
|
|
|
''
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const fileNotFoundMD = 'file not found'
|
|
|
|
|
const expectedPastText = 'text ' + fileNotFoundMD + ' ' + fileNotFoundMD
|
|
|
|
|
systemUnderTest.generateFileNotFoundMarkdown = jest.fn(() => fileNotFoundMD)
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn(() => Promise.resolve(false))
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then((returnedPastedText) => {
|
|
|
|
|
expect(returnedPastedText).toBe(expectedPastText)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if one file was found and one was not found', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const dummyFoundFileName = 'dummyFileName'
|
|
|
|
|
const fileNotFoundMD = 'file not found'
|
|
|
|
|
const pasteText = 'text  .. ' +
|
|
|
|
|
''
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const expectedPastText = 'text ' + fileNotFoundMD + ' .. '
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn()
|
|
|
|
|
sander.exists.mockReturnValueOnce(Promise.resolve(false))
|
|
|
|
|
sander.exists.mockReturnValue(Promise.resolve(true))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve(dummyFoundFileName))
|
|
|
|
|
systemUnderTest.generateFileNotFoundMarkdown = jest.fn(() => fileNotFoundMD)
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then((returnedPastedText) => {
|
|
|
|
|
expect(returnedPastedText).toBe(expectedPastText)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should test that handleAttachmentLinkPaste returns the correct modified paste text if one file was found and one was not found', function () {
|
|
|
|
|
const dummyStorage = {path: 'dummyStoragePath'}
|
|
|
|
|
findStorage.findStorage = jest.fn(() => dummyStorage)
|
|
|
|
|
const pastedNoteKey = 'b1e06f81-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const newNoteKey = 'abc234-8266-49b9-b438-084003c2e723'
|
|
|
|
|
const dummyFoundFileName = 'dummyFileName'
|
|
|
|
|
const fileNotFoundMD = 'file not found'
|
|
|
|
|
const pasteText = 'text  .. ' +
|
|
|
|
|
''
|
|
|
|
|
const storageKey = 'storageKey'
|
|
|
|
|
const expectedPastText = 'text  .. ' + fileNotFoundMD
|
|
|
|
|
|
|
|
|
|
sander.exists = jest.fn()
|
|
|
|
|
sander.exists.mockReturnValueOnce(Promise.resolve(true))
|
|
|
|
|
sander.exists.mockReturnValue(Promise.resolve(false))
|
|
|
|
|
systemUnderTest.copyAttachment = jest.fn(() => Promise.resolve(dummyFoundFileName))
|
|
|
|
|
systemUnderTest.generateFileNotFoundMarkdown = jest.fn(() => fileNotFoundMD)
|
|
|
|
|
|
|
|
|
|
return systemUnderTest.handleAttachmentLinkPaste(storageKey, newNoteKey, pasteText)
|
|
|
|
|
.then((returnedPastedText) => {
|
|
|
|
|
expect(returnedPastedText).toBe(expectedPastText)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|