-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
390 additions
and
91 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.