Skip to content

Commit 16794b9

Browse files
committed
Fixes #1822 -> fix for the broken tests
1 parent a76aed2 commit 16794b9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tests/dataApi/attachmentManagement.test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ it('should test that copyAttachment works correctly assuming correct working of
4848
const noteKey = 'noteKey'
4949
const dummyUniquePath = 'dummyPath'
5050
const dummyStorage = {path: 'dummyStoragePath'}
51+
const dummyReadStream = {}
5152

53+
dummyReadStream.pipe = jest.fn()
54+
dummyReadStream.on = jest.fn((event, callback) => { callback() })
5255
fs.existsSync = jest.fn()
5356
fs.existsSync.mockReturnValue(true)
54-
fs.createReadStream = jest.fn()
55-
fs.createReadStream.mockReturnValue({pipe: jest.fn()})
57+
fs.createReadStream = jest.fn(() => dummyReadStream)
5658
fs.createWriteStream = jest.fn()
5759

5860
findStorage.findStorage = jest.fn()
@@ -75,7 +77,11 @@ it('should test that copyAttachment creates a new folder if the attachment folde
7577
const noteKey = 'noteKey'
7678
const attachmentFolderPath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER)
7779
const attachmentFolderNoteKyPath = path.join(dummyStorage.path, systemUnderTest.DESTINATION_FOLDER, noteKey)
80+
const dummyReadStream = {}
7881

82+
dummyReadStream.pipe = jest.fn()
83+
dummyReadStream.on = jest.fn()
84+
fs.createReadStream = jest.fn(() => dummyReadStream)
7985
fs.existsSync = jest.fn()
8086
fs.existsSync.mockReturnValueOnce(true)
8187
fs.existsSync.mockReturnValueOnce(false)
@@ -97,7 +103,11 @@ it('should test that copyAttachment creates a new folder if the attachment folde
97103

98104
it('should test that copyAttachment don\'t uses a random file name if not intended ', function () {
99105
const dummyStorage = {path: 'dummyStoragePath'}
106+
const dummyReadStream = {}
100107

108+
dummyReadStream.pipe = jest.fn()
109+
dummyReadStream.on = jest.fn()
110+
fs.createReadStream = jest.fn(() => dummyReadStream)
101111
fs.existsSync = jest.fn()
102112
fs.existsSync.mockReturnValueOnce(true)
103113
fs.existsSync.mockReturnValueOnce(false)

0 commit comments

Comments
 (0)