js-waku/src/lib/chat_message/index.spec.ts
Franck Royer e91f7933c9
Pass proto in constructor
Makes the relation between the protobuf class and the wrapper more
direct. Conversion only happens at creates or on getters.
2021-05-10 16:29:25 +10:00

27 lines
818 B
TypeScript

import { expect } from 'chai';
import fc from 'fast-check';
import { ChatMessage } from './index';
describe('Chat Message', function () {
it('Chat message round trip binary serialization', function () {
fc.assert(
fc.property(
fc.date({ min: new Date(0) }),
fc.string(),
fc.string(),
(timestamp, nick, message) => {
const msg = ChatMessage.fromUtf8String(timestamp, nick, message);
const buf = msg.encode();
const actual = ChatMessage.decode(buf);
// Date.toString does not include ms, as we loose this precision by design
expect(actual.timestamp.toString()).to.eq(timestamp.toString());
expect(actual.nick).to.eq(nick);
expect(actual.payloadAsUtf8).to.eq(message);
}
)
);
});
});