Check for X-Signal-Alert header, and report it in a callback

This on-connect header will be used for lightweight "alerts" from the
server to an authenticated client. For now, it's only threaded through
to the Node implementation; the iOS and Android ones will come later.
This commit is contained in:
Jordan Rose
2025-03-04 15:07:23 -08:00
committed by GitHub
parent 3580994ba9
commit 2ebd7cd2b3
28 changed files with 312 additions and 41 deletions

View File

@@ -421,12 +421,25 @@ describe('chat service api', () => {
const listener = {
onIncomingMessage: sinon.stub(),
onQueueEmpty: sinon.stub(),
onReceivedAlerts: sinon.stub(),
onConnectionInterrupted: sinon.stub(),
};
// We have to set this up ahead of time because the callback is scheduled as part of the
// connect action.
const receivedAlerts = new CompletablePromise();
listener.onReceivedAlerts.callsFake(receivedAlerts.resolve);
const tokio = new TokioAsyncContext(Native.TokioAsyncContext_new());
const [_chat, fakeRemote] = AuthenticatedChatConnection.fakeConnect(
tokio,
listener
listener,
['UPPERcase', 'lowercase']
);
await receivedAlerts.done();
expect(listener.onReceivedAlerts).to.have.been.calledOnceWith(
sinon.match.array.deepEquals(['UPPERcase', 'lowercase'])
);
// a helper function to check that the message has been passed to the listener
@@ -475,6 +488,9 @@ describe('chat service api', () => {
onQueueEmpty(): void {
recordCall('_queue_empty');
},
onReceivedAlerts(alerts: string[]): void {
recordCall('_received_alerts', alerts);
},
onConnectionInterrupted(cause: object | null): void {
recordCall('_connection_interrupted', cause);
},
@@ -499,6 +515,10 @@ describe('chat service api', () => {
];
const callsReceived: [string, (object | null)[]][] = [];
const callsExpected: [string, ((value: object | null) => void)[]][] = [
[
'_received_alerts',
[(value: object | null) => expect(value).deep.equals([])],
],
['_incoming_message', []],
['_queue_empty', []],
['_incoming_message', []],
@@ -550,6 +570,9 @@ describe('chat service api', () => {
onQueueEmpty(): void {
fail('unexpected call');
},
onReceivedAlerts(_alerts: string[]): void {
fail('unexpected call');
},
onConnectionInterrupted(cause: object | null): void {
connectionInterruptedReasons.push(cause);
completable.complete();
@@ -571,6 +594,7 @@ describe('chat service api', () => {
const [chat, fakeRemote] = AuthenticatedChatConnection.fakeConnect(tokio, {
onIncomingMessage: () => {},
onQueueEmpty: () => {},
onReceivedAlerts() {},
onConnectionInterrupted: () => {},
});