Skip to content

Commit

Permalink
[JS] Fix method sendEvent for event types different from custom (#172)
Browse files Browse the repository at this point in the history
* PubNub js 0.11.5 release.

---------

Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
marcin-cebo and pubnub-release-bot authored Feb 7, 2025
1 parent 2c46f05 commit d913917
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=false
GROUP=com.pubnub
POM_PACKAGING=jar
VERSION_NAME=0.11.4
VERSION_NAME=0.11.5

POM_NAME=PubNub Chat SDK
POM_DESCRIPTION=This SDK offers a set of handy methods to create your own feature-rich chat or add a chat to your existing application.
Expand Down
7 changes: 6 additions & 1 deletion js-chat/.pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: pubnub-js-chat
version: 0.11.4
version: 0.11.5
scm: github.com/pubnub/js-chat
schema: 1
files:
- lib/dist/index.js
changelog:
- date: 2025-02-06
version: 0.11.5
changes:
- type: bug
text: "Fixed method sendEvent for event types different from custom ."
- date: 2025-02-04
version: 0.11.4
changes:
Expand Down
2 changes: 1 addition & 1 deletion js-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"module": "dist/index.es.js",
"types": "dist/index.d.ts",
"react-native": "dist/index.es.js",
"version": "0.11.4",
"version": "0.11.5",
"name": "@pubnub/chat",
"dependencies": {
"pubnub": "8.6.0",
Expand Down
106 changes: 83 additions & 23 deletions js-chat/tests/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,36 +1276,96 @@ describe("Channel test", () => {
expect(result.channels.length).toBe(2)
})

test("send report event", async () => {
let receivedEvent
const reason = "rude"
const text = "reporting"
const unsubscribe = chat.listenForEvents({
channel: channel.id,
type: "report",
callback: (event) => {
receivedEvent = event
},
})

await sleep(1000)
await chat.emitEvent({
channel: channel.id,
type: 'report',
payload: {
text: text,
reason: reason
}
})
await sleep(500)
expect(receivedEvent.payload.text).toEqual(text)
expect(receivedEvent.payload.reason).toEqual(reason)

unsubscribe(); // Cleanup
})

test("send receipt event", async () => {
let receivedEvent
const messageTimetokenValue = "123"
const eventTypeReceipt = "receipt"

const unsubscribe = chat.listenForEvents({
type: eventTypeReceipt,
channel: channel.id,
callback: event => {
receivedEvent = event
}
})

await sleep(1000)
await chat.emitEvent({
type: eventTypeReceipt,
channel: channel.id,
payload: {
messageTimetoken: messageTimetokenValue
}

})

await sleep(500)
expect(receivedEvent.payload.messageTimetoken).toEqual(messageTimetokenValue)
expect(receivedEvent.type).toEqual(eventTypeReceipt)

unsubscribe() // cleanup
})

test("send custom event", async () => {
const inviteCallback = jest.fn()
const unsubscribe = chat.listenForEvents({
channel: channel.id,
type: "custom",
method: "publish",
callback: inviteCallback,
})

await sleep(1000)
await chat.emitEvent({
channel: channel.id,
type: 'custom',
method: 'publish',
payload: {
action: "action",
body: "payload"
}
})
await sleep(2000)
expect(inviteCallback).toHaveBeenCalledTimes(1)
expect(inviteCallback).toHaveBeenCalledWith(
const inviteCallback = jest.fn()
const unsubscribe = chat.listenForEvents({
channel: channel.id,
type: "custom",
method: "publish",
callback: inviteCallback,
})

await sleep(1000)
await chat.emitEvent({
channel: channel.id,
type: 'custom',
method: 'publish',
payload: {
action: "action",
body: "payload"
}
})
await sleep(2000)
expect(inviteCallback).toHaveBeenCalledTimes(1)
expect(inviteCallback).toHaveBeenCalledWith(
expect.objectContaining({
payload: expect.objectContaining({
action: "action",
body: "payload"
}),
})
)
})
)

unsubscribe(); // Cleanup
})

test("use PubNub SDK types from Chat SDK", async () => {
let channelMetadata = await chat.sdk.objects.getChannelMetadata({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ class ChatIntegrationTest : BaseChatIntegrationTest() {
}
}

delayForHistory()
delayForHistory()
val eventFromHistory = chat.getEventsHistory(channelId, tt + 1, tt).await().events.first()
val payload: EventContent.Custom = eventFromHistory.payload as EventContent.Custom
Expand Down
2 changes: 1 addition & 1 deletion pubnub-chat-impl/src/jsMain/kotlin/ChatJs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ChatJs internal constructor(val chat: ChatInternal, val config: ChatConfig
EventContent.Custom((payload as JsMap<Any?>).toMap(), method)
} else {
payload.type = type
PNDataEncoder.decode(createJsonElement(payload))
PNDataEncoder.decode<EventContent>(createJsonElement(payload))
}
return chat.emitEvent(
channel,
Expand Down

0 comments on commit d913917

Please sign in to comment.