From d2eb40f6ccb24dfe8175e93395b22f27e654475e Mon Sep 17 00:00:00 2001 From: Alex Risch Date: Wed, 13 Mar 2024 18:50:34 -0600 Subject: [PATCH 1/5] Stream Validation WIP Stream Validation test Added complex streaming example --- example/src/tests.ts | 109 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/example/src/tests.ts b/example/src/tests.ts index 9431bc9ce..beeac8465 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -1367,3 +1367,112 @@ test('get all HMAC keys', async () => { return true }) + +test('can handle complex streaming setup', async () => { + const bo = await Client.createRandom({ env: 'dev' }) + await delayToPropogate() + const alix = await Client.createRandom({ env: 'dev' }) + await delayToPropogate() + + const allConvos: Conversation[] = [] + await alix.conversations.stream(async (convo) => { + allConvos.push(convo) + }) + const allMessages: DecodedMessage[] = [] + await alix.conversations.streamAllMessages(async (message) => { + allMessages.push(message) + }) + + const conv1 = await bo.conversations.newConversation(alix.address) + await delayToPropogate() + + await bo.conversations.newConversation(alix.address, { + conversationID: 'convo-2', + metadata: {}, + }) + const allConvMessages: DecodedMessage[] = [] + conv1.streamMessages(async (message) => { + allConvMessages.push(message) + }) + await conv1.send({ text: 'Hello' }) + await delayToPropogate() + + assert( + allConvos.length === 2, + 'Unexpected all convos count1 ' + allConvos.length + ) + + assert( + allMessages.length === 1, + 'Unexpected all messages count2 ' + allMessages.length + ) + + assert( + allConvMessages.length === 1, + 'Unexpected all conv messages count3 ' + allConvMessages.length + ) + + await sleep(15000) + const conv3 = await bo.conversations.newConversation(alix.address, { + conversationID: 'convo-3', + metadata: {}, + }) + const allConv3Messages: DecodedMessage[] = [] + conv3.streamMessages(async (message) => { + allConv3Messages.push(message) + }) + await conv1.send({ text: 'Hello' }) + await conv3.send({ text: 'Hello' }) + await delayToPropogate() + + assert( + allConvos.length === 3, + 'Unexpected all convos count4 ' + allConvos.length + ) + + assert( + allMessages.length === 3, + 'Unexpected all messages count5 ' + allMessages.length + ) + + assert( + allConvMessages.length === 2, + 'Unexpected all conv messages count6 ' + allConvMessages.length + ) + + assert( + allConv3Messages.length === 1, + 'Unexpected all conv3 messages count7 ' + allConv3Messages.length + ) + + alix.conversations.cancelStream() + alix.conversations.cancelStreamAllMessages() + + await bo.conversations.newConversation(alix.address, { + conversationID: 'convo-4', + metadata: {}, + }) + await conv3.send({ text: 'Hello' }) + + assert( + allConvos.length === 3, + 'Unexpected all convos count8 ' + allConvos.length + ) + + assert( + allMessages.length === 3, + 'Unexpected all messages count9 ' + allMessages.length + ) + + assert( + allConvMessages.length === 2, + 'Unexpected all conv messages count10 ' + allConvMessages.length + ) + + assert( + allConv3Messages.length === 2, + 'Unexpected all conv3 messages count11 ' + allConv3Messages.length + ) + + return true +}) From 482f0ffb57195e192788a04420efd0d982ea6187 Mon Sep 17 00:00:00 2001 From: Alex Risch Date: Thu, 14 Mar 2024 20:12:18 -0600 Subject: [PATCH 2/5] Stream Validation Added tests Added UI for hanlding streams/conversations Ability to export events as well to recreate in normal testing pattern --- example/App.tsx | 6 + example/src/LaunchScreen.tsx | 8 + example/src/Navigation.tsx | 1 + example/src/StreamScreen.tsx | 337 +++++++++++++++++++++++++++++++++++ example/src/tests.ts | 121 ++++++++++++- 5 files changed, 468 insertions(+), 5 deletions(-) create mode 100644 example/src/StreamScreen.tsx diff --git a/example/App.tsx b/example/App.tsx index 8f3f529da..2a7f8b531 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -17,6 +17,7 @@ import ConversationScreen from './src/ConversationScreen' import HomeScreen from './src/HomeScreen' import LaunchScreen from './src/LaunchScreen' import { Navigator } from './src/Navigation' +import StreamScreen from './src/StreamScreen' import TestScreen from './src/TestScreen' const queryClient = new QueryClient() @@ -94,6 +95,11 @@ export default function App() { component={ConversationCreateScreen} options={{ title: 'New Conversation' }} /> + diff --git a/example/src/LaunchScreen.tsx b/example/src/LaunchScreen.tsx index 3bf8f37bb..8b8225fcc 100644 --- a/example/src/LaunchScreen.tsx +++ b/example/src/LaunchScreen.tsx @@ -89,6 +89,14 @@ export default function LaunchScreen({ accessibilityLabel="Unit-tests" /> + +