-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert the web socket transport to a channel
- Loading branch information
1 parent
d341abb
commit 859d964
Showing
29 changed files
with
782 additions
and
732 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 26 additions & 7 deletions
33
packages/rpc-subscriptions-api/src/__tests__/index-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,39 @@ | ||
import type { RpcSubscriptionsApi } from '@solana/rpc-subscriptions-spec'; | ||
import { executeRpcPubSubSubscriptionPlan, type RpcSubscriptionsApi } from '@solana/rpc-subscriptions-spec'; | ||
|
||
import { createSolanaRpcSubscriptionsApi } from '..'; | ||
import { createSolanaRpcSubscriptionsApi } from '../index'; | ||
|
||
type TestRpcSubscriptionNotifications = { | ||
thingNotifications(...args: unknown[]): unknown; | ||
}; | ||
|
||
describe('RpcSubscriptionsApi', () => { | ||
jest.mock('@solana/rpc-subscriptions-spec', () => ({ | ||
...jest.requireActual('@solana/rpc-subscriptions-spec'), | ||
executeRpcPubSubSubscriptionPlan: jest.fn().mockReturnValue( | ||
new Promise(() => { | ||
/* never resolves */ | ||
}), | ||
), | ||
})); | ||
|
||
describe('createSolanaRpcSubscriptionsApi', () => { | ||
let api: RpcSubscriptionsApi<TestRpcSubscriptionNotifications>; | ||
beforeEach(() => { | ||
api = createSolanaRpcSubscriptionsApi(); | ||
}); | ||
it('synthesizes subscribe/unsubscribe method names from the name of the notification', () => { | ||
expect(api.thingNotifications()).toMatchObject({ | ||
subscribeMethodName: 'thingSubscribe', | ||
unsubscribeMethodName: 'thingUnsubscribe', | ||
it('creates a subscription plan that synthesizes the correct subscribe/unsubscribe method names from the name of the notification', () => { | ||
const { executeSubscriptionPlan } = api.thingNotifications(); | ||
executeSubscriptionPlan({ | ||
channel: { | ||
on: jest.fn(), | ||
send: jest.fn(), | ||
}, | ||
signal: new AbortController().signal, | ||
}); | ||
expect(executeRpcPubSubSubscriptionPlan).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
subscribeMethodName: 'thingSubscribe', | ||
unsubscribeMethodName: 'thingUnsubscribe', | ||
}), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.