Skip to content

Commit

Permalink
fix: fix testcases to take push node environment from .env rather tha… (
Browse files Browse the repository at this point in the history
#1196)

* fix: fix testcases to take push node environment from .env rather than defining at each file

* Dynamically loading the env from .env, add process-env.d.ts and remove redundant declarations of ENV
  • Loading branch information
ankur12-1610 authored Apr 5, 2024
1 parent 985c422 commit 7a4bd8d
Show file tree
Hide file tree
Showing 38 changed files with 210 additions and 190 deletions.
4 changes: 2 additions & 2 deletions packages/restapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"viem": "^1.20.3"
},
"scripts": {
"test": "TS_NODE_PROJECT='./tsconfig.mocha.json' NODE_OPTIONS='--loader ts-node/esm' mocha -r ts-node/register 'tests/**/*.test.ts' --timeout 1200000 --require tests/root.ts --serial"
"test": "TS_NODE_PROJECT='./tsconfig.mocha.json' NODE_OPTIONS='--loader ts-node/esm' DOTENV_CONFIG_PATH='./tests/.env' mocha -r ts-node/register -r dotenv/config 'tests/**/*.test.ts' --timeout 1200000 --require tests/root.ts --serial"
},
"devDependencies": {
"@types/chai": "^4.3.4",
Expand All @@ -43,4 +43,4 @@
"ts-node": "^10.9.1",
"typescript": "^5.0.2"
}
}
}
13 changes: 8 additions & 5 deletions packages/restapi/tests/lib/alias/arbitrum.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import { ethers } from 'ethers';
import { PushAPI } from '../../../src';
import { ENV } from '../../../src/lib/constants';
Expand All @@ -10,6 +7,12 @@ describe('ARBITRUM ALIAS functionality', () => {
let userBob: PushAPI;
let account: string;
let account2: string;

// accessing env dynamically using process.env
type EnvStrings = keyof typeof ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = ENV[envMode];

before(async () => {
const provider = new ethers.providers.JsonRpcProvider(
'https://sepolia-rollup.arbitrum.io/rpc'
Expand All @@ -20,12 +23,12 @@ describe('ARBITRUM ALIAS functionality', () => {
);
account = signer.address;
userAlice = await PushAPI.initialize(signer, {
env: ENV.DEV,
env: _env,
});

const signer2 = new ethers.Wallet(ethers.Wallet.createRandom().privateKey);
account2 = signer2.address;
userBob = await PushAPI.initialize(signer2, { env: ENV.DEV });
userBob = await PushAPI.initialize(signer2, { env: _env });
});

it.skip('Should be able to create channel', async () => {
Expand Down
13 changes: 8 additions & 5 deletions packages/restapi/tests/lib/alias/berachain.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import { ethers } from 'ethers';
import { PushAPI } from '../../../src';
import { ENV } from '../../../src/lib/constants';
Expand All @@ -10,6 +7,12 @@ describe('BERACHAIN ALIAS functionality', () => {
let userBob: PushAPI;
let account: string;
let account2: string;

// accessing env dynamically using process.env
type EnvStrings = keyof typeof ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = ENV[envMode];

before(async () => {
const provider = new ethers.providers.JsonRpcProvider(
'https://artio.rpc.berachain.com' // berachain artio Provider
Expand All @@ -20,12 +23,12 @@ describe('BERACHAIN ALIAS functionality', () => {
);
account = signer.address;
userAlice = await PushAPI.initialize(signer, {
env: ENV.DEV,
env: _env,
});

const signer2 = new ethers.Wallet(ethers.Wallet.createRandom().privateKey);
account2 = signer2.address;
userBob = await PushAPI.initialize(signer2, { env: ENV.DEV });
userBob = await PushAPI.initialize(signer2, { env: _env });
});

it.skip('Should be able to create channel', async () => {
Expand Down
13 changes: 8 additions & 5 deletions packages/restapi/tests/lib/alias/optimism.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import { ethers } from 'ethers';
import { PushAPI } from '../../../src';
import { ENV } from '../../../src/lib/constants';
Expand All @@ -10,6 +7,12 @@ describe('OPTIMISM ALIAS functionality', () => {
let userBob: PushAPI;
let account: string;
let account2: string;

// accessing env dynamically using process.env
type EnvStrings = keyof typeof ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = ENV[envMode];

before(async () => {
const provider = new ethers.providers.JsonRpcProvider(
'https://sepolia.optimism.io'
Expand All @@ -20,12 +23,12 @@ describe('OPTIMISM ALIAS functionality', () => {
);
account = signer.address;
userAlice = await PushAPI.initialize(signer, {
env: ENV.DEV,
env: _env,
});

const signer2 = new ethers.Wallet(ethers.Wallet.createRandom().privateKey);
account2 = signer2.address;
userBob = await PushAPI.initialize(signer2, { env: ENV.DEV });
userBob = await PushAPI.initialize(signer2, { env: _env });
});

it.skip('Should be able to create channel', async () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/restapi/tests/lib/benchmark/chatMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { ethers } from 'ethers';
import Constants from '../../../src/lib/constants';
import { PushAPI } from '../../../src/lib/pushapi/PushAPI';

const _env = Constants.ENV.PROD;
// accessing env dynamically using process.env
type EnvStrings = keyof typeof Constants.ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = Constants.ENV[envMode];

/**
* THIS TEST GROUP IS FOR BENCHMARKING CHAT PERFORMANCE
Expand Down
5 changes: 4 additions & 1 deletion packages/restapi/tests/lib/benchmark/privateGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import Constants from '../../../src/lib/constants';
import { PushAPI } from '../../../src/lib/pushapi/PushAPI';
import { users } from './data/did';

const _env = Constants.ENV.LOCAL;
// accessing env dynamically using process.env
type EnvStrings = keyof typeof Constants.ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = Constants.ENV[envMode];

/**
* THIS TEST GROUP IS FOR BENCHMARKING PUBLIC GROUP
Expand Down
5 changes: 4 additions & 1 deletion packages/restapi/tests/lib/benchmark/publicGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import Constants from '../../../src/lib/constants';
import { PushAPI } from '../../../src/lib/pushapi/PushAPI';
import { users } from './data/did';

const _env = Constants.ENV.LOCAL;
// accessing env dynamically using process.env
type EnvStrings = keyof typeof Constants.ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = Constants.ENV[envMode];

/**
* THIS TEST GROUP IS FOR BENCHMARKING PUBLIC GROUP
Expand Down
27 changes: 11 additions & 16 deletions packages/restapi/tests/lib/channel/getChannelNotifications.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import * as PUSH_CHANNELS from '../../../src/lib/channels';
import { expect } from 'chai';
import { ethers } from 'ethers';
import { ENV } from '../../../src/lib/constants';

describe('PUSH_CHANNELS.sendNotification functionality', () => {
let signer1: any;
let account1: string;
let signer2: any;
let account2: string;
enum ENV {
PROD = 'prod',
STAGING = 'staging',
DEV = 'dev',
/**
* **This is for local development only**
*/
LOCAL = 'local',
}

// accessing env dynamically using process.env
type EnvStrings = keyof typeof ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = ENV[envMode];

beforeEach(async () => {
signer1 = new ethers.Wallet(
'0xb9d00f786e1d024cfed08f696a775217ff75501f4aacef5ec0795fc4a2eb9df1'
Expand All @@ -33,22 +28,22 @@ describe('PUSH_CHANNELS.sendNotification functionality', () => {
it('Should fetch notifications of a channel', async () => {
const res = await PUSH_CHANNELS.getChannelNotifications({
channel: '0xD8634C39BBFd4033c0d3289C4515275102423681',
env: ENV.DEV,
env: _env,
});
console.log(res);
});
it('Should should fetch notifications of a channel based on filter', async () => {
const res = await PUSH_CHANNELS.getChannelNotifications({
channel: '0xD8634C39BBFd4033c0d3289C4515275102423681',
env: ENV.DEV,
env: _env,
filter: 1,
});
console.log(res);
});
it('Should should fetch notifications of a channel based on filter and in standard format', async () => {
const res = await PUSH_CHANNELS.getChannelNotifications({
channel: '0xD8634C39BBFd4033c0d3289C4515275102423681',
env: ENV.DEV,
env: _env,
filter: 1,
raw: false,
});
Expand All @@ -57,7 +52,7 @@ describe('PUSH_CHANNELS.sendNotification functionality', () => {
it('Should should fetch notifications of a channel based on filter and in standard format', async () => {
const res = await PUSH_CHANNELS.getChannelNotifications({
channel: '0xD8634C39BBFd4033c0d3289C4515275102423681',
env: ENV.DEV,
env: _env,
filter: 1,
raw: false,
page: 1,
Expand Down
20 changes: 7 additions & 13 deletions packages/restapi/tests/lib/channel/sendNotification.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import * as PUSH_PAYLOAD from '../../../src/lib/payloads';
import { expect } from 'chai';
import { ethers } from 'ethers';
import { ENV } from '../../../src/lib/constants';

describe('PUSH_PAYLOAD.sendNotification functionality', () => {
let signer1: any;
Expand Down Expand Up @@ -36,17 +34,13 @@ describe('PUSH_PAYLOAD.sendNotification functionality', () => {
SUBSET = 4,
}

enum ENV {
PROD = 'prod',
STAGING = 'staging',
DEV = 'dev',
/**
* **This is for local development only**
*/
LOCAL = 'local',
}
// accessing env dynamically using process.env
type EnvStrings = keyof typeof ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = ENV[envMode];

const res = await PUSH_PAYLOAD.sendNotification({
env: ENV.DEV,
env: _env,
signer: signer1,
type: NOTIFICATION_TYPE.BROADCAST,
identityType: IDENTITY_TYPE.DIRECT_PAYLOAD,
Expand Down
12 changes: 7 additions & 5 deletions packages/restapi/tests/lib/channel/subscribeV2.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import * as PUSH_CHANNEL from '../../../src/lib/channels/';
import { expect } from 'chai';
import { ethers } from 'ethers';
Expand All @@ -12,6 +9,11 @@ describe('PUSH_CHANNEL.subscribeV2 functionality', () => {
let signer2: any;
let account2: string;

// accessing env dynamically using process.env
type EnvStrings = keyof typeof CONSTANTS.ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = CONSTANTS.ENV[envMode];

beforeEach(async () => {
const WALLET1 = ethers.Wallet.createRandom();
signer1 = new ethers.Wallet(WALLET1.privateKey);
Expand All @@ -27,7 +29,7 @@ describe('PUSH_CHANNEL.subscribeV2 functionality', () => {
signer: signer1,
channelAddress: 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681',
userAddress: `eip155:11155111:${account1}`,
env: CONSTANTS.ENV.STAGING,
env: _env,
});
expect(res.status).to.be.equal(204);
});
Expand All @@ -37,7 +39,7 @@ describe('PUSH_CHANNEL.subscribeV2 functionality', () => {
signer: signer1,
channelAddress: 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681',
userAddress: `eip155:11155111:${account1}`,
env: CONSTANTS.ENV.STAGING,
env: _env,
});
// console.log(res)
expect(res.status).to.be.equal(204);
Expand Down
6 changes: 5 additions & 1 deletion packages/restapi/tests/lib/chat/chat.group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
} from 'unique-names-generator';
import { PushAPI } from '../../../src/lib/pushapi/PushAPI'; // Ensure correct import path

const _env = Constants.ENV.DEV;
// accessing env dynamically using process.env
type EnvStrings = keyof typeof Constants.ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = Constants.ENV[envMode];

let groupName: string;
let groupDescription: string;
const groupImage =
Expand Down
10 changes: 5 additions & 5 deletions packages/restapi/tests/lib/chat/chat.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
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';
Expand All @@ -16,7 +12,11 @@ describe('PushAPI.chat functionality', () => {
let signer2: any;
let account2: string;
const MESSAGE = 'Hey There!!!';
const env = CONSTANTS.ENV.DEV;

// accessing env dynamically using process.env
type EnvStrings = keyof typeof CONSTANTS.ENV;
const envMode = process.env.ENV as EnvStrings;
const env = CONSTANTS.ENV[envMode];

beforeEach(async () => {
const WALLET1 = ethers.Wallet.createRandom();
Expand Down
3 changes: 0 additions & 3 deletions packages/restapi/tests/lib/chat/initialize.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import { ProgressHookType } from '../../../src/lib/types';
import { PushAPI } from '../../../src/lib/pushapi/PushAPI'; // Ensure correct import path
import { expect } from 'chai';
Expand Down
8 changes: 4 additions & 4 deletions packages/restapi/tests/lib/chat/nftChat.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
import { PushAPI } from '../../../src/lib/pushapi/PushAPI';
import { ethers } from 'ethers';
import CONSTANTS from '../../../src/lib/constantsV2';
Expand All @@ -11,9 +9,11 @@ import {
} from 'unique-names-generator';
import { PushStream } from '../../../src/lib/pushstream/PushStream';

dotenv.config({ path: path.resolve(__dirname, '../../.env') });
// accessing env dynamically using process.env
type EnvStrings = keyof typeof CONSTANTS.ENV;
const envMode = process.env.ENV as EnvStrings;
const env = CONSTANTS.ENV[envMode];

const env = CONSTANTS.ENV.DEV;
const showAPIResponse = false;

describe('PushAPI.chat functionality For NFT Profile', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/restapi/tests/lib/chat/privateGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { PushAPI } from '../../../src/lib/pushapi/PushAPI'; // Ensure correct im
import { GroupDTO, GroupInfoDTO, MessageWithCID } from '../../../src/lib/types';
import { cache } from '../../../src/lib/helpers/cache';

const _env = Constants.ENV.DEV;
// accessing env dynamically using process.env
type EnvStrings = keyof typeof Constants.ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = Constants.ENV[envMode];

let groupName: string;
let groupDescription: string;
const groupImage =
Expand Down
4 changes: 0 additions & 4 deletions packages/restapi/tests/lib/chat/profile.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
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';
Expand Down
9 changes: 5 additions & 4 deletions packages/restapi/tests/lib/chatLowLevel/chat.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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;

// accessing env dynamically using process.env
type EnvStrings = keyof typeof Constants.ENV;
const envMode = process.env.ENV as EnvStrings;
const _env = Constants.ENV[envMode];

describe('Get chat', () => {
it('Should return {} when not chat between users', async () => {
Expand Down
Loading

0 comments on commit 7a4bd8d

Please sign in to comment.