Skip to content

Commit

Permalink
fix: Merge branch 'main' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Aug 10, 2023
2 parents 0142fb7 + 5e9b0b9 commit 2af8d12
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ const CreateGroupTest = () => {
setLoading(true);
const librarySigner = await library.getSigner();
// Remove empty string elements

const response = await PushAPI.chat.createGroup({
groupName,
groupDescription,
members: members.split(','),
members: members ? members.split(',') : [],
groupImage,
admins: admins.split(','),
admins: admins ? admins.split(',') : [],
isPublic: isPublic === 'true',
contractAddressNFT,
numberOfNFTs: numberOfNFTs != null ? Number(numberOfNFTs) : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const UpdateGroupTest = () => {
groupName,
groupImage,
groupDescription,
members: members.split(','),
admins: admins.split(','),
members: members ? members.split(',') : [],
admins: admins ? admins.split(',') : [],
account: isCAIP ? walletToPCAIP10(account) : account,
signer: librarySigner,
env,
Expand Down
3 changes: 3 additions & 0 deletions packages/restapi/src/lib/chat/getGroupByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export const getGroupByName = async (
): Promise<GroupDTO> => {
const { groupName, env = Constants.ENV.PROD } = options || {};
try {
console.log("=============================================");
console.log("NOTICE: The method 'getGroupByName' will be deprecated on January 1st, 2024. Please update your code to remove this.");
console.log("=============================================");
if (groupName == null || groupName.length == 0) {
throw new Error(`Group Name cannot be null or empty`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/chat/helpers/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const createGroupRequestValidator = (
}

if (admins == null) {
throw new Error(`admins cannot be null`);
throw new Error(`admins cannot be null`);
}

for (let i = 0; i < admins.length; i++) {
Expand Down
52 changes: 52 additions & 0 deletions packages/restapi/src/lib/user/createUserWithProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { create } from './createUser';
import { IUser, ProgressHookType, SignerType } from '../types';
import { profileUpdate } from './profile.updateUser';
import { decryptPGPKey } from '../../../src/lib/helpers';
import Constants, { ENV } from '../constants';

export type CreateUserPropsWithProfile = {
env?: ENV;
account?: string;
signer?: SignerType;
version?: typeof Constants.ENC_TYPE_V1 | typeof Constants.ENC_TYPE_V3;
additionalMeta?: {
NFTPGP_V1?: {
password: string;
};
};
profile?: {
name?: string;
desc?: string;
picture?: string;
blockedUsersList?: Array<string>;
};
progressHook?: (progress: ProgressHookType) => void;
};

export const createUserWithProfile = async (
userOptions: CreateUserPropsWithProfile
): Promise<IUser> => {
try {
let user = await create(userOptions);

if (userOptions.profile) {
const pk = await decryptPGPKey({
account: user.did,
encryptedPGPPrivateKey: user.encryptedPrivateKey,
env: userOptions.env,
signer: userOptions.signer,
});


user = await profileUpdate({
account: user.did,
env: userOptions.env,
pgpPrivateKey: pk,
profile: userOptions.profile
});
}
return user;
} catch (err) {
throw new Error(`[Push SDK] - Error in createUserWithProfile -: ${err}`);
}
};
1 change: 1 addition & 0 deletions packages/restapi/src/lib/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './getDelegations';
export * from './getUsersBatch';
export * from './upgradeUser';
export * from './decryptAuth';
export * from './createUserWithProfile';
export const auth = {
update: authUpdate,
};
Expand Down
60 changes: 60 additions & 0 deletions packages/restapi/tests/lib/user/createUserWithProfile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import * as chai from 'chai';
import { expect } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import { createUserWithProfile } from '../../../src/lib/user';
import { ethers } from 'ethers';
import Constants from '../../../src/lib/constants';
chai.use(chaiAsPromised);

describe('Create Push Profile with Profile update', () => {
const _env = Constants.ENV.DEV;
let provider = ethers.getDefaultProvider(5);
let _signer: any;
let walletAddress: string;
let account: string;


beforeEach(() => {
provider = ethers.getDefaultProvider(5);
const WALLET = ethers.Wallet.createRandom();
_signer = new ethers.Wallet(WALLET.privateKey, provider);
walletAddress = _signer.address;
account = `eip155:${walletAddress}`;
});


it('Push Profile V3', async () => {
const name = 'John';
const desc = 'He is web3 dev'
const picture = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAvUlEQVR4AcXBsa3CMBiF0Y+rFNarM0Jqi1EoU2QIj+IxPACTuGYEBnAH7Q+FI/SKe87lflxfGAkzYSbMFr7kMoh6TUTb2ph5PHeiXAZRr4lImAkzYbbkMoh6TUTb2vjFtjaiXneiXAaRMBNmwmzhxN9xI+o1MZPL4ENNzAgzYSbMFk70mohyGcz0mviFMBNmwmzhxLY2Pt2Y2dZG9HjuzAgzYSbMLvfj+mIil8F/9JqYEWbCTJgJM2EmzITZG0wkJb/EapQdAAAAAElFTkSuQmCC',
const user = await createUserWithProfile({
account: account,
env: _env,
signer: _signer,
profile: {
name: name,
desc: desc,
picture: picture,
},
});
console.log(user)
expect(user).to.be.an('object');
expect(user).not.to.be.null;
expect(user).not.to.be.undefined;
expect(user.did).to.be.equal(account);
expect(user.wallets).to.be.equal(account);
expect(user.publicKey).to.contains(
'-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n'
);
expect(user.encryptedPrivateKey).to.contains(
`"version":"${Constants.ENC_TYPE_V3}"`
);
expect(user.profile.name).to.be.equal(name);
expect(user.profile.desc).to.be.equal(desc);
expect(user.profile.picture).to.be.equal(picture);;
expect(user.msgSent).to.be.equal(0);
});
});

0 comments on commit 2af8d12

Please sign in to comment.