You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
5 years ago
|
import { expect } from 'chai';
|
||
|
|
||
5 years ago
|
import { TypingMessage } from '../../../../session/messages/outgoing';
|
||
|
import { SignalService } from '../../../../protobuf';
|
||
5 years ago
|
import Long from 'long';
|
||
5 years ago
|
import { toNumber } from 'lodash';
|
||
5 years ago
|
import { StringUtils } from '../../../../session/utils';
|
||
|
import { TestUtils } from '../../../test-utils';
|
||
|
import { Constants } from '../../../../session';
|
||
5 years ago
|
|
||
|
describe('TypingMessage', () => {
|
||
5 years ago
|
it('has Action.STARTED if isTyping = true', () => {
|
||
|
const message = new TypingMessage({
|
||
|
timestamp: Date.now(),
|
||
|
isTyping: true,
|
||
5 years ago
|
});
|
||
5 years ago
|
const plainText = message.plainTextBuffer();
|
||
|
const decoded = SignalService.Content.decode(plainText);
|
||
|
expect(decoded.typingMessage).to.have.property(
|
||
|
'action',
|
||
|
SignalService.TypingMessage.Action.STARTED
|
||
|
);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('has Action.STOPPED if isTyping = false', () => {
|
||
|
const message = new TypingMessage({
|
||
|
timestamp: Date.now(),
|
||
|
isTyping: false,
|
||
5 years ago
|
});
|
||
5 years ago
|
const plainText = message.plainTextBuffer();
|
||
|
const decoded = SignalService.Content.decode(plainText);
|
||
|
expect(decoded.typingMessage).to.have.property(
|
||
|
'action',
|
||
|
SignalService.TypingMessage.Action.STOPPED
|
||
|
);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('has typingTimestamp set if value passed', () => {
|
||
|
const message = new TypingMessage({
|
||
|
timestamp: Date.now(),
|
||
|
isTyping: true,
|
||
|
typingTimestamp: 111111111,
|
||
5 years ago
|
});
|
||
5 years ago
|
const plainText = message.plainTextBuffer();
|
||
|
const decoded = SignalService.Content.decode(plainText);
|
||
5 years ago
|
const decodedtimestamp = toNumber(decoded.typingMessage?.timestamp);
|
||
|
expect(decodedtimestamp).to.be.equal(111111111);
|
||
5 years ago
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('has typingTimestamp set with Date.now() if value not passed', () => {
|
||
|
const message = new TypingMessage({
|
||
|
timestamp: Date.now(),
|
||
|
isTyping: true,
|
||
5 years ago
|
});
|
||
5 years ago
|
const plainText = message.plainTextBuffer();
|
||
|
const decoded = SignalService.Content.decode(plainText);
|
||
|
let timestamp = decoded.typingMessage?.timestamp;
|
||
|
if (timestamp instanceof Long) {
|
||
|
timestamp = timestamp.toNumber();
|
||
|
}
|
||
|
expect(timestamp).to.be.approximately(Date.now(), 10);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('correct ttl', () => {
|
||
5 years ago
|
const message = new TypingMessage({
|
||
|
timestamp: Date.now(),
|
||
|
isTyping: true,
|
||
5 years ago
|
});
|
||
5 years ago
|
expect(message.ttl()).to.equal(Constants.TTL_DEFAULT.TYPING_MESSAGE);
|
||
5 years ago
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('has an identifier', () => {
|
||
|
const message = new TypingMessage({
|
||
|
timestamp: Date.now(),
|
||
|
isTyping: true,
|
||
5 years ago
|
});
|
||
5 years ago
|
expect(message.identifier).to.not.equal(null, 'identifier cannot be null');
|
||
|
expect(message.identifier).to.not.equal(
|
||
|
undefined,
|
||
|
'identifier cannot be undefined'
|
||
|
);
|
||
|
});
|
||
5 years ago
|
});
|