From 497136d16f533216471e46a60f8611c2fcff3fc2 Mon Sep 17 00:00:00 2001 From: Teo Gebhard Date: Thu, 21 Nov 2024 21:59:12 +0200 Subject: [PATCH] rename custom matcher --- packages/sdk/karma-setup.js | 6 +++--- packages/sdk/test/end-to-end/Permissions.test.ts | 4 ++-- packages/sdk/test/end-to-end/StreamRegistry.test.ts | 2 +- .../sdk/test/integration/NetworkNodeFacade.test.ts | 8 ++++---- packages/sdk/test/integration/Resends2.test.ts | 2 +- packages/sdk/test/integration/client-destroy.test.ts | 2 +- packages/sdk/test/integration/waitForStorage.test.ts | 2 +- packages/sdk/test/test-utils/customMatchers.ts | 6 +++--- packages/sdk/test/unit/Publisher.test.ts | 2 +- packages/sdk/test/unit/PushBuffer.test.ts | 10 +++++----- packages/sdk/test/unit/Resends.test.ts | 4 ++-- packages/sdk/test/unit/Stream.test.ts | 2 +- packages/sdk/test/unit/StreamrClient.test.ts | 2 +- packages/sdk/test/unit/customMatchers.test.ts | 12 ++++++------ 14 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/sdk/karma-setup.js b/packages/sdk/karma-setup.js index 6b65291bc0..bc0f96ba52 100644 --- a/packages/sdk/karma-setup.js +++ b/packages/sdk/karma-setup.js @@ -4,13 +4,13 @@ */ // eslint-disable-next-line @typescript-eslint/no-require-imports -const { toThrowStreamrError } = require('./test/test-utils/customMatchers') +const { toThrowStreamrClientError } = require('./test/test-utils/customMatchers') // Karma runner ends up reporting an error if we don't have this check here. TODO: investigate why this is -if (toThrowStreamrError !== undefined) { +if (toThrowStreamrClientError !== undefined) { // eslint-disable-next-line no-undef expect.extend({ - toThrowStreamrError + toThrowStreamrClientError }) } diff --git a/packages/sdk/test/end-to-end/Permissions.test.ts b/packages/sdk/test/end-to-end/Permissions.test.ts index af4d0b9bf0..b71e97b6af 100644 --- a/packages/sdk/test/end-to-end/Permissions.test.ts +++ b/packages/sdk/test/end-to-end/Permissions.test.ts @@ -235,7 +235,7 @@ describe('Stream permissions', () => { await expect(() => client.grantPermissions(stream.id, { public: true, permissions: [StreamPermission.PUBLISH, StreamPermission.GRANT] - })).rejects.toThrowStreamrError({ + })).rejects.toThrowStreamrClientError({ message: 'Public permission is not supported for permission types: GRANT', code: 'UNSUPPORTED_OPERATION' }) @@ -245,7 +245,7 @@ describe('Stream permissions', () => { await expect(() => client.grantPermissions(stream.id, { userId: toUserId(randomBytes(50)), permissions: [StreamPermission.EDIT, StreamPermission.GRANT] - })).rejects.toThrowStreamrError({ + })).rejects.toThrowStreamrClientError({ message: 'Non-Ethereum user id is not supported for permission types: EDIT, GRANT', code: 'UNSUPPORTED_OPERATION' }) diff --git a/packages/sdk/test/end-to-end/StreamRegistry.test.ts b/packages/sdk/test/end-to-end/StreamRegistry.test.ts index 1a1142edde..1a97735240 100644 --- a/packages/sdk/test/end-to-end/StreamRegistry.test.ts +++ b/packages/sdk/test/end-to-end/StreamRegistry.test.ts @@ -148,7 +148,7 @@ describe('StreamRegistry', () => { it('get a non-existing Stream', async () => { const streamId = `${publicAddress}/StreamRegistry-nonexisting-${Date.now()}` - return expect(() => client.getStream(streamId)).rejects.toThrowStreamrError({ + return expect(() => client.getStream(streamId)).rejects.toThrowStreamrClientError({ code: 'STREAM_NOT_FOUND' }) }, TIMEOUT) diff --git a/packages/sdk/test/integration/NetworkNodeFacade.test.ts b/packages/sdk/test/integration/NetworkNodeFacade.test.ts index 4b42699a4a..13bd878ab4 100644 --- a/packages/sdk/test/integration/NetworkNodeFacade.test.ts +++ b/packages/sdk/test/integration/NetworkNodeFacade.test.ts @@ -55,7 +55,7 @@ describe('NetworkNodeFacade', () => { await client.destroy() await expect(async () => { await getNode() - }).rejects.toThrowStreamrError({ code: 'CLIENT_DESTROYED' }) + }).rejects.toThrowStreamrClientError({ code: 'CLIENT_DESTROYED' }) }) it('can call destroy multiple times', async () => { @@ -67,14 +67,14 @@ describe('NetworkNodeFacade', () => { await client.destroy() await expect(async () => { await getNode() - }).rejects.toThrowStreamrError({ code: 'CLIENT_DESTROYED' }) + }).rejects.toThrowStreamrClientError({ code: 'CLIENT_DESTROYED' }) }) it('can destroy before start', async () => { await client.destroy() await expect(async () => { await getNode() - }).rejects.toThrowStreamrError({ code: 'CLIENT_DESTROYED' }) + }).rejects.toThrowStreamrClientError({ code: 'CLIENT_DESTROYED' }) }) it('can destroy during start', async () => { @@ -85,7 +85,7 @@ describe('NetworkNodeFacade', () => { ] await Promise.allSettled(tasks) await Promise.all(tasks) - }).rejects.toThrowStreamrError({ code: 'CLIENT_DESTROYED' }) + }).rejects.toThrowStreamrClientError({ code: 'CLIENT_DESTROYED' }) }) }) }) diff --git a/packages/sdk/test/integration/Resends2.test.ts b/packages/sdk/test/integration/Resends2.test.ts index 38a0a271aa..c1b654db09 100644 --- a/packages/sdk/test/integration/Resends2.test.ts +++ b/packages/sdk/test/integration/Resends2.test.ts @@ -71,7 +71,7 @@ describe('Resends2', () => { }, { last: 5 }) - }).rejects.toThrowStreamrError(new StreamrClientError(`no storage assigned: ${stream.id}`, 'NO_STORAGE_NODES')) + }).rejects.toThrowStreamrClientError(new StreamrClientError(`no storage assigned: ${stream.id}`, 'NO_STORAGE_NODES')) }) it('throws error if bad partition', async () => { diff --git a/packages/sdk/test/integration/client-destroy.test.ts b/packages/sdk/test/integration/client-destroy.test.ts index deb68bda33..1ef1a10063 100644 --- a/packages/sdk/test/integration/client-destroy.test.ts +++ b/packages/sdk/test/integration/client-destroy.test.ts @@ -43,7 +43,7 @@ describe('client destroy', () => { await client.destroy() await expect(async () => { await client.subscribe(stream.id) - }).rejects.toThrowStreamrError({ code: 'CLIENT_DESTROYED' }) + }).rejects.toThrowStreamrClientError({ code: 'CLIENT_DESTROYED' }) }) it('unable to publish after destroy called', async () => { diff --git a/packages/sdk/test/integration/waitForStorage.test.ts b/packages/sdk/test/integration/waitForStorage.test.ts index 97f9ef5c6a..a7087131a9 100644 --- a/packages/sdk/test/integration/waitForStorage.test.ts +++ b/packages/sdk/test/integration/waitForStorage.test.ts @@ -96,6 +96,6 @@ describe('waitForStorage', () => { messageMatchFn: () => { return true } - })).rejects.toThrowStreamrError(new StreamrClientError(`no storage assigned: ${stream.id}`, 'NO_STORAGE_NODES')) + })).rejects.toThrowStreamrClientError(new StreamrClientError(`no storage assigned: ${stream.id}`, 'NO_STORAGE_NODES')) }) }) diff --git a/packages/sdk/test/test-utils/customMatchers.ts b/packages/sdk/test/test-utils/customMatchers.ts index ddd65e7ef4..e69195d5a4 100644 --- a/packages/sdk/test/test-utils/customMatchers.ts +++ b/packages/sdk/test/test-utils/customMatchers.ts @@ -13,7 +13,7 @@ declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace jest { interface Matchers { - toThrowStreamrError(expectedError: PartialStreamrClientError): R + toThrowStreamrClientError(expectedError: PartialStreamrClientError): R } } } @@ -22,7 +22,7 @@ const formErrorMessage = (field: keyof StreamrClientError, expected: string, act return `StreamrClientError ${field} values don't match:\nExpected: ${printExpected(expected)}\nReceived: ${printReceived(actual)}` } -const toThrowStreamrError = ( +const toThrowStreamrClientError = ( actual: unknown, // should be (() => StreamrClientError) | StreamrClientError expectedError: PartialStreamrClientError ): jest.CustomMatcherResult => { @@ -67,5 +67,5 @@ const toThrowStreamrError = ( } expect.extend({ - toThrowStreamrError + toThrowStreamrClientError }) diff --git a/packages/sdk/test/unit/Publisher.test.ts b/packages/sdk/test/unit/Publisher.test.ts index 33e647cec9..24406f1181 100644 --- a/packages/sdk/test/unit/Publisher.test.ts +++ b/packages/sdk/test/unit/Publisher.test.ts @@ -27,7 +27,7 @@ describe('Publisher', () => { const streamId = await streamIdBuilder.toStreamID('/test') await expect(async () => { await publisher.publish(streamId, {}) - }).rejects.toThrowStreamrError({ + }).rejects.toThrowStreamrClientError({ code: 'MISSING_PERMISSION', // eslint-disable-next-line max-len message: `Failed to publish to stream ${streamId}. Cause: You don't have permission to publish to this stream. Using address: ${await authentication.getUserId()}` diff --git a/packages/sdk/test/unit/PushBuffer.test.ts b/packages/sdk/test/unit/PushBuffer.test.ts index bb7e8c9c9a..ac29521d17 100644 --- a/packages/sdk/test/unit/PushBuffer.test.ts +++ b/packages/sdk/test/unit/PushBuffer.test.ts @@ -174,19 +174,19 @@ describe.skip('PushBuffer', () => { it('errors on bad buffer size', async () => { expect(() => { new PushBuffer(0) - }).toThrowStreamrError({ code: 'INVALID_ARGUMENT' }) + }).toThrowStreamrClientError({ code: 'INVALID_ARGUMENT' }) expect(() => { new PushBuffer(-1) - }).toThrowStreamrError({ code: 'INVALID_ARGUMENT' }) + }).toThrowStreamrClientError({ code: 'INVALID_ARGUMENT' }) expect(() => { new PushBuffer(Number.MAX_SAFE_INTEGER + 10) - }).toThrowStreamrError({ code: 'INVALID_ARGUMENT' }) + }).toThrowStreamrClientError({ code: 'INVALID_ARGUMENT' }) expect(() => { new PushBuffer(1.5) - }).toThrowStreamrError({ code: 'INVALID_ARGUMENT' }) + }).toThrowStreamrClientError({ code: 'INVALID_ARGUMENT' }) expect(() => { new PushBuffer(0.5) - }).toThrowStreamrError({ code: 'INVALID_ARGUMENT' }) + }).toThrowStreamrClientError({ code: 'INVALID_ARGUMENT' }) }) it('can push inside pull', async () => { diff --git a/packages/sdk/test/unit/Resends.test.ts b/packages/sdk/test/unit/Resends.test.ts index ad7def3e3e..e7212cb2ff 100644 --- a/packages/sdk/test/unit/Resends.test.ts +++ b/packages/sdk/test/unit/Resends.test.ts @@ -33,7 +33,7 @@ describe('Resends', () => { await expect(async () => { const messages = await resends.resend(StreamPartIDUtils.parse('stream#0'), { last: 1, raw: true }, async () => [randomEthereumAddress()]) await collect(messages) - }).rejects.toThrowStreamrError({ + }).rejects.toThrowStreamrClientError({ message: `Storage node fetch failed: Mock error, httpStatus=400, url=${requestUrl}`, code: 'STORAGE_NODE_ERROR' }) @@ -45,7 +45,7 @@ describe('Resends', () => { await expect(async () => { const messages = await resends.resend(StreamPartIDUtils.parse('stream#0'), { last: 1, raw: true }, async () => [randomEthereumAddress()]) await collect(messages) - }).rejects.toThrowStreamrError({ + }).rejects.toThrowStreamrClientError({ message: isRunningInElectron() ? 'Failed to fetch' // eslint-disable-next-line max-len diff --git a/packages/sdk/test/unit/Stream.test.ts b/packages/sdk/test/unit/Stream.test.ts index 7818930d28..cc6f4556f4 100644 --- a/packages/sdk/test/unit/Stream.test.ts +++ b/packages/sdk/test/unit/Stream.test.ts @@ -28,7 +28,7 @@ describe('Stream', () => { { partitions: 150 }, undefined as any, ) - expect(() => stream.getPartitionCount()).toThrowStreamrError({ + expect(() => stream.getPartitionCount()).toThrowStreamrClientError({ message: 'Invalid partition count: 150', code: 'INVALID_STREAM_METADATA' }) diff --git a/packages/sdk/test/unit/StreamrClient.test.ts b/packages/sdk/test/unit/StreamrClient.test.ts index 8dd8356804..42cb9ff2fa 100644 --- a/packages/sdk/test/unit/StreamrClient.test.ts +++ b/packages/sdk/test/unit/StreamrClient.test.ts @@ -61,7 +61,7 @@ describe('StreamrClient', () => { distributionMethod: 'rotate', key: GroupKey.generate() }) - }).rejects.toThrowStreamrError({ + }).rejects.toThrowStreamrClientError({ message: 'cannot pass "key" when Lit Protocol is enabled', code: 'UNSUPPORTED_OPERATION' }) diff --git a/packages/sdk/test/unit/customMatchers.test.ts b/packages/sdk/test/unit/customMatchers.test.ts index b8134c96cb..cc6987f188 100644 --- a/packages/sdk/test/unit/customMatchers.test.ts +++ b/packages/sdk/test/unit/customMatchers.test.ts @@ -2,13 +2,13 @@ import { StreamrClientError } from '../../src/StreamrClientError' describe('custom matchers', () => { - describe('toThrowStreamrError', () => { + describe('toThrowStreamrClientError', () => { it('happy path', () => { const error = new StreamrClientError('Foobar', 'UNKNOWN_ERROR') expect(() => { throw error - }).toThrowStreamrError({ + }).toThrowStreamrClientError({ code: error.code, message: error.message }) @@ -19,7 +19,7 @@ describe('custom matchers', () => { it('field', () => { const actual = new StreamrClientError('Foobar', 'UNKNOWN_ERROR') expect(() => { - expect(() => { throw actual }).toThrowStreamrError({ + expect(() => { throw actual }).toThrowStreamrClientError({ message: 'Foobar', code: 'UNSUPPORTED_OPERATION' }) @@ -31,7 +31,7 @@ describe('custom matchers', () => { class TestClass {} expect(() => { // eslint-disable-next-line @typescript-eslint/only-throw-error - expect(() => { throw new TestClass() }).toThrowStreamrError({ + expect(() => { throw new TestClass() }).toThrowStreamrClientError({ message: 'Foobar', code: 'UNSUPPORTED_OPERATION' }) @@ -41,7 +41,7 @@ describe('custom matchers', () => { it('unexpected privitive', () => { expect(() => { // eslint-disable-next-line @typescript-eslint/only-throw-error - expect(() => { throw 'mock-error' }).toThrowStreamrError({ + expect(() => { throw 'mock-error' }).toThrowStreamrClientError({ message: 'Foobar', code: 'UNSUPPORTED_OPERATION' }) @@ -51,7 +51,7 @@ describe('custom matchers', () => { it('inverse', () => { const actual = new StreamrClientError('Foobar', 'UNKNOWN_ERROR') expect(() => { - expect(() => { throw actual }).not.toThrowStreamrError(actual) + expect(() => { throw actual }).not.toThrowStreamrClientError(actual) }).toThrow('Expected not to throw StreamrClientError') }) })