Skip to content

Commit

Permalink
fix: merged maain
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman035 committed Jul 7, 2023
2 parents 2f4ad32 + 6e48314 commit 942cc65
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 14 deletions.
26 changes: 17 additions & 9 deletions packages/restapi/src/lib/chat/helpers/payloadHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const createGroupPayload = (
contractAddressERC20?: string,
numberOfERC20?: number,
meta?: string,
groupType? : string | null,
groupType?: string | null,
scheduleAt?: Date | null,
scheduleEnd?: Date | null
): ICreateGroupRequestPayload => {
Expand All @@ -196,7 +196,7 @@ export const createGroupPayload = (
meta: meta,
groupType: groupType,
scheduleAt: scheduleAt,
scheduleEnd: scheduleEnd
scheduleEnd: scheduleEnd,
};
return body;
};
Expand Down Expand Up @@ -228,7 +228,7 @@ export const groupDtoToSpaceDto = (groupDto: GroupDTO): SpaceDTO => {
spaceId: groupDto.chatId,
scheduleAt: groupDto.scheduleAt,
scheduleEnd: groupDto.scheduleEnd,
status: groupDto.status ?? null
status: groupDto.status ?? null,
};
return spaceDto;
};
Expand All @@ -243,7 +243,8 @@ export const updateGroupPayload = (
verificationProof: string,
scheduleAt?: Date | null,
scheduleEnd?: Date | null,
status?: ChatStatus | null
status?: ChatStatus | null,
meta?: string | null
): IUpdateGroupRequestPayload => {
const body = {
groupName: groupName,
Expand All @@ -255,7 +256,8 @@ export const updateGroupPayload = (
verificationProof: verificationProof,
scheduleAt: scheduleAt,
scheduleEnd: scheduleEnd,
status: status
status: status,
...(meta !== undefined && { meta: meta }),
};
return body;
};
Expand All @@ -281,7 +283,9 @@ export const getAdminsList = (
: [];

const adminsFromPendingMembers = pendingMembers
? convertToWalletAddressList(pendingMembers.filter((admin) => admin.isAdmin))
? convertToWalletAddressList(
pendingMembers.filter((admin) => admin.isAdmin)
)
: [];

const adminList = [...adminsFromMembers, ...adminsFromPendingMembers];
Expand All @@ -307,14 +311,18 @@ export const getSpaceAdminsList = (
: [];

const adminsFromPendingMembers = pendingMembers
? convertToWalletAddressList(pendingMembers.filter((admin) => admin.isSpeaker))
? convertToWalletAddressList(
pendingMembers.filter((admin) => admin.isSpeaker)
)
: [];

const adminList = [...adminsFromMembers, ...adminsFromPendingMembers];
return adminList;
};

export const convertToWalletAddressList = (memberList: { wallet: string }[]): string[] => {
export const convertToWalletAddressList = (
memberList: { wallet: string }[]
): string[] => {
return memberList ? memberList.map((member) => member.wallet) : [];
};

Expand Down Expand Up @@ -352,4 +360,4 @@ export const getSpacesMembersList = (
): Array<string> => {
const allMembers = [...(members || []), ...(pendingMembers || [])];
return convertToWalletAddressList(allMembers);
};
};
16 changes: 11 additions & 5 deletions packages/restapi/src/lib/chat/updateGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getUserDID,
getConnectedUserV2,
updateGroupRequestValidator,
validateScheduleDates
validateScheduleDates,
} from './helpers';
import * as CryptoJS from 'crypto-js';

Expand All @@ -25,9 +25,13 @@ export interface ChatUpdateGroupType extends EnvOptionsType {
members: Array<string>;
admins: Array<string>;
pgpPrivateKey?: string | null;
scheduleAt?: Date | null
scheduleEnd?: Date | null
status?: ChatStatus | null
scheduleAt?: Date | null;
scheduleEnd?: Date | null;
status?: ChatStatus | null;
// If meta is not passed, old meta is not affected
// If passed as null will update to null
// If passed as string will update to that value
meta?: string | null;
}

/**
Expand All @@ -50,6 +54,7 @@ export const updateGroup = async (
scheduleAt,
scheduleEnd,
status,
meta,
} = options || {};
try {
if (account == null && signer == null) {
Expand All @@ -66,7 +71,7 @@ export const updateGroup = async (
admins,
address
);
validateScheduleDates(scheduleAt, scheduleEnd)
validateScheduleDates(scheduleAt, scheduleEnd);

const connectedUser = await getConnectedUserV2(wallet, pgpPrivateKey, env);
const convertedMembersPromise = members.map(async (each) => {
Expand Down Expand Up @@ -105,6 +110,7 @@ export const updateGroup = async (
scheduleAt,
scheduleEnd,
status,
meta
);

return axios
Expand Down
3 changes: 3 additions & 0 deletions packages/restapi/src/lib/types/metaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const enum META_ACTION {
REMOVE_LISTENER = 10,
PROMOTE_TO_SPEAKER = 11,
DEMOTE_FROM_SPEARKER = 12,
PROMOTE_TO_COHOST = 13,
DEMOTE_FROM_COHOST = 14,
USER_INTERACTION = 15, // For MIC_ON | MIC_OFF | RAISE_HAND | EMOJI REACTION | or any other user activity
}

export type META_MESSAGE_META = {
Expand Down
148 changes: 148 additions & 0 deletions packages/restapi/tests/lib/chat/createGroup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
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 { createGroup } from '../../../src/lib/chat';
import { GroupDTO } from '../../../src/lib/types';
import {
adjectives,
animals,
colors,
uniqueNamesGenerator,
} from 'unique-names-generator';
const _env = Constants.ENV.DEV;
let account: string;
let signer: any;
let groupName: string;
let groupDescription: string;
const groupImage =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAvklEQVR4AcXBsW2FMBiF0Y8r3GQb6jeBxRauYRpo4yGQkMd4A7kg7Z/GUfSKe8703fKDkTATZsJsrr0RlZSJ9r4RLayMvLmJjnQS1d6IhJkwE2bT13U/DBzp5BN73xgRZsJMmM1HOolqb/yWiWpvjJSUiRZWopIykTATZsJs5g+1N6KSMiO1N/5DmAkzYTa9Lh6MhJkwE2ZzSZlo7xvRwson3txERzqJhJkwE2bT6+JhoKTMJ2pvjAgzYSbMfgDlXixqjH6gRgAAAABJRU5ErkJggg==';
const meta = 'Random Group Meta';

describe('Create Group', () => {
beforeEach(() => {
const WALLET1 = ethers.Wallet.createRandom();
signer = new ethers.Wallet(WALLET1.privateKey);
account = `eip155:${signer.address}`;

groupName = uniqueNamesGenerator({
dictionaries: [adjectives, colors, animals],
});
groupDescription = uniqueNamesGenerator({
dictionaries: [adjectives, colors, animals],
});
});
it('View Control - Public | Meta Property', async () => {
const admins: string[] = [];
const members = [
'eip155:0x736Cd8461132a1B52d95D535230ca4cd4C8bD7e5',
'eip155:0xDB0Bb1C25e36a5Ec9d199688bB01eADa4e70225E',
];
const group = await createGroup({
groupName,
groupDescription,
members,
groupImage,
admins,
isPublic: true,
signer,
env: _env,
meta,
});
await expectGroup(group, true, admins, members, true);
});
it('View Control - Public | Without Meta Property', async () => {
const admins: string[] = [];
const members = [
'eip155:0x736Cd8461132a1B52d95D535230ca4cd4C8bD7e5',
'eip155:0xDB0Bb1C25e36a5Ec9d199688bB01eADa4e70225E',
];
const group = await createGroup({
groupName,
groupDescription,
members,
groupImage,
admins,
isPublic: true,
signer,
env: _env,
});
await expectGroup(group, true, admins, members, false);
});
it('View Control - Private | Meta Property', async () => {
const admins: string[] = [];
const members = [
'eip155:0x736Cd8461132a1B52d95D535230ca4cd4C8bD7e5',
'eip155:0xDB0Bb1C25e36a5Ec9d199688bB01eADa4e70225E',
];
const group = await createGroup({
groupName,
groupDescription,
members,
groupImage,
admins,
isPublic: false,
signer,
env: _env,
meta,
});
await expectGroup(group, false, admins, members, true);
});
it('View Control - Private | Without Meta Property', async () => {
const admins: string[] = [];
const members = [
'eip155:0x736Cd8461132a1B52d95D535230ca4cd4C8bD7e5',
'eip155:0xDB0Bb1C25e36a5Ec9d199688bB01eADa4e70225E',
];
const group = await createGroup({
groupName,
groupDescription,
members,
groupImage,
admins,
isPublic: false,
signer,
env: _env,
});
await expectGroup(group, false, admins, members, false);
});
});

/**
* HELPER FUNCTIONS
*/
const expectGroup = async (
group: GroupDTO,
isPublic: boolean,
admins: string[],
pendingMembers: string[],
HasMeta: boolean
) => {
expect(group).to.exist;
expect(group.members).to.be.an('array');
expect(group.members.length).to.equal(1);
expect(group.members[0].wallet).to.equal(account);
expect(group.members[0].isAdmin).to.be.true;
expect(group.members[0].image).to.be.a('string');
expect(group.pendingMembers).to.be.an('array');
expect(group.pendingMembers.length).to.equal(pendingMembers.length);
expect(group.pendingMembers[0].wallet).to.equal(pendingMembers[0]);
expect(group.pendingMembers[1].wallet).to.equal(pendingMembers[1]);
expect(group.groupImage).to.equal(groupImage);
expect(group.groupName).to.equal(groupName);
expect(group.groupDescription).to.equal(groupDescription);
expect(group.isPublic).to.equal(isPublic);
expect(group.groupCreator).to.equal(account);
expect(group.chatId).to.be.a('string');
expect(group.scheduleAt).to.be.null;
expect(group.scheduleEnd).to.be.null;
expect(group.groupType).to.equal('default');
expect((group as any).status).to.be.null;
expect((group as any).eventType).to.equal('create');
if (!HasMeta) {
expect((group as any).meta).to.be.null;
} else {
expect((group as any).meta).to.equal(meta);
}
};
Loading

0 comments on commit 942cc65

Please sign in to comment.