Skip to content

Commit

Permalink
EDD-26: Adds missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
macrouch committed Aug 24, 2023
1 parent c73a88f commit 34eac32
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/main/utils/database/__tests__/EddDatabase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,4 +890,77 @@ describe('EddDatabase', () => {
})
})
})

describe('getDownloadsReport', () => {
test('returns the report', async () => {
dbTracker.on('query', (query) => {
expect(query.sql).toEqual('select `downloads`.`createdAt`, `downloads`.`id`, `downloads`.`loadingMoreFiles`, `downloads`.`state`, `downloads`.`timeEnd`, `downloads`.`timeStart` from `downloads` order by `createdAt` desc limit ? offset ?')
expect(query.bindings).toEqual([
10,
10
])

query.response([
{
createdAt: 1692731224799,
id: 'mock-download-id-1',
loadingMoreFiles: 1,
state: downloadStates.active,
timeEnd: null,
timeStart: 1692731225946
},
{
createdAt: 1692731213513,
id: 'mock-download-id-2',
loadingMoreFiles: 0,
state: downloadStates.active,
timeEnd: null,
timeStart: 1692731217041
}
])
})

const database = new EddDatabase('./')

const result = await database.getDownloadsReport(10, 10)

expect(result).toEqual([
{
createdAt: 1692731224799,
id: 'mock-download-id-1',
loadingMoreFiles: 1,
state: downloadStates.active,
timeEnd: null,
timeStart: 1692731225946
},
{
createdAt: 1692731213513,
id: 'mock-download-id-2',
loadingMoreFiles: 0,
state: downloadStates.active,
timeEnd: null,
timeStart: 1692731217041
}
])
})
})

describe('getAllDownloadsCount', () => {
test('returns the report', async () => {
dbTracker.on('query', (query) => {
expect(query.sql).toEqual('select count(`id`) from `downloads`')
expect(query.bindings).toEqual([])

query.response([{
'count(`id`)': 5
}])
})

const database = new EddDatabase('./')

const result = await database.getAllDownloadsCount()

expect(result).toEqual(5)
})
})
})

0 comments on commit 34eac32

Please sign in to comment.