Skip to content

Commit

Permalink
rename custom matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
teogeb committed Nov 21, 2024
1 parent 163e774 commit 497136d
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions packages/sdk/karma-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/test/end-to-end/Permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand All @@ -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'
})
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/end-to-end/StreamRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/test/integration/NetworkNodeFacade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -85,7 +85,7 @@ describe('NetworkNodeFacade', () => {
]
await Promise.allSettled(tasks)
await Promise.all(tasks)
}).rejects.toThrowStreamrError({ code: 'CLIENT_DESTROYED' })
}).rejects.toThrowStreamrClientError({ code: 'CLIENT_DESTROYED' })
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/integration/Resends2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/integration/client-destroy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/integration/waitForStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
})
})
6 changes: 3 additions & 3 deletions packages/sdk/test/test-utils/customMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
interface Matchers<R> {
toThrowStreamrError(expectedError: PartialStreamrClientError): R
toThrowStreamrClientError(expectedError: PartialStreamrClientError): R
}
}
}
Expand All @@ -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 => {
Expand Down Expand Up @@ -67,5 +67,5 @@ const toThrowStreamrError = (
}

expect.extend({
toThrowStreamrError
toThrowStreamrClientError
})
2 changes: 1 addition & 1 deletion packages/sdk/test/unit/Publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/test/unit/PushBuffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/test/unit/Resends.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/unit/Stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/unit/StreamrClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/test/unit/customMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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'
})
Expand All @@ -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'
})
Expand All @@ -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'
})
Expand All @@ -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')
})
})
Expand Down

0 comments on commit 497136d

Please sign in to comment.