Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/dht/test/unit/AutoCertifierClientFacade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ describe('AutoCertifierClientFacade', () => {

it('start', async () => {
await client.start()
expect(setHost).toBeCalled()
expect(updateCertificate).toBeCalled()
expect(setHost).toHaveBeenCalled()
expect(updateCertificate).toHaveBeenCalled()
})

it('updated events are processed', async () => {
await client.start()
expect(setHost).toBeCalledTimes(1)
expect(updateCertificate).toBeCalledTimes(1);
expect(setHost).toHaveBeenCalledTimes(1)
expect(updateCertificate).toHaveBeenCalledTimes(1);
(mockClient as MockAutoCertifierClient).emitUpdateSubdomain()
expect(setHost).toBeCalledTimes(2)
expect(updateCertificate).toBeCalledTimes(2)
expect(setHost).toHaveBeenCalledTimes(2)
expect(updateCertificate).toHaveBeenCalledTimes(2)
})

})
6 changes: 3 additions & 3 deletions packages/dht/test/unit/SortedContactList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('SortedContactList', () => {
expect(list.getSize()).toEqual(3)
expect(list.getClosestContacts()).toEqual([item1, item2, item3])
expect(list.getContactIds()).toEqual([item1.getNodeId(), item2.getNodeId(), item3.getNodeId()])
expect(onContactRemoved).toBeCalledWith(item4)
expect(onContactRemoved).toHaveBeenCalledWith(item4)
expect(list.getContact(item4.getNodeId())).toBeFalsy()
})

Expand Down Expand Up @@ -106,9 +106,9 @@ describe('SortedContactList', () => {
list.on('contactAdded', onContactAdded)
list.addContact(item1)
list.addContact(item2)
expect(onContactAdded).toBeCalledTimes(2)
expect(onContactAdded).toHaveBeenCalledTimes(2)
list.addContact(item3)
expect(onContactAdded).toBeCalledTimes(2)
expect(onContactAdded).toHaveBeenCalledTimes(2)
expect(list.getClosestContacts().length).toEqual(2)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('BatchManager', () => {

await until(() => batch.retries === 1)

expect(mockBatch).toBeCalledTimes(1)
expect(mockBatch).toHaveBeenCalledTimes(1)
expect(batch.retries).toEqual(1)

jest.restoreAllMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('close', () => {
client.on('close', onClose)
server.stop()
await wait(100)
expect(onClose).toBeCalled()
expect(onClose).toHaveBeenCalled()
})

it('paused client doesn\'t prevent server stop', async () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/node/test/integration/plugins/websocket/ping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('ping', () => {
client.ping(PAYLOAD)
const pongMessage = await payloads.pop()
expect(pongMessage).toBe(PAYLOAD)
expect(streamrClient.publish).not.toBeCalled()
expect(streamrClient.publish).not.toHaveBeenCalled()
})

it('application layer', async () => {
Expand All @@ -58,7 +58,7 @@ describe('ping', () => {
client.send('ping')
const pongMessage = await messages.pop()
expect(pongMessage).toBe('pong')
expect(streamrClient.publish).not.toBeCalled()
expect(streamrClient.publish).not.toHaveBeenCalled()
})
})

Expand Down Expand Up @@ -135,7 +135,7 @@ describe('ping', () => {
client.resume()
// wait some time so that buffered events (e.g. 'close' are processed)
await wait(10)
expect(onClose).toBeCalled()
expect(onClose).toHaveBeenCalled()
})

it('disable ping', async () => {
Expand All @@ -145,7 +145,7 @@ describe('ping', () => {
const onPing = jest.fn()
client.on('ping', onPing)
await wait(100)
expect(onPing).not.toBeCalled()
expect(onPing).not.toHaveBeenCalled()
})

it('disable disconnect', async () => {
Expand All @@ -156,7 +156,7 @@ describe('ping', () => {
client.on('close', onClose)
client.pause()
await wait(100)
expect(onClose).not.toBeCalled()
expect(onClose).not.toHaveBeenCalled()
})
})
})
6 changes: 3 additions & 3 deletions packages/node/test/unit/plugins/http/publishEndpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('publishEndpoint', () => {
await postMessage({
foo: 'bar'
}, queryParams).expect(200)
expect(streamrClient.publish).toBeCalledTimes(1)
expect(streamrClient.publish).toBeCalledWith({
expect(streamrClient.publish).toHaveBeenCalledTimes(1)
expect(streamrClient.publish).toHaveBeenCalledWith({
streamId: MOCK_STREAM_ID,
streamPartition: expectedPartition
}, {
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('publishEndpoint', () => {
await postMessage({
foo: 2
}, {})
expect(streamrClient.publish).toBeCalledTimes(2)
expect(streamrClient.publish).toHaveBeenCalledTimes(2)
const firstMessageMsgChainId = streamrClient.publish.mock.calls[0][2].msgChainId
const secondMessageMsgChainId = streamrClient.publish.mock.calls[1][2].msgChainId
expect(firstMessageMsgChainId).toBeDefined()
Expand Down
14 changes: 7 additions & 7 deletions packages/node/test/unit/plugins/mqtt/Bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('MQTT Bridge', () => {

it('onMessageReceived', async () => {
await bridge.onMessageReceived(topic, JSON.stringify(MOCK_CONTENT), MOCK_CLIENT_ID)
expect(streamrClient.publish).toBeCalledWith(
expect(streamrClient.publish).toHaveBeenCalledWith(
{ id: MOCK_STREAM_ID, partition: undefined },
MOCK_CONTENT,
{ msgChainId: expect.any(String) }
Expand All @@ -57,13 +57,13 @@ describe('MQTT Bridge', () => {

it('onSubscribed', async () => {
await bridge.onSubscribed(topic, MOCK_CLIENT_ID)
expect(streamrClient.subscribe).toBeCalledWith(`${MOCK_STREAM_ID}#0`, expect.anything())
expect(streamrClient.subscribe).toHaveBeenCalledWith(`${MOCK_STREAM_ID}#0`, expect.anything())
})

it('onUnsubscribed', async () => {
await bridge.onSubscribed(topic, MOCK_CLIENT_ID)
bridge.onUnsubscribed(topic, MOCK_CLIENT_ID)
expect(subscription.unsubscribe).toBeCalled()
expect(subscription.unsubscribe).toHaveBeenCalled()
})

})
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('MQTT Bridge', () => {

it('publish with partition', async () => {
await bridge.onMessageReceived(`${MOCK_TOPIC}?partition=5`, JSON.stringify(MOCK_CONTENT), MOCK_CLIENT_ID)
expect(streamrClient.publish).toBeCalledWith(
expect(streamrClient.publish).toHaveBeenCalledWith(
{
id: MOCK_TOPIC,
partition: 5
Expand All @@ -119,7 +119,7 @@ describe('MQTT Bridge', () => {

it('publish with partition key', async () => {
await bridge.onMessageReceived(`${MOCK_TOPIC}?partitionKey=mock-key`, JSON.stringify(MOCK_CONTENT), MOCK_CLIENT_ID)
expect(streamrClient.publish).toBeCalledWith(
expect(streamrClient.publish).toHaveBeenCalledWith(
{
id: MOCK_TOPIC,
partition: undefined
Expand All @@ -135,7 +135,7 @@ describe('MQTT Bridge', () => {

it('publish with partition key field', async () => {
await bridge.onMessageReceived(`${MOCK_TOPIC}?partitionKeyField=foo`, JSON.stringify(MOCK_CONTENT), MOCK_CLIENT_ID)
expect(streamrClient.publish).toBeCalledWith(
expect(streamrClient.publish).toHaveBeenCalledWith(
{
id: MOCK_TOPIC,
partition: undefined
Expand All @@ -151,7 +151,7 @@ describe('MQTT Bridge', () => {

it('subscribe', async () => {
await bridge.onSubscribed(`${MOCK_TOPIC}?partition=5`, MOCK_CLIENT_ID)
expect(streamrClient.subscribe).toBeCalledWith(
expect(streamrClient.subscribe).toHaveBeenCalledWith(
`${MOCK_TOPIC}#5`,
expect.anything()
)
Expand Down
8 changes: 4 additions & 4 deletions packages/node/test/unit/plugins/storage/StorageConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ describe(StorageConfig, () => {
})

it('stream part listeners invoked', () => {
expect(onStreamPartAdded).toBeCalledTimes(6)
expect(onStreamPartRemoved).toBeCalledTimes(0)
expect(onStreamPartAdded).toHaveBeenCalledTimes(6)
expect(onStreamPartRemoved).toHaveBeenCalledTimes(0)
expect(onStreamPartAdded.mock.calls).toEqual([
[parse('stream-1#0')],
[parse('stream-1#1')],
Expand Down Expand Up @@ -123,8 +123,8 @@ describe(StorageConfig, () => {
})

it('stream part listeners invoked', () => {
expect(onStreamPartAdded).toBeCalledTimes(2 + 1)
expect(onStreamPartRemoved).toBeCalledTimes(2)
expect(onStreamPartAdded).toHaveBeenCalledTimes(2 + 1)
expect(onStreamPartRemoved).toHaveBeenCalledTimes(2)
expect(onStreamPartAdded.mock.calls).toEqual([
[parse('stream-1#0')],
[parse('stream-1#1')],
Expand Down
4 changes: 2 additions & 2 deletions packages/node/test/unit/plugins/storage/StoragePoller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ describe(StoragePoller, () => {
poller = initPoller(0)
await poller.start(abortController.signal)
await wait(POLL_TIME * 10)
expect(getStoredStreams).toBeCalledTimes(1)
expect(getStoredStreams).toHaveBeenCalledTimes(1)
})

it('start() handles polling errors gracefully', async () => {
getStoredStreams.mockRejectedValue(new Error('poll failed'))
await poller.start(abortController.signal)
await wait(POLL_TIME * 2)
expect(onNewSnapshot).toBeCalledTimes(0) // Should not have encountered unhandledRejectionError
expect(onNewSnapshot).toHaveBeenCalledTimes(0) // Should not have encountered unhandledRejectionError
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('WebsocketServer', () => {

it('without parameters', async () => {
await connectAndPublish()
expect(streamrClient.publish).toBeCalledWith(
expect(streamrClient.publish).toHaveBeenCalledWith(
{
id: MOCK_STREAM_ID,
partition: undefined
Expand All @@ -88,7 +88,7 @@ describe('WebsocketServer', () => {

it('valid partition', async () => {
await connectAndPublish({ partition: 50 })
expect(streamrClient.publish).toBeCalledWith(
expect(streamrClient.publish).toHaveBeenCalledWith(
{
id: MOCK_STREAM_ID,
partition: 50
Expand All @@ -102,7 +102,7 @@ describe('WebsocketServer', () => {

it('valid partitionKey', async () => {
await connectAndPublish({ partitionKey: 'mock-key' })
expect(streamrClient.publish).toBeCalledWith(
expect(streamrClient.publish).toHaveBeenCalledWith(
{
id: MOCK_STREAM_ID,
partition: undefined
Expand All @@ -117,7 +117,7 @@ describe('WebsocketServer', () => {

it('valid partitionKeyField', async () => {
await connectAndPublish({ partitionKeyField: 'foo' })
expect(streamrClient.publish).toBeCalledWith(
expect(streamrClient.publish).toHaveBeenCalledWith(
{
id: MOCK_STREAM_ID,
partition: undefined
Expand Down Expand Up @@ -149,14 +149,14 @@ describe('WebsocketServer', () => {
it('without parameters', async () => {
wsClient = createTestClient(PATH_SUBSCRIBE_MOCK_STREAM)
await waitForEvent(wsClient, 'open')
expect(streamrClient.subscribe).toBeCalledTimes(1)
expect(streamrClient.subscribe).toBeCalledWith({ id: MOCK_STREAM_ID, partition: undefined }, expect.anything())
expect(streamrClient.subscribe).toHaveBeenCalledTimes(1)
expect(streamrClient.subscribe).toHaveBeenCalledWith({ id: MOCK_STREAM_ID, partition: undefined }, expect.anything())
})

it('valid partitions', async () => {
wsClient = createTestClient(PATH_SUBSCRIBE_MOCK_STREAM, { partitions: '0,2,5' })
await waitForEvent(wsClient, 'open')
expect(streamrClient.subscribe).toBeCalledTimes(3)
expect(streamrClient.subscribe).toHaveBeenCalledTimes(3)
expect(streamrClient.subscribe).toHaveBeenNthCalledWith(1, { id: MOCK_STREAM_ID, partition: 0 }, expect.anything())
expect(streamrClient.subscribe).toHaveBeenNthCalledWith(2, { id: MOCK_STREAM_ID, partition: 2 }, expect.anything())
expect(streamrClient.subscribe).toHaveBeenNthCalledWith(3, { id: MOCK_STREAM_ID, partition: 5 }, expect.anything())
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/test/integration/client-destroy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('client destroy', () => {
const sub = await client.subscribe(stream.id)
jest.spyOn(sub, 'unsubscribe')
await client.destroy()
expect(sub.unsubscribe).toBeCalled()
expect(sub.unsubscribe).toHaveBeenCalled()
})

it('ongoing subscribe pipeline ends', async () => {
Expand All @@ -35,7 +35,7 @@ describe('client destroy', () => {
sub.on('error', onError)
const outputPromise = collect(sub)
await client.destroy()
expect(onError).toBeCalledTimes(0)
expect(onError).toHaveBeenCalledTimes(0)
expect(await outputPromise).toEqual([])
})

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/integration/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('events', () => {
const onResendComplete = jest.fn()
subscription.once('resendCompleted', onResendComplete)
await client.destroy()
expect(onResendComplete).not.toBeCalled()
expect(onResendComplete).not.toHaveBeenCalled()
// @ts-expect-error private
expect(subscription.eventEmitter.listenerCount()).toBe(0)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('resend with existing key', () => {
const onError = jest.fn()
messageStream.onError.listen(onError)
const messages = await collect(messageStream)
expect(onError).not.toBeCalled()
expect(onError).not.toHaveBeenCalled()
const expectedTimestamps = allMessages.map((m) => m.timestamp).filter((ts) => ts >= fromTimestamp && ts <= toTimestamp)
expect(messages.map((m) => m.timestamp)).toEqual(expectedTimestamps)
}
Expand All @@ -66,7 +66,7 @@ describe('resend with existing key', () => {
const onError = jest.fn()
messageStream.onError.listen(onError)
await collect(messageStream)
expect(onError).toBeCalled()
expect(onError).toHaveBeenCalled()
const error = onError.mock.calls[0][0]
expect(error).toBeInstanceOf(DecryptError)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/integration/unsubscribe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('unsubscribe', () => {
await client.unsubscribe(sub)

expect(await client.getSubscriptions()).toHaveLength(0)
expect(sub.unsubscribe).toBeCalled()
expect(sub.unsubscribe).toHaveBeenCalled()
})

it('twice', async () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/test/unit/CachingMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ describe('CachingMap', () => {
const result2 = await cache.get('foo', 'bar')
expect(result1).toBe('FOOBAR')
expect(result2).toBe('FOOBAR')
expect(plainFn).toBeCalledTimes(1)
expect(plainFn).toHaveBeenCalledTimes(1)
})

it('miss', async () => {
const result1 = await cache.get('foo', 'x')
const result2 = await cache.get('foo', 'y')
expect(result1).toBe('FOOX')
expect(result2).toBe('FOOY')
expect(plainFn).toBeCalledTimes(2)
expect(plainFn).toHaveBeenCalledTimes(2)
})

it('concurrency', async () => {
Expand All @@ -42,7 +42,7 @@ describe('CachingMap', () => {
])
expect(result1).toBe('FOOBAR')
expect(result2).toBe('FOOBAR')
expect(plainFn).toBeCalledTimes(1)
expect(plainFn).toHaveBeenCalledTimes(1)
})

it('rejections are not cached', async () => {
Expand All @@ -52,7 +52,7 @@ describe('CachingMap', () => {
await expect(cache.get('foo', 'x')).rejects.toEqual(new Error('error foo-x'))
await expect(cache.get('foo', 'x')).rejects.toEqual(new Error('error foo-x'))

expect(plainFn).toBeCalledTimes(2) // would be 1 if rejections were cached
expect(plainFn).toHaveBeenCalledTimes(2) // would be 1 if rejections were cached
})

it('throws are not cached', async () => {
Expand All @@ -62,6 +62,6 @@ describe('CachingMap', () => {
await expect(cache.get('foo', 'x')).rejects.toEqual(new Error('error foo-x'))
await expect(cache.get('foo', 'x')).rejects.toEqual(new Error('error foo-x'))

expect(plainFn).toBeCalledTimes(2) // would be 1 if throws were cached
expect(plainFn).toHaveBeenCalledTimes(2) // would be 1 if throws were cached
})
})
2 changes: 1 addition & 1 deletion packages/sdk/test/unit/Decrypt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Decrypt', () => {
encryptionType: EncryptionType.NONE,
content: unencryptedContent
}))
expect(groupKeyManager.fetchKey).toBeCalledWith(
expect(groupKeyManager.fetchKey).toHaveBeenCalledWith(
encryptedMessage.getStreamPartID(),
encryptedMessage.groupKeyId,
encryptedMessage.getPublisherId()
Expand Down
Loading
Loading