Skip to content

Commit

Permalink
fix: constant changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Nov 11, 2023
1 parent 2e3e63f commit b126ed6
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 64 deletions.
26 changes: 26 additions & 0 deletions packages/restapi/src/lib/constantsV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ENV, MessageType } from "./constants";
import { ChatListType } from "./pushapi/pushAPITypes";
import { STREAM } from "./pushstream/pushStreamTypes";
import { ConditionType, GROUP_INVITER_ROLE, GROUP_RULES_CATEGORY, GROUP_RULES_PERMISSION, GROUP_RULES_SUB_CATEGORY } from "./types";



const CONSTANTS = {
ENV: ENV,
STREAM: STREAM,
CHAT: {
LIST_TYPE: ChatListType,
MESSAGE_TYPE: MessageType,
GROUP: {
RULES: {
CONDITION_TYPE: ConditionType,
CATEGORY: GROUP_RULES_CATEGORY,
SUBCATEGORY: GROUP_RULES_SUB_CATEGORY,
PERMISSION: GROUP_RULES_PERMISSION,
INVITER_ROLE: GROUP_INVITER_ROLE,
},
},
},
};

export default CONSTANTS;
2 changes: 2 additions & 0 deletions packages/restapi/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import * as payloads from './payloads';
import * as chat from './chat';
import * as space from './space';
import * as video from "./video"
import CONSTANTS from './constantsV2';

export * from './types';
export * from './pushNotification/PushNotificationTypes';
export * from './pushstream/pushStreamTypes';
export * from './pushapi/pushAPITypes';
export { CONSTANTS };

export { PushAPI } from './pushapi/PushAPI';
export {
Expand Down
3 changes: 1 addition & 2 deletions packages/restapi/src/lib/pushNotification/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
validateCAIP,
getFallbackETHCAIPAddress,
} from '../helpers';
import PROGRESSHOOK from '../progressHook';
import { ethers } from 'ethers';


import { PushNotificationBaseClass } from './pushNotificationBase';
// ERROR CONSTANTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NotificationSettings,
UserSetting,
} from './PushNotificationTypes';
import CONFIG, * as config from '../config';
import * as config from '../config';
import { getAccountAddress } from '../chat/helpers';
import { IDENTITY_TYPE, NOTIFICATION_TYPE } from '../payloads/constants';
import { ethers, Signer, BigNumber } from 'ethers';
Expand Down
26 changes: 26 additions & 0 deletions packages/restapi/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,32 @@ export enum ConditionType {
GUILD = 'GUILD',
}

export enum GROUP_RULES_CATEGORY {
PUSH = 'PUSH',
GUILD = 'GUILD',
ERC721 = 'ERC721',
ERC20 = 'ERC20',
CUSTOM_ENDPOINT = 'CustomEndpoint',
INVITE = 'INVITE',
}

export enum GROUP_RULES_SUB_CATEGORY {
DEFAULT = 'DEFAULT',
HOLDER = 'holder',
GET = 'GET',
}


export enum GROUP_RULES_PERMISSION {
ENTRY = 'Entry',
CHAT = 'Chat',
}

export enum GROUP_INVITER_ROLE {
ADMIN = 'ADMIN',
OWNER = 'OWNER',
}

export type Data = {
contract?: string;
amount?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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 Constants from '../../../src/lib/constants';
import { ethers } from 'ethers';

describe('PUSH_PAYLOAD.sendNotification functionality', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/restapi/tests/lib/channel/subscribeV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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 Constants from '../../../src/lib/constants';
import { ethers } from 'ethers';
import CONSTANTS from '../../../src/lib/constantsV2';

describe('PUSH_CHANNEL.subscribeV2 functionality', () => {
let signer1: any;
Expand All @@ -27,7 +27,7 @@ describe('PUSH_CHANNEL.subscribeV2 functionality', () => {
signer: signer1,
channelAddress: 'eip155:5:0xD8634C39BBFd4033c0d3289C4515275102423681',
userAddress: `eip155:5:${account1}`,
env: Constants.ENV.STAGING,
env: CONSTANTS.ENV.STAGING,
});
expect(res.status).to.be.equal('success');
});
Expand All @@ -37,7 +37,7 @@ describe('PUSH_CHANNEL.subscribeV2 functionality', () => {
signer: signer1,
channelAddress: 'eip155:5:0xD8634C39BBFd4033c0d3289C4515275102423681',
userAddress: `eip155:5:${account1}`,
env: Constants.ENV.STAGING,
env: CONSTANTS.ENV.STAGING,
});
console.log(res)
expect(res.status).to.be.equal('success');
Expand All @@ -48,7 +48,7 @@ describe('PUSH_CHANNEL.subscribeV2 functionality', () => {
signer: signer1,
channelAddress: 'eip155:5:0xD8634C39BBFd4033c0d3289C4515275102423681',
userAddress: `eip155:5:${account1}`,
env: Constants.ENV.STAGING,
env: CONSTANTS.ENV.STAGING,
userSetting: '2-1-0+2-1',
});
expect(res.status).to.be.equal('success');
Expand Down
4 changes: 2 additions & 2 deletions packages/restapi/tests/lib/chat/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ 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';
import CONSTANTS from '../../../src/lib/constantsV2';

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

describe('Get chat', () => {
it('Should return {} when not chat between users', async () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/restapi/tests/lib/chat/createGroup.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as chai from 'chai';
import { expect } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import { ethers } from 'ethers';
import Constants from '../../../src/lib/constants';
import CONSTANTS from '../../../src/lib/constantsV2';
import { createGroup } from '../../../src/lib/chat';
import { GroupDTO } from '../../../src/lib/types';
import {
Expand All @@ -11,7 +9,7 @@ import {
colors,
uniqueNamesGenerator,
} from 'unique-names-generator';
const _env = Constants.ENV.DEV;
const _env = CONSTANTS.ENV.DEV;
let account: string;
let signer: any;
let groupName: string;
Expand Down
6 changes: 2 additions & 4 deletions packages/restapi/tests/lib/chat/updateGroup.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as chai from 'chai';
import { expect } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import { ethers } from 'ethers';
import Constants from '../../../src/lib/constants';
import CONSTANTS from '../../../src/lib/constantsV2';
import { createGroup, updateGroup, removeMembers } from '../../../src/lib/chat';
import { GroupDTO } from '../../../src/lib/types';
import {
Expand All @@ -11,7 +9,7 @@ import {
colors,
uniqueNamesGenerator,
} from 'unique-names-generator';
const _env = Constants.ENV.DEV;
const _env = CONSTANTS.ENV.DEV;
let account: string;
let signer: any;
let account2: string;
Expand Down
4 changes: 3 additions & 1 deletion packages/restapi/tests/lib/progressHook/progressHook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as chaiAsPromised from 'chai-as-promised';
import { create, decryptAuth, get } from '../../../src/lib/user';
import { ethers } from 'ethers';
import Constants, { ENCRYPTION_TYPE } from '../../../src/lib/constants';
import CONSTANTS from '../../../src/lib/constantsV2';

import { ProgressHookType, ProgressHookTypeFunction } from '../../../src';
chai.use(chaiAsPromised);
import PROGRESSHOOK from './progressHookData';
Expand All @@ -15,7 +17,7 @@ import { profileUpdate } from '../../../src/lib/user/profile.updateUser';
import { authUpdate } from '../../../src/lib/user/auth.updateUser';

describe('ProgressHook Tests', () => {
const _env = Constants.ENV.DEV;
const _env = CONSTANTS.ENV.DEV;
let provider = ethers.getDefaultProvider(5);
let _signer: any;
let walletAddress: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/restapi/tests/lib/pushapi/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,14 +48,14 @@ describe('PushAPI.chat functionality', () => {
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 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(
Expand Down
86 changes: 49 additions & 37 deletions packages/restapi/tests/lib/pushstream/initialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { ethers } from 'ethers';
import { PushAPI } from '../../../src/lib/pushapi/PushAPI';
import { sendNotification } from '../../../src/lib/payloads/sendNotifications';
import { subscribe, unsubscribe } from '../../../src/lib/channels';
import CONSTANTS from '../../../src/lib/constantsV2';

import { ENV } from '../../../src/lib/constants';
import { STREAM } from '../../../src/lib/pushstream/pushStreamTypes';
import * as util from 'util';
import { ConditionType } from '../../../src/lib';

describe.only('PushStream.initialize functionality', () => {
describe('PushStream.initialize functionality', () => {
it('Should initialize new stream and listen to events', async () => {
const MESSAGE = 'Hey There!!!';

Expand All @@ -21,25 +19,25 @@ describe.only('PushStream.initialize functionality', () => {
const WALLET = ethers.Wallet.createRandom();
const signer = new ethers.Wallet(WALLET.privateKey, provider);
const user = await PushAPI.initialize(signer, {
env: ENV.LOCAL,
env: CONSTANTS.ENV.LOCAL,
});

const WALLET2 = ethers.Wallet.createRandom();
const signer2 = new ethers.Wallet(WALLET2.privateKey, provider);
const user2 = await PushAPI.initialize(signer2, {
env: ENV.LOCAL,
env: CONSTANTS.ENV.LOCAL,
});

const WALLET3 = ethers.Wallet.createRandom();
const signer3 = new ethers.Wallet(WALLET3.privateKey, provider);
const user3 = await PushAPI.initialize(signer3, {
env: ENV.LOCAL,
env: CONSTANTS.ENV.LOCAL,
});

const WALLET4 = ethers.Wallet.createRandom();
const signer4 = new ethers.Wallet(WALLET4.privateKey, provider);
const user4 = await PushAPI.initialize(signer4, {
env: ENV.LOCAL,
env: CONSTANTS.ENV.LOCAL,
});

const GROUP_RULES = {
Expand All @@ -48,9 +46,9 @@ describe.only('PushStream.initialize functionality', () => {
{
any: [
{
type: 'PUSH',
category: 'CustomEndpoint',
subcategory: 'GET',
type: CONSTANTS.CHAT.GROUP.RULES.CONDITION_TYPE.PUSH,
category: CONSTANTS.CHAT.GROUP.RULES.CATEGORY.CUSTOM_ENDPOINT,
subcategory: CONSTANTS.CHAT.GROUP.RULES.SUBCATEGORY.GET,
data: {
url: 'https://api.ud-staging.com/profile/badges/dead_pixel/validate/{{user_address}}?rule=join',
},
Expand All @@ -64,9 +62,9 @@ describe.only('PushStream.initialize functionality', () => {
{
any: [
{
type: 'PUSH',
category: 'CustomEndpoint',
subcategory: 'GET',
type: CONSTANTS.CHAT.GROUP.RULES.CONDITION_TYPE.PUSH,
category: CONSTANTS.CHAT.GROUP.RULES.CATEGORY.CUSTOM_ENDPOINT,
subcategory: CONSTANTS.CHAT.GROUP.RULES.SUBCATEGORY.GET,
data: {
url: 'https://api.ud-staging.com/profile/badges/dead_pixel/validate/{{user_address}}?rule=chat',
},
Expand All @@ -88,9 +86,9 @@ describe.only('PushStream.initialize functionality', () => {
conditions: {
any: [
{
type: ConditionType.PUSH,
category: 'ERC20',
subcategory: 'holder',
type: CONSTANTS.CHAT.GROUP.RULES.CONDITION_TYPE.PUSH,
category: CONSTANTS.CHAT.GROUP.RULES.CATEGORY.ERC20,
subcategory: CONSTANTS.CHAT.GROUP.RULES.SUBCATEGORY.HOLDER,
data: {
contract:
'eip155:1:0xf418588522d5dd018b425E472991E52EBBeEEEEE',
Expand All @@ -99,11 +97,14 @@ describe.only('PushStream.initialize functionality', () => {
},
},
{
type: ConditionType.PUSH,
category: 'INVITE',
subcategory: 'DEFAULT',
type: CONSTANTS.CHAT.GROUP.RULES.CONDITION_TYPE.PUSH,
category: CONSTANTS.CHAT.GROUP.RULES.CATEGORY.INVITE,
subcategory: CONSTANTS.CHAT.GROUP.RULES.SUBCATEGORY.DEFAULT,
data: {
inviterRoles: ['ADMIN', 'OWNER'],
inviterRoles: [
CONSTANTS.CHAT.GROUP.RULES.INVITER_ROLE.ADMIN,
CONSTANTS.CHAT.GROUP.RULES.INVITER_ROLE.OWNER,
],
},
},
],
Expand All @@ -121,20 +122,23 @@ describe.only('PushStream.initialize functionality', () => {
rules: {},
};

const stream = await user.stream([STREAM.CHAT, STREAM.CHAT_OPS], {
// stream supports other products as well, such as STREAM.CHAT, STREAM.CHAT_OPS
// more info can be found at push.org/docs/chat
const stream = await user.stream(
[CONSTANTS.STREAM.CHAT, CONSTANTS.STREAM.CHAT_OPS],
{
// stream supports other products as well, such as STREAM.CHAT, STREAM.CHAT_OPS
// more info can be found at push.org/docs/chat

filter: {
channels: ['*'],
chats: ['*'],
},
connection: {
auto: false, // should connection be automatic, else need to call stream.connect();
retries: 3, // number of retries in case of error
},
raw: true, // enable true to show all data
});
filter: {
channels: ['*'],
chats: ['*'],
},
connection: {
auto: false, // should connection be automatic, else need to call stream.connect();
retries: 3, // number of retries in case of error
},
raw: true, // enable true to show all data
}
);

await stream.connect();

Expand Down Expand Up @@ -178,11 +182,19 @@ describe.only('PushStream.initialize functionality', () => {
// leave admin bug
// group creator check remove add

const onDataReceived = createEventPromise('CHAT_OPS', STREAM.CHAT_OPS, 5);
const onMessageReceived = createEventPromise('CHAT', STREAM.CHAT, 4);
const onDataReceived = createEventPromise(
'CHAT_OPS',
CONSTANTS.STREAM.CHAT_OPS,
5
);
const onMessageReceived = createEventPromise(
'CHAT',
CONSTANTS.STREAM.CHAT,
4
);
const onNoitificationsReceived = createEventPromise(
'NOTIF',
STREAM.NOTIF,
CONSTANTS.STREAM.NOTIF,
4
);

Expand Down
Loading

0 comments on commit b126ed6

Please sign in to comment.