Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Nov 26, 2024
1 parent 3bb0ff2 commit 0773a8a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
21 changes: 8 additions & 13 deletions packages/transport-http/src/subscribe/subscription-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
SubscriptionDataMessage,
UnsubscribeMessageRequest,
} from "./models"
import {SubscriptionManager} from "./subscription-manager"
import {
SubscriptionManager,
SubscriptionManagerConfig,
} from "./subscription-manager"
import {SdkTransport} from "@onflow/typedefs"

jest.mock("./websocket", () => ({
Expand All @@ -25,10 +28,8 @@ describe("WsSubscriptionTransport", () => {
})

test("does not connect to the socket when no subscriptions are made", async () => {
const config = {
const config: SubscriptionManagerConfig = {
node: "wss://localhost:8080",
reconnectInterval: 1000,
reconnectAttempts: 10,
}

new SubscriptionManager(config)
Expand All @@ -38,10 +39,8 @@ describe("WsSubscriptionTransport", () => {
})

test("disconnects from the socket when the last subscription is removed", async () => {
const config = {
const config: SubscriptionManagerConfig = {
node: "wss://localhost:8080",
reconnectInterval: 1000,
reconnectAttempts: 10,
}
const streamController = new SubscriptionManager(config)
const topic = "topic" as SdkTransport.SubscriptionTopic
Expand Down Expand Up @@ -90,10 +89,8 @@ describe("WsSubscriptionTransport", () => {
})

test("subscribes, receives data, and unsubscribes", async () => {
const config = {
const config: SubscriptionManagerConfig = {
node: "wss://localhost:8080",
reconnectInterval: 1000,
reconnectAttempts: 10,
}
const streamController = new SubscriptionManager(config)
const topic = "topic" as SdkTransport.SubscriptionTopic
Expand Down Expand Up @@ -162,10 +159,8 @@ describe("WsSubscriptionTransport", () => {
})

test("reconnects to stream on close", async () => {
const config = {
const config: SubscriptionManagerConfig = {
node: "wss://localhost:8080",
reconnectInterval: 1000,
reconnectAttempts: 1,
}
const streamController = new SubscriptionManager(config)
const topic = "topic" as SdkTransport.SubscriptionTopic
Expand Down
6 changes: 3 additions & 3 deletions packages/transport-http/src/subscribe/subscription-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface SubscriptionInfo<T extends SdkTransport.SubscriptionTopic> {
onError: (error: Error) => void
}

interface WsTransportConfig {
export interface SubscriptionManagerConfig {
/**
* The URL of the node to connect to
*/
Expand Down Expand Up @@ -65,10 +65,10 @@ export class SubscriptionManager {
private counter = 0
private subscriptions: SubscriptionInfo<SdkTransport.SubscriptionTopic>[] = []
private socket: WebSocket | null = null
private config: DeepRequired<WsTransportConfig>
private config: DeepRequired<SubscriptionManagerConfig>
private reconnectAttempts = 0

constructor(config: WsTransportConfig) {
constructor(config: SubscriptionManagerConfig) {
this.config = {
...config,
reconnectOptions: {
Expand Down

0 comments on commit 0773a8a

Please sign in to comment.