Skip to content

Commit

Permalink
fix: fix test directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman035 committed Oct 26, 2023
1 parent 4c342a1 commit 506f588
Show file tree
Hide file tree
Showing 21 changed files with 390 additions and 91 deletions.
83 changes: 58 additions & 25 deletions packages/restapi/tests/lib/chat/chat.test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,66 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import { chat } from '../../../src/lib/chat/chat';
import { ethers } from 'ethers';

import { PushAPI } from '../../../src/lib/pushapi/PushAPI'; // Ensure correct import path
import { expect } from 'chai';
import Constants from '../../../src/lib/constants';
import { ethers } from 'ethers';
import { MessageType } from '../../../src/lib/constants';

describe('PushAPI.chat functionality', () => {
let userAlice: PushAPI;
let userBob: PushAPI;
let signer1: any;
let account1: string;
let signer2: any;
let account2: string;
const MESSAGE = 'Hey There!!!';

beforeEach(async () => {
const WALLET1 = ethers.Wallet.createRandom();
signer1 = new ethers.Wallet(WALLET1.privateKey);
account1 = WALLET1.address;

const WALLET_PRIVATE_KEY = process.env['WALLET_PRIVATE_KEY'];
const _env = Constants.ENV.DEV;
const WALLET2 = ethers.Wallet.createRandom();
signer2 = new ethers.Wallet(WALLET2.privateKey);
account2 = WALLET2.address;

describe('Get chat', () => {
it('Should return {} when not chat between users', async () => {
try {
const provider = ethers.getDefaultProvider(5);
const Pkey = `0x${WALLET_PRIVATE_KEY}`;
const _signer = new ethers.Wallet(Pkey, provider);
const walletAddress = _signer.address;
const account = `eip155:${walletAddress}`;
const inbox = await chat({
account: account,
env: _env,
toDecrypt: true,
recipient: '0xDAFEA492D9c6733ae3d56b7Ed1ADB60692c98Bc5',
});
expect(inbox).not.to.be.null;
expect(inbox).not.to.be.undefined;
expect(inbox).not.to.be.equal({});
} catch (error) {
console.log(error);
}
userAlice = await PushAPI.initialize(signer1);
userBob = await PushAPI.initialize(signer2);
});

it('Should list request ', async () => {
await userAlice.chat.send(account2, { content: MESSAGE });
const response = await userBob.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 send message ', async () => {
const response = await userAlice.chat.send(account2, {
content: 'Hello',
type: MessageType.TEXT,
});
expect(response).to.be.an('object');
});
it('Should decrypt message ', async () => {
await userAlice.chat.send(account2, {
content: 'Hello',
type: MessageType.TEXT,
});
const messagePayloads = await userAlice.chat.history(account2);
const decryptedMessagePayloads = await userBob.chat.decrypt(
messagePayloads
);
expect(decryptedMessagePayloads).to.be.an('array');
});
});
33 changes: 33 additions & 0 deletions packages/restapi/tests/lib/chatLowLevel/chat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import { chat } from '../../../src/lib/chat/chat';
import { ethers } from 'ethers';
import { expect } from 'chai';
import Constants from '../../../src/lib/constants';

const WALLET_PRIVATE_KEY = process.env['WALLET_PRIVATE_KEY'];
const _env = Constants.ENV.DEV;

describe('Get chat', () => {
it('Should return {} when not chat between users', async () => {
try {
const provider = ethers.getDefaultProvider(5);
const Pkey = `0x${WALLET_PRIVATE_KEY}`;
const _signer = new ethers.Wallet(Pkey, provider);
const walletAddress = _signer.address;
const account = `eip155:${walletAddress}`;
const inbox = await chat({
account: account,
env: _env,
toDecrypt: true,
recipient: '0xDAFEA492D9c6733ae3d56b7Ed1ADB60692c98Bc5',
});
expect(inbox).not.to.be.null;
expect(inbox).not.to.be.undefined;
expect(inbox).not.to.be.equal({});
} catch (error) {
console.log(error);
}
});
});
Loading

0 comments on commit 506f588

Please sign in to comment.