Skip to content

Commit

Permalink
Dynamically loading the env from .env and add process-env.d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur12-1610 committed Apr 2, 2024
1 parent f6e0c43 commit 33345ec
Show file tree
Hide file tree
Showing 32 changed files with 200 additions and 54 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/lib/chat/initialize.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"
}
}
}
10 changes: 8 additions & 2 deletions packages/restapi/tests/lib/alias/arbitrum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,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 @@ -17,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
10 changes: 8 additions & 2 deletions packages/restapi/tests/lib/alias/berachain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,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 @@ -17,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
10 changes: 8 additions & 2 deletions packages/restapi/tests/lib/alias/optimism.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,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 @@ -17,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
14 changes: 10 additions & 4 deletions packages/restapi/tests/lib/channel/getChannelNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe('PUSH_CHANNELS.sendNotification functionality', () => {
*/
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 @@ -30,22 +36,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 @@ -54,7 +60,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
8 changes: 7 additions & 1 deletion packages/restapi/tests/lib/channel/sendNotification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ describe('PUSH_PAYLOAD.sendNotification functionality', () => {
*/
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
9 changes: 7 additions & 2 deletions packages/restapi/tests/lib/channel/subscribeV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,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 @@ -24,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 @@ -34,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
6 changes: 5 additions & 1 deletion packages/restapi/tests/lib/chat/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,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
6 changes: 5 additions & 1 deletion packages/restapi/tests/lib/chat/nftChat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
} from 'unique-names-generator';
import { PushStream } from '../../../src/lib/pushstream/PushStream';

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];

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
6 changes: 5 additions & 1 deletion packages/restapi/tests/lib/chatLowLevel/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ 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
7 changes: 6 additions & 1 deletion packages/restapi/tests/lib/chatLowLevel/createGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
colors,
uniqueNamesGenerator,
} from 'unique-names-generator';
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 account: string;
let signer: any;
let groupName: string;
Expand Down
7 changes: 6 additions & 1 deletion packages/restapi/tests/lib/chatLowLevel/send.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import {
import { CHAT } from '../../../src/lib/types/messageTypes';

chai.use(chaiAsPromised);
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('PushAPI.chat.send', () => {
const _env = Constants.ENV.DEV;
const provider = ethers.getDefaultProvider(11155111);
Expand Down
7 changes: 6 additions & 1 deletion packages/restapi/tests/lib/chatLowLevel/updateGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
colors,
uniqueNamesGenerator,
} from 'unique-names-generator';
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 account: string;
let signer: any;
let account2: string;
Expand Down
6 changes: 5 additions & 1 deletion packages/restapi/tests/lib/encryption/encryption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { expect } from 'chai';
import { ethers } from 'ethers';
import CONSTANTS from '../../../src/lib/constantsV2';

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('PushAPI.encryption functionality', () => {
let signer1: any;
let account1: string;
Expand Down
12 changes: 9 additions & 3 deletions packages/restapi/tests/lib/notification/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,19 @@ describe('PushAPI.channel functionality', () => {
*/
LOCAL = 'local',
}

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

// initialisation with signer and provider
userKate = await PushAPI.initialize(signer2, { env: ENV.DEV });
userKate = await PushAPI.initialize(signer2, { env: _env });
// initialisation with signer
userAlice = await PushAPI.initialize(signer2, { env: ENV.DEV });
userAlice = await PushAPI.initialize(signer2, { env: _env });
// TODO: remove signer1 after chat makes signer as optional
//initialisation without signer
userBob = await PushAPI.initialize(signer1, { env: ENV.DEV });
userBob = await PushAPI.initialize(signer1, { env: _env });
// initialisation with a signer that has no channel
userNoChannel = await PushAPI.initialize(noChannelSigner);
// viem signer
Expand Down
14 changes: 10 additions & 4 deletions packages/restapi/tests/lib/notification/notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,21 @@ describe('PushAPI.notification functionality', () => {
*/
LOCAL = 'local',
}

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

// initialisation with signer and provider
userKate = await PushAPI.initialize(signer2, { env: ENV.DEV });
userKate = await PushAPI.initialize(signer2, { env: _env });
// initialisation with signer
userAlice = await PushAPI.initialize(signer1, { env: ENV.DEV });
userAlice = await PushAPI.initialize(signer1, { env: _env });
// TODO: remove signer1 after signer becomes optional
// initialisation without signer
userBob = await PushAPI.initialize(signer1, { env: ENV.DEV });
userBob = await PushAPI.initialize(signer1, { env: _env });
// initialisation with viem
userViem = await PushAPI.initialize(viemSigner, { env: ENV.DEV });
userViem = await PushAPI.initialize(viemSigner, { env: _env });
});

describe('PushAPI.notification functionality', () => {
Expand Down
Loading

0 comments on commit 33345ec

Please sign in to comment.