diff --git a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts index f8d9febd8..dcc4dbf74 100644 --- a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts +++ b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts @@ -36,7 +36,7 @@ export enum FeedType { export type FeedsOptions = { account?: string; //TODO: change it to string[] once we start supporting multiple channel - channels?: [string]; + channels?: string[]; page?: number; limit?: number; raw?: boolean; diff --git a/packages/restapi/src/lib/pushNotification/notification.ts b/packages/restapi/src/lib/pushNotification/notification.ts index 35fd339f8..9420a68ca 100644 --- a/packages/restapi/src/lib/pushNotification/notification.ts +++ b/packages/restapi/src/lib/pushNotification/notification.ts @@ -69,15 +69,21 @@ export class Notification extends PushNotificationBaseClass { env: this.env, }); } else { - return await PUSH_USER.getFeedsPerChannel({ - user: nonCaipAccount!, - page: page, - limit: limit, - spam: FEED_MAP[spam], - raw: raw, - env: this.env, - channels: channels, + const promises = channels.map(async (channel) => { + return await PUSH_USER.getFeedsPerChannel({ + user: nonCaipAccount!, + page: page, + limit: limit, + spam: FEED_MAP[spam], + raw: raw, + env: this.env, + channels: [channel], + }); }); + + const results = await Promise.all(promises); + const feedRes = results.flat(); + return feedRes; } } catch (error) { throw new Error(`Push SDK Error: API : notifcaiton::list : ${error}`); diff --git a/packages/restapi/src/lib/user/getFeedsPerChannel.ts b/packages/restapi/src/lib/user/getFeedsPerChannel.ts index 0ff7db014..333f8556f 100644 --- a/packages/restapi/src/lib/user/getFeedsPerChannel.ts +++ b/packages/restapi/src/lib/user/getFeedsPerChannel.ts @@ -11,14 +11,16 @@ import { parseApiResponse } from '../utils'; export type FeedsPerChannelOptionsType = { user: string; env?: ENV; - channels?: [string]; + channels?: string[]; page?: number; limit?: number; spam?: boolean; raw?: boolean; }; -export const getFeedsPerChannel = async (options: FeedsPerChannelOptionsType) => { +export const getFeedsPerChannel = async ( + options: FeedsPerChannelOptionsType +) => { const { user, env = Constants.ENV.PROD, diff --git a/packages/restapi/tests/lib/notification/notification.test.ts b/packages/restapi/tests/lib/notification/notification.test.ts index 9ba9d0b46..0a9ab276a 100644 --- a/packages/restapi/tests/lib/notification/notification.test.ts +++ b/packages/restapi/tests/lib/notification/notification.test.ts @@ -20,9 +20,7 @@ describe('PushAPI.notification functionality', () => { let viemSigner: any; let userViem: PushAPI; beforeEach(async () => { - signer1 = new ethers.Wallet( - `0x${process.env['WALLET_PRIVATE_KEY']}` - ); + signer1 = new ethers.Wallet(`0x${process.env['WALLET_PRIVATE_KEY']}`); account1 = await signer1.getAddress(); const provider = new ethers.providers.JsonRpcProvider( @@ -35,9 +33,7 @@ describe('PushAPI.notification functionality', () => { ); account2 = await signer2.getAddress(); viemSigner = createWalletClient({ - account: privateKeyToAccount( - `0x${process.env['WALLET_PRIVATE_KEY']}` - ), + account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`), chain: sepolia, transport: http(), }); @@ -92,7 +88,7 @@ describe('PushAPI.notification functionality', () => { it('Should return feeds when signer with provider is used', async () => { const response = await userKate.notification.list('SPAM', { - account: "0xD8634C39BBFd4033c0d3289C4515275102423681" + account: '0xD8634C39BBFd4033c0d3289C4515275102423681', }); // console.log(response) expect(response).not.null; @@ -113,27 +109,50 @@ describe('PushAPI.notification functionality', () => { // console.log(response) expect(response).not.null; }); + + it('Should return feeds when signer with provider is used', async () => { + const response = await userKate.notification.list('INBOX', { + account: '0xD8634C39BBFd4033c0d3289C4515275102423681', + channels: [ + '0xD8634C39BBFd4033c0d3289C4515275102423681', + '0x53474D90663de06BEf5D0017F450730D83168063', + ], + raw: true, + }); + // console.log(response) + expect(response).not.null; + }); + + it('Should return feeds when signer with provider is used', async () => { + const response = await userKate.notification.list('INBOX', { + account: 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681', + channels: [ + 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681', + 'eip155:11155111:0x53474D90663de06BEf5D0017F450730D83168063', + ], + raw: true, + }); + // console.log(response); + expect(response).not.null; + }); }); describe('notification :: subscribe', () => { beforeEach(async () => { - // await userAlice.notification.unsubscribe( - // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' - // ); - - // await userKate.notification.unsubscribe( - // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' - // ); - // }); - - // afterEach(async () => { - // await userAlice.notification.unsubscribe( - // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' - // ); - - // await userKate.notification.unsubscribe( - // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' - // ); + // await userAlice.notification.unsubscribe( + // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' + // ); + // await userKate.notification.unsubscribe( + // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' + // ); + // }); + // afterEach(async () => { + // await userAlice.notification.unsubscribe( + // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' + // ); + // await userKate.notification.unsubscribe( + // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' + // ); }); it.skip('Without signer object: should throw error', async () => { await expect(() => @@ -207,7 +226,7 @@ describe('PushAPI.notification functionality', () => { ], } ); - console.log(res) + // console.log(res); expect(res).not.null; }); @@ -235,17 +254,16 @@ describe('PushAPI.notification functionality', () => { const response = await userAlice.notification.subscriptions({ account: 'eip155:80001:0xD8634C39BBFd4033c0d3289C4515275102423681', }); - // console.log(response); + // console.log(response); expect(response).not.null; expect(response.lenth).not.equal(0); }); - it('Signer with account: Should return response', async () => { const response = await userKate.notification.subscriptions({ account: '0xD8634C39BBFd4033c0d3289C4515275102423681', }); - // console.log(response); + // console.log(response); expect(response).not.null; expect(response.lenth).not.equal(0); });