Skip to content

Commit

Permalink
Merge pull request #5008 from rmosolgo/fix-relay-subscription-empty-s…
Browse files Browse the repository at this point in the history
…tring

Fix Relay subscription handler sending an empty string
  • Loading branch information
rmosolgo committed Jul 3, 2024
2 parents 516a2f6 + 99d787b commit 843014f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import createRelaySubscriptionHandler from "../createRelaySubscriptionHandler"
import { createLegacyRelaySubscriptionHandler } from "../createRelaySubscriptionHandler"
import type { Consumer } from "@rails/actioncable"
import { Network} from 'relay-runtime'
import { Network } from 'relay-runtime'

describe("createRelaySubscriptionHandler", () => {
it("returns a function producing a observable subscription", () => {
Expand All @@ -20,6 +20,48 @@ describe("createRelaySubscriptionHandler", () => {
// basically, make sure this doesn't blow up during type-checking or runtime
expect(Network.create(fetchQuery, handler)).toBeTruthy()
})

it("doesn't send an empty string when no string is given", () => {
var channel: any;
var performLog: any[] = [];
var dummyActionCableConsumer = {
subscriptions: {
create: (opts1: any, opts2: any) => {
channel = Object.assign(
opts1,
opts2,
{
unsubscribe: () => true,
perform: (event: string, payload: object) => performLog.push([event, payload]),

}
)
return channel
}
},
}

var options = {
cable: (dummyActionCableConsumer as unknown) as Consumer
}

var handler = createRelaySubscriptionHandler(options)
var observable = handler({id: "abc", text: null, name: "def", operationKind: "subscription", metadata: {}}, { abc: true});
observable.subscribe({})
channel.connected()
var expectedLog = [
[
'execute',
{
variables: { abc: true },
operationName: 'def',
query: null,
operationId: null
}
]
]
expect(performLog).toEqual(expectedLog)
})
})

describe("createLegacyRelaySubscriptionHandler", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function createRelaySubscriptionHandler(options: ActionCableHandlerOptions | Pus
}) => {
const client = handler(
{
text: request.text || "",
text: request.text,
name: request.name,
id: request.id,
},
Expand Down

0 comments on commit 843014f

Please sign in to comment.