chore: restore back to recipients + add test
Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { DefaultSignalService } from './DefaultSignalService';
|
||||
|
||||
describe('DefaultSignalService', () => {
|
||||
const mockEventBroker = {
|
||||
publish: jest.fn(),
|
||||
subscribe: jest.fn(),
|
||||
};
|
||||
|
||||
const service = DefaultSignalService.create({ eventBroker: mockEventBroker });
|
||||
|
||||
it('should publish signal', () => {
|
||||
const signal = {
|
||||
channel: 'test-channel',
|
||||
recipients: null,
|
||||
message: { msg: 'hello world' },
|
||||
};
|
||||
service.publish(signal);
|
||||
expect(mockEventBroker.publish).toHaveBeenCalledWith({
|
||||
topic: 'signals',
|
||||
eventPayload: signal,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -37,14 +37,9 @@ export class DefaultSignalService implements SignalService {
|
||||
* @param message - message to publish
|
||||
*/
|
||||
async publish(signal: SignalPayload) {
|
||||
const { receivers, channel, message } = signal;
|
||||
await this.eventBroker?.publish({
|
||||
topic: 'signals',
|
||||
eventPayload: {
|
||||
receivers,
|
||||
message,
|
||||
channel,
|
||||
},
|
||||
eventPayload: signal,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export type SignalServiceOptions = {
|
||||
|
||||
/** @public */
|
||||
export type SignalPayload = {
|
||||
receivers: string[] | string | null;
|
||||
recipients: string[] | string | null;
|
||||
channel: string;
|
||||
message: JsonObject;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user