use toNumber from lodash to make testing of Long cleaner

pull/1151/head
Audric Ackermann 5 years ago
parent a4bb22f16a
commit 77552aa3b7
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -8,6 +8,7 @@ import {
} from '../../../session/messages/outgoing';
import { SignalService } from '../../../protobuf';
import { TextEncoder } from 'util';
import { toNumber } from 'lodash';
describe('ChatMessage', () => {
it('can create empty message with just a timestamp', () => {
@ -75,7 +76,8 @@ describe('ChatMessage', () => {
});
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.decode(plainText);
expect(decoded.dataMessage?.quote?.id).to.have.property('low', 1234);
const decodedID = toNumber(decoded.dataMessage?.quote?.id);
expect(decodedID).to.be.equal(1234);
expect(decoded.dataMessage?.quote).to.have.deep.property(
'author',
'author'
@ -119,15 +121,11 @@ describe('ChatMessage', () => {
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.decode(plainText);
expect(decoded.dataMessage?.attachments).to.have.lengthOf(1);
expect(decoded.dataMessage)
.to.have.nested.property('attachments[0].id')
.to.have.property('low', 1234);
expect(decoded.dataMessage)
.to.have.nested.property('attachments[0].contentType')
.to.be.deep.equal('contentType');
expect(decoded.dataMessage)
.to.have.nested.property('attachments[0].url')
.to.be.deep.equal('url');
const firstAttachment = decoded?.dataMessage?.attachments?.[0];
const decodedID = toNumber(firstAttachment?.id);
expect(decodedID).to.be.equal(1234);
expect(firstAttachment?.contentType).to.be.deep.equal('contentType');
expect(firstAttachment?.url).to.be.deep.equal('url');
});
it('ttl of 1 day', () => {

@ -6,6 +6,7 @@ import {
ReadReceiptMessage,
} from '../../../session/messages/outgoing';
import { SignalService } from '../../../protobuf';
import { toNumber } from 'lodash';
describe('ReceiptMessage', () => {
let readMessage: ReadReceiptMessage;
@ -24,15 +25,10 @@ describe('ReceiptMessage', () => {
const decoded = SignalService.Content.decode(plainText);
expect(decoded.receiptMessage).to.have.property('type', 1);
expect(decoded.receiptMessage?.timestamp).to.have.lengthOf(2);
expect(decoded.receiptMessage).to.have.nested.property(
'timestamp[0].low',
timestamps[0]
);
expect(decoded.receiptMessage).to.have.nested.property(
'timestamp[1].low',
timestamps[1]
const decodedTimestamps = (decoded.receiptMessage?.timestamp ?? []).map(
toNumber
);
expect(decodedTimestamps).to.deep.equal(timestamps);
});
it('content of a delivery receipt is correct', () => {
@ -40,15 +36,10 @@ describe('ReceiptMessage', () => {
const decoded = SignalService.Content.decode(plainText);
expect(decoded.receiptMessage).to.have.property('type', 0);
expect(decoded.receiptMessage?.timestamp).to.have.lengthOf(2);
expect(decoded.receiptMessage).to.have.nested.property(
'timestamp[0].low',
timestamps[0]
);
expect(decoded.receiptMessage).to.have.nested.property(
'timestamp[1].low',
timestamps[1]
const decodedTimestamps = (decoded.receiptMessage?.timestamp ?? []).map(
toNumber
);
expect(decodedTimestamps).to.deep.equal(timestamps);
});
it('ttl of 1 day', () => {

@ -4,6 +4,7 @@ import { TypingMessage } from '../../../session/messages/outgoing';
import { SignalService } from '../../../protobuf';
import { TextEncoder } from 'util';
import Long from 'long';
import { toNumber } from 'lodash';
describe('TypingMessage', () => {
it('has Action.STARTED if isTyping = true', () => {
@ -40,7 +41,8 @@ describe('TypingMessage', () => {
});
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.decode(plainText);
expect(decoded.typingMessage?.timestamp).to.have.property('low', 111111111);
const decodedtimestamp = toNumber(decoded.typingMessage?.timestamp);
expect(decodedtimestamp).to.be.equal(111111111);
});
it('has typingTimestamp set with Date.now() if value not passed', () => {

Loading…
Cancel
Save