From 728ca8ae67b5ed5c87ec3f679480f2406fe5b1dc Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Fri, 1 Dec 2023 14:22:45 +0530 Subject: [PATCH] chore: remove duplicate tests (#907) --- .../examples/sdk-backend-node/package.json | 2 +- packages/restapi/tests/lib/chat/chat.test.ts | 61 ++++++++- .../restapi/tests/lib/pushapi/chat.test.ts | 121 ------------------ 3 files changed, 59 insertions(+), 125 deletions(-) delete mode 100644 packages/restapi/tests/lib/pushapi/chat.test.ts diff --git a/packages/examples/sdk-backend-node/package.json b/packages/examples/sdk-backend-node/package.json index 772b3586e..47b5d3196 100644 --- a/packages/examples/sdk-backend-node/package.json +++ b/packages/examples/sdk-backend-node/package.json @@ -11,7 +11,7 @@ "author": "", "license": "ISC", "dependencies": { - "@pushprotocol/restapi": "0.0.1-alpha.53", + "@pushprotocol/restapi": "@latest", "@pushprotocol/socket": "^0.5.2" } } diff --git a/packages/restapi/tests/lib/chat/chat.test.ts b/packages/restapi/tests/lib/chat/chat.test.ts index c98e3e0ca..b78b1fc0a 100644 --- a/packages/restapi/tests/lib/chat/chat.test.ts +++ b/packages/restapi/tests/lib/chat/chat.test.ts @@ -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,6 +38,24 @@ 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, @@ -45,17 +63,54 @@ describe('PushAPI.chat functionality', () => { }); 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( diff --git a/packages/restapi/tests/lib/pushapi/chat.test.ts b/packages/restapi/tests/lib/pushapi/chat.test.ts deleted file mode 100644 index b78b1fc0a..000000000 --- a/packages/restapi/tests/lib/pushapi/chat.test.ts +++ /dev/null @@ -1,121 +0,0 @@ -import * as path from 'path'; -import * as dotenv from 'dotenv'; -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 CONSTANTS from '../../../src/lib/constantsV2'; - -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 WALLET2 = ethers.Wallet.createRandom(); - signer2 = new ethers.Wallet(WALLET2.privateKey); - account2 = WALLET2.address; - - 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 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: 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: CONSTANTS.CHAT.MESSAGE_TYPE.TEXT, - }); - const messagePayloads = await userAlice.chat.history(account2); - const decryptedMessagePayloads = await userBob.chat.decrypt( - messagePayloads - ); - expect(decryptedMessagePayloads).to.be.an('array'); - }); -});