logos-messaging-js/packages/tests/tests/light-push/custom_pubsub.node.spec.ts
fbarbu15 e284c78701
chore: new lightpush tests (#1571)
* new lightpush tests

* fixes after CI run

* split tests into 2 files

* small fix

* address code review comments

* small fix after CI run

---------

Co-authored-by: Danish Arora <35004822+danisharora099@users.noreply.github.com>
2023-09-19 15:51:03 +05:30

50 lines
1.3 KiB
TypeScript

import { LightNode } from "@waku/interfaces";
import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai";
import { MessageCollector, NimGoNode, tearDownNodes } from "../../src/index.js";
import {
messageText,
runNodes,
TestContentTopic,
TestEncoder
} from "./utils.js";
describe("Waku Light Push [node only] - custom pubsub topic", function () {
this.timeout(15000);
let waku: LightNode;
let nwaku: NimGoNode;
let messageCollector: MessageCollector;
const customPubSubTopic = "/waku/2/custom-dapp/proto";
beforeEach(async function () {
[nwaku, waku] = await runNodes(this, customPubSubTopic);
messageCollector = new MessageCollector(
TestContentTopic,
nwaku,
customPubSubTopic
);
});
this.afterEach(async function () {
tearDownNodes([nwaku], [waku]);
});
it("Push message", async function () {
const nimPeerId = await nwaku.getPeerId();
const pushResponse = await waku.lightPush.send(TestEncoder, {
payload: utf8ToBytes(messageText)
});
expect(pushResponse.recipients[0].toString()).to.eq(nimPeerId.toString());
expect(await messageCollector.waitForMessages(1)).to.eq(true);
messageCollector.verifyReceivedMessage(0, {
expectedMessageText: messageText,
expectedContentTopic: TestContentTopic
});
});
});