aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/javascript/src/unit/subscriptions_test.coffee
blob: 170b370e4a0361916100fc3a8851fb85c489f4aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{module, test} = QUnit
{consumerTest} = ActionCable.TestHelpers

module "ActionCable.Subscriptions", ->
  consumerTest "create subscription with channel string", ({consumer, server, assert, done}) ->
    channel = "chat"

    server.on "message", (message) ->
      data = JSON.parse(message)
      assert.equal data.command, "subscribe"
      assert.equal data.identifier, JSON.stringify({channel})
      done()

    consumer.subscriptions.create(channel)

  consumerTest "create subscription with channel object", ({consumer, server, assert, done}) ->
    channel = channel: "chat", room: "action"

    server.on "message", (message) ->
      data = JSON.parse(message)
      assert.equal data.command, "subscribe"
      assert.equal data.identifier, JSON.stringify(channel)
      done()

    consumer.subscriptions.create(channel)