Skip to content

Commit

Permalink
Showing 3 changed files with 59 additions and 125 deletions.
2 changes: 1 addition & 1 deletion packages/examples/sdk-backend-node/package.json
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@pushprotocol/restapi": "0.0.1-alpha.53",
"@pushprotocol/restapi": "@latest",
"@pushprotocol/socket": "^0.5.2"
}
}
61 changes: 58 additions & 3 deletions packages/restapi/tests/lib/chat/chat.test.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import { PushAPI } from '../../../src/lib/pushapi/PushAPI'; // Ensure correct import path
import { expect } from 'chai';
import { ethers } from 'ethers';
import { MessageType } from '../../../src/lib/constants';
import CONSTANTS from '../../../src/lib/constantsV2';

describe('PushAPI.chat functionality', () => {
let userAlice: PushAPI;
@@ -38,24 +38,79 @@ describe('PushAPI.chat functionality', () => {
expect(response).to.be.an('array');
expect(response.length).to.equal(1);
});

it('Should list request read only', async () => {
await userAlice.chat.send(account2, { content: MESSAGE });

const account = (await userBob.info()).did;

const userBobReadOnly = await PushAPI.initialize({
account: account,
});

const response = await userBobReadOnly.chat.list('REQUESTS', {
page: 1,
limit: 10,
});
expect(response).to.be.an('array');
expect(response.length).to.equal(1);
});

it('Should list chats ', async () => {
const response = await userAlice.chat.list('CHATS', {
page: 1,
limit: 10,
});
expect(response).to.be.an('array');
});
it('Should list chats read only', async () => {
const account = (await userAlice.info()).did;

const userAliceReadOnly = await PushAPI.initialize({
account: account,
});

const response = await userAliceReadOnly.chat.list('CHATS', {
page: 1,
limit: 10,
});
expect(response).to.be.an('array');
});
it('Should send message ', async () => {
const response = await userAlice.chat.send(account2, {
content: 'Hello',
type: MessageType.TEXT,
type: CONSTANTS.CHAT.MESSAGE_TYPE.TEXT,
});
expect(response).to.be.an('object');
});
it('Should send message read only', async () => {
const account = (await userAlice.info()).did;

const userAliceReadOnly = await PushAPI.initialize({
account: account,
});

let errorCaught: any = null;

try {
await userAliceReadOnly.chat.send(account2, {
content: 'Hello',
type: CONSTANTS.CHAT.MESSAGE_TYPE.TEXT,
});
} catch (error) {
errorCaught = error;
}

expect(errorCaught).to.be.an('error');
expect(errorCaught.message).to.equal(
'Operation not allowed in read-only mode. Signer is required.'
);
});

it('Should decrypt message ', async () => {
await userAlice.chat.send(account2, {
content: 'Hello',
type: MessageType.TEXT,
type: CONSTANTS.CHAT.MESSAGE_TYPE.TEXT,
});
const messagePayloads = await userAlice.chat.history(account2);
const decryptedMessagePayloads = await userBob.chat.decrypt(
121 changes: 0 additions & 121 deletions packages/restapi/tests/lib/pushapi/chat.test.ts

This file was deleted.

0 comments on commit 728ca8a

Please sign in to comment.