add GroupInvitationMessage and tests
parent
56d744fda9
commit
9ea95e59fa
@ -1,13 +1,39 @@
|
|||||||
import { DataMessage } from './DataMessage';
|
import { DataMessage } from './DataMessage';
|
||||||
import { SignalService } from '../../../../../protobuf';
|
import { SignalService } from '../../../../../protobuf';
|
||||||
|
|
||||||
|
interface GroupInvitationMessageParams {
|
||||||
|
timestamp: number;
|
||||||
|
identifier: string;
|
||||||
|
serverAddress: string;
|
||||||
|
channelId: number;
|
||||||
|
serverName: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class GroupInvitationMessage extends DataMessage {
|
export class GroupInvitationMessage extends DataMessage {
|
||||||
|
private readonly serverAddress: string;
|
||||||
|
private readonly channelId: number;
|
||||||
|
private readonly serverName: string;
|
||||||
|
|
||||||
|
constructor(params: GroupInvitationMessageParams) {
|
||||||
|
super({ timestamp: params.timestamp, identifier: params.identifier });
|
||||||
|
this.serverAddress = params.serverAddress;
|
||||||
|
this.channelId = params.channelId;
|
||||||
|
this.serverName = params.serverName;
|
||||||
|
}
|
||||||
|
|
||||||
public ttl(): number {
|
public ttl(): number {
|
||||||
return this.getDefaultTTL();
|
return this.getDefaultTTL();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected dataProto(): SignalService.DataMessage {
|
protected dataProto(): SignalService.DataMessage {
|
||||||
throw new Error('Not implemented');
|
const groupInvitation = new SignalService.DataMessage.GroupInvitation({
|
||||||
|
serverAddress: this.serverAddress,
|
||||||
|
channelId: this.channelId,
|
||||||
|
serverName: this.serverName,
|
||||||
|
});
|
||||||
|
|
||||||
|
return new SignalService.DataMessage({
|
||||||
|
groupInvitation,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
import { expect } from 'chai';
|
||||||
|
import { beforeEach} from 'mocha';
|
||||||
|
|
||||||
|
import { GroupInvitationMessage } from '../../../session/messages/outgoing';
|
||||||
|
import { SignalService } from '../../../protobuf';
|
||||||
|
|
||||||
|
describe('GroupInvitationMessage', () => {
|
||||||
|
let message: GroupInvitationMessage;
|
||||||
|
const timestamp = Date.now();
|
||||||
|
const identifier = '123456';
|
||||||
|
const serverAddress = 'http://localhost';
|
||||||
|
const channelId = 1;
|
||||||
|
const serverName = 'test';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
message = new GroupInvitationMessage({
|
||||||
|
timestamp,
|
||||||
|
identifier,
|
||||||
|
serverAddress,
|
||||||
|
channelId,
|
||||||
|
serverName,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('dataMessage.groupInvitation has serverAddress, channelId, and serverName set', () => {
|
||||||
|
const plainText = message.plainTextBuffer();
|
||||||
|
const decoded = SignalService.Content.toObject(SignalService.Content.decode(plainText));
|
||||||
|
|
||||||
|
expect(decoded.dataMessage.groupInvitation).to.have.property('serverAddress', serverAddress);
|
||||||
|
expect(decoded.dataMessage.groupInvitation).to.have.property('channelId', channelId);
|
||||||
|
expect(decoded.dataMessage.groupInvitation).to.have.property('serverName', serverName);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ttl of 1 day', () => {
|
||||||
|
expect(message.ttl()).to.equal(24 * 60 * 60 * 1000);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue