Skip to content

Commit

Permalink
test: basic unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed Nov 3, 2023
1 parent 4666004 commit 66ac180
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/backend/src/nest/storage/storage.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,4 +675,48 @@ describe('StorageService', () => {
await expect(storageService.deleteFilesFromChannel(messages)).resolves.not.toThrowError()
})
})

describe('replicate certificatesRequests event', () => {
const replicatedEvent = async () => {
// @ts-ignore - Property 'certificates' is private
storageService.certificatesRequests.events.emit('replicated')
await new Promise<void>(resolve => setTimeout(() => resolve(), 2000))
}

it('replicated event ', async () => {
await storageService.init(peerId)
const spyOnUpdatePeersList = jest.spyOn(storageService, 'updatePeersList')
await replicatedEvent()
expect(spyOnUpdatePeersList).toBeCalledTimes(1)
})

it('2 replicated events - first not resolved ', async () => {
await storageService.init(peerId)
const spyOnUpdatePeersList = jest.spyOn(storageService, 'updatePeersList')
await replicatedEvent()
await replicatedEvent()
expect(spyOnUpdatePeersList).toBeCalledTimes(1)
})

it('2 replicated events - first resolved ', async () => {
await storageService.init(peerId)
const spyOnUpdatePeersList = jest.spyOn(storageService, 'updatePeersList')
await replicatedEvent()
await replicatedEvent()
storageService.resolveCsrReplicatedPromise(1)
await new Promise<void>(resolve => setTimeout(() => resolve(), 500))
expect(spyOnUpdatePeersList).toBeCalledTimes(2)
})

it('3 replicated events - no resolved promises', async () => {
await storageService.init(peerId)
const spyOnUpdatePeersList = jest.spyOn(storageService, 'updatePeersList')

await replicatedEvent()
await replicatedEvent()
await replicatedEvent()

expect(spyOnUpdatePeersList).toBeCalledTimes(1)
})
})
})

0 comments on commit 66ac180

Please sign in to comment.