-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
186 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Realtime, Types } from 'ably/promises'; | ||
import pino from 'pino'; | ||
import { it, describe, expect, beforeEach, afterEach } from 'vitest'; | ||
|
||
import Stream from './Stream.js'; | ||
import { defaultSyncOptions, defaultEventBufferOptions } from '../Options.js'; | ||
import type { StreamOptions } from '../types/stream.js'; | ||
import { createAblyApp } from '../utilities/test/createAblyApp.js'; | ||
|
||
interface StreamTestContext extends StreamOptions { | ||
stream: Stream; | ||
channel: Types.RealtimeChannelPromise; | ||
} | ||
|
||
describe('Stream integration', () => { | ||
beforeEach<StreamTestContext>(async (context) => { | ||
const name = 'test'; | ||
const data = await createAblyApp({ | ||
keys: [{}], | ||
namespaces: [{ id: name, persisted: true }], | ||
channels: [ | ||
{ | ||
name, | ||
presence: [ | ||
{ clientId: 'John', data: 'john@test.com' }, | ||
{ clientId: 'Dave', data: 'dave@test.com' }, | ||
], | ||
}, | ||
], | ||
}); | ||
const ably = new Realtime({ | ||
key: data.keys[0].keyStr, | ||
environment: 'sandbox', | ||
}); | ||
const logger = pino({ level: 'silent' }); | ||
const channel = ably.channels.get(name); | ||
const stream = new Stream({ | ||
ably, | ||
logger, | ||
channelName: name, | ||
syncOptions: defaultSyncOptions, | ||
eventBufferOptions: defaultEventBufferOptions, | ||
}); | ||
|
||
context.stream = stream; | ||
context.channel = channel; | ||
}); | ||
|
||
afterEach<StreamTestContext>(async ({ stream, channel }) => { | ||
await stream.dispose(); | ||
await channel.detach(); | ||
}); | ||
|
||
it<StreamTestContext>('sets agent options when state is not attached', async ({ channel, stream }) => { | ||
await stream.replay('0'); | ||
//@ts-ignore - `agent` is filtered out in `channel.params`, so that's the only way to check this | ||
expect(channel.channelOptions.params).toEqual({ agent: 'models/0.0.2' }); // initial call from test | ||
}); | ||
|
||
it<StreamTestContext>('does not sets agent options when state is attached', async ({ channel }) => { | ||
await channel.attach(); | ||
//@ts-ignore - `agent` is filtered out in `channel.params`, so that's the only way to check this | ||
expect(channel.channelOptions.params).toEqual(undefined); // initial call from test | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import ky from 'ky'; | ||
|
||
export const createAblyApp = async (json: Options): Promise<Data> => { | ||
const response = await ky | ||
.post('https://sandbox-rest.ably.io/apps', { | ||
json, | ||
headers: { | ||
'content-type': 'application/json', | ||
Accept: 'application/json', | ||
}, | ||
}) | ||
.json<Data>(); | ||
return response; | ||
}; | ||
|
||
interface Key { | ||
capability?: { | ||
private: ('subscribe' | 'publish')[]; | ||
chat?: 'presence'[]; | ||
}; | ||
} | ||
|
||
interface Namespace { | ||
id: string; | ||
persisted: boolean; | ||
} | ||
|
||
interface Presence { | ||
clientId: string; | ||
data: string; | ||
} | ||
|
||
interface Channel { | ||
name: string; | ||
presence: Presence[]; | ||
} | ||
|
||
interface Options { | ||
keys?: Key[]; | ||
namespaces?: Namespace[]; | ||
channels?: Channel[]; | ||
} | ||
|
||
interface Data { | ||
status: number; | ||
created: Date; | ||
modified: Date; | ||
tlsOnly: boolean; | ||
labels: string; | ||
enablePusherCompatibility: boolean; | ||
namespaces: { | ||
id: string; | ||
created: Date; | ||
modified: Date; | ||
expires: Date | null; | ||
persisted: boolean; | ||
persistLast: boolean; | ||
pushEnabled: boolean; | ||
exposeTimeserial: boolean; | ||
populateChannelRegistry: boolean; | ||
tlsOnly: boolean; | ||
authenticated: boolean; | ||
identified: boolean; | ||
cursorEventProcessing: boolean; | ||
}[]; | ||
metaChannels: any; | ||
id: string; | ||
appId: string; | ||
accountId: string; | ||
keys: { | ||
id: string; | ||
value: string; | ||
keyName: string; | ||
keySecret: string; | ||
keyStr: string; | ||
capability: string; | ||
expires: Date; | ||
}[]; | ||
connections: { | ||
name: string; | ||
key: string; | ||
}[]; | ||
channels: { | ||
name: string; | ||
presence: Presence[]; | ||
connection: string; | ||
}[]; | ||
} |