|
|
|
|
@ -8,8 +8,9 @@ const paths = { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('sending files', function sendfileSuite() { |
|
|
|
|
const bot = new TelegramBot('token '); |
|
|
|
|
describe('#_formatSendData', function sendfileSuite() { |
|
|
|
|
const bot = new TelegramBot('token'); |
|
|
|
|
const type = 'file'; |
|
|
|
|
|
|
|
|
|
before(function beforeSuite() { |
|
|
|
|
process.env.NTBA_FIX_350 = 1; |
|
|
|
|
@ -19,7 +20,6 @@ describe('sending files', function sendfileSuite() { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('using fileOptions', function sendfileOptionsSuite() { |
|
|
|
|
const type = 'file'; |
|
|
|
|
const stream = fs.createReadStream(paths.audio); |
|
|
|
|
const nonPathStream = fs.createReadStream(paths.audio); |
|
|
|
|
const buffer = fs.readFileSync(paths.audio); |
|
|
|
|
@ -105,4 +105,35 @@ describe('sending files', function sendfileSuite() { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should handle buffer path from fs.readStream', function test() { |
|
|
|
|
let file; |
|
|
|
|
try { |
|
|
|
|
file = fs.createReadStream(Buffer.from(paths.audio)); |
|
|
|
|
} catch (ex) { |
|
|
|
|
// Older Node.js versions do not support passing a Buffer
|
|
|
|
|
// representation of the path to fs.createReadStream()
|
|
|
|
|
if (ex instanceof TypeError) { |
|
|
|
|
Promise.resolve(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const [{ [type]: data }] = bot._formatSendData('file', file); |
|
|
|
|
assert.equal(data.options.filename, path.basename(paths.audio)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should not accept file-paths if disallowed with constructor option', function test() { |
|
|
|
|
const tgbot = new TelegramBot('token', { filepath: false }); |
|
|
|
|
const [formData, fileId] = tgbot._formatSendData('file', paths.audio); |
|
|
|
|
assert.ok(fileId); |
|
|
|
|
assert.ok(!formData); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should allow stream.path that can not be parsed', function test() { |
|
|
|
|
const stream = fs.createReadStream(paths.audio); |
|
|
|
|
stream.path = '/?id=123'; // for example, 'http://example.com/?id=666'
|
|
|
|
|
assert.doesNotThrow(function assertDoesNotThrow() { |
|
|
|
|
bot._formatSendData('file', stream); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |