Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rassokhina-e committed Nov 1, 2023
1 parent f93d00a commit 0dd2bbf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/internal/arbimon/bl/recordings.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function findSourceFiles (arr, options = {}) {
*/
async function softDeleteSourceFilesBatch (arr, options = {}) {
const ids = await findSourceFiles(arr, options)
await streamSourceFileDao.updateByIds({ stream_id: TRASHES_STREAM_ID }, ids, options)
await streamSourceFileDao.updateByIds(ids, { stream_id: TRASHES_STREAM_ID }, options)
}

module.exports = {
Expand Down
34 changes: 28 additions & 6 deletions core/internal/arbimon/recordings.int.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ function resetTestData () {
}

async function commonSetup () {
await models.Stream.findOrCreate({ where: stream })
await models.Stream.findOrCreate({ where: trashesStream })
audioFileFormatId = (await models.AudioFileFormat.findOrCreate({ where: audioFileFormat }))[0].id
audioCodecId = (await models.AudioCodec.findOrCreate({ where: audioCodec }))[0].id
fileExtensionId = (await models.FileExtension.findOrCreate({ where: fileExtension }))[0].id
await models.Stream.create(stream)
await models.Stream.create(trashesStream)
audioFileFormatId = (await models.AudioFileFormat.create(audioFileFormat)).id
audioCodecId = (await models.AudioCodec.create(audioCodec)).id
fileExtensionId = (await models.FileExtension.create(fileExtension)).id
const sourceFile = await models.StreamSourceFile.create({ ...testPayload.stream_source_file, stream_id: stream.id, audio_codec_id: audioCodecId, audio_file_format_id: audioFileFormatId })
await models.StreamSegment.create({ ...testPayload.stream_segments[0], stream_id: stream.id, file_extension_id: fileExtensionId, stream_source_file_id: sourceFile.id })
}
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('DELETE internal/arbimon/recordings', () => {
const sourceFile = await models.StreamSourceFile.create({ ...testPayload.stream_source_file, filename: '0d99db29f26d-2021-04-19T12-11-11.flac', sha1_checksum: 'e427f7bf6c589b4856d5f51691d159366d74211', stream_id: stream.id, audio_codec_id: audioCodecId, audio_file_format_id: audioFileFormatId })
await models.StreamSegment.create({ ...testPayload.stream_segments[0], start: '2021-04-18T13:12:00.000Z', end: '2021-04-18T13:13:00.000Z', stream_id: stream.id, file_extension_id: fileExtensionId, stream_source_file_id: sourceFile.id })
const testStream2 = { id: '1delete6y5yb', name: 'test stream 2', createdById: seedValues.primaryUserId }
await models.Stream.findOrCreate({ where: testStream2 })
await models.Stream.create(testStream2)
const sourceFile2 = await models.StreamSourceFile.create({ ...testPayload.stream_source_file, filename: '0d99db29f26d-2021-04-19T13-11-12.flac', sha1_checksum: 'e427f7bf6c589b4856d5f51691d159366d74212', stream_id: testStream2.id, audio_codec_id: audioCodecId, audio_file_format_id: audioFileFormatId })
await models.StreamSegment.create({ ...testPayload.stream_segments[0], start: '2021-04-18T14:12:00.000Z', end: '2021-04-18T14:13:00.000Z', stream_id: testStream2.id, file_extension_id: fileExtensionId, stream_source_file_id: sourceFile2.id })
const sourceFile3 = await models.StreamSourceFile.create({ ...testPayload.stream_source_file, filename: '0d99db29f26d-2021-04-19T14-11-12.flac', sha1_checksum: 'e427f7bf6c589b4856d5f51691d159366d74213', stream_id: testStream2.id, audio_codec_id: audioCodecId, audio_file_format_id: audioFileFormatId })
Expand All @@ -151,6 +151,28 @@ describe('DELETE internal/arbimon/recordings', () => {
expect(streamSourceFiles.length).toBe(2)
expect(streamSegments.length).toBe(2)
})
test('cam delete recordings from any one stream, but the streams has overlapping starts', async () => {
const sourceFile = await models.StreamSourceFile.create({ ...testPayload.stream_source_file, filename: '0d99db29f26d-2021-04-19T12-11-11.flac', sha1_checksum: 'e427f7bf6c589b4856d5f51691d159366d74211', stream_id: stream.id, audio_codec_id: audioCodecId, audio_file_format_id: audioFileFormatId })
await models.StreamSegment.create({ ...testPayload.stream_segments[0], start: '2021-04-18T13:12:00.000Z', end: '2021-04-18T13:13:00.000Z', stream_id: stream.id, file_extension_id: fileExtensionId, stream_source_file_id: sourceFile.id })
const testStream2 = { id: '1delete6y5yb', name: 'test stream 2', createdById: seedValues.primaryUserId }
await models.Stream.create(testStream2)
const sourceFile2 = await models.StreamSourceFile.create({ ...testPayload.stream_source_file, filename: '0d99db29f26d-2021-04-19T13-11-12.flac', sha1_checksum: 'e427f7bf6c589b4856d5f51691d159366d74212', stream_id: testStream2.id, audio_codec_id: audioCodecId, audio_file_format_id: audioFileFormatId })
await models.StreamSegment.create({ ...testPayload.stream_segments[0], start: '2021-04-18T12:12:00.000Z', end: '2021-04-18T14:13:00.000Z', stream_id: testStream2.id, file_extension_id: fileExtensionId, stream_source_file_id: sourceFile2.id })
const sourceFile3 = await models.StreamSourceFile.create({ ...testPayload.stream_source_file, filename: '0d99db29f26d-2021-04-19T14-11-12.flac', sha1_checksum: 'e427f7bf6c589b4856d5f51691d159366d74213', stream_id: testStream2.id, audio_codec_id: audioCodecId, audio_file_format_id: audioFileFormatId })
await models.StreamSegment.create({ ...testPayload.stream_segments[0], start: '2021-04-18T13:12:00.000Z', end: '2021-04-18T15:13:00.000Z', stream_id: testStream2.id, file_extension_id: fileExtensionId, stream_source_file_id: sourceFile3.id })
testRequestData[0].starts.push('2021-04-18T13:12:00.000Z')
console.debug(testRequestData)
const response = await request(app).delete('/recordings').send(testRequestData)

const streamSourceFiles = await models.StreamSourceFile.findAll({ where: { stream_id: [stream.id, testStream2.id] } })
const streamSegments = await models.StreamSegment.findAll({ where: { stream_id: [stream.id, testStream2.id] } })

expect(response.statusCode).toBe(200)
expect(streamSourceFiles.length).toBe(2)
expect(streamSegments.length).toBe(2)
streamSourceFiles.forEach(ssf => expect(ssf.stream_id).toBe(testStream2.id))
streamSegments.forEach(ss => expect(ss.stream_id).toBe(testStream2.id))
})
test('doesnt work for not correct dates', async () => {
testRequestData[0].starts = '20210418_121200'
const response = await request(app).delete('/recordings').send(testRequestData)
Expand Down
2 changes: 1 addition & 1 deletion core/stream-source-files/dao/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function calcAvailability (segments) {
* @returns {StreamSourceFile}
* @throws EmptyResultError when segment not found
*/
async function updateByIds (data, existingSourceFilesId, options = {}) {
async function updateByIds (existingSourceFilesId, data, options = {}) {
const transaction = options.transaction
return await StreamSourceFile.update(data, { where: { id: existingSourceFilesId }, transaction })
}
Expand Down

0 comments on commit 0dd2bbf

Please sign in to comment.