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 Nov 28, 2023
2 parents eebbc31 + 0145aed commit e9f6aa2
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 60 deletions.
7 changes: 6 additions & 1 deletion packages/restapi/src/lib/channels/getSubscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type GetChannelSubscribersOptionsType = {
channel: string; // plain ETH Format only
page?: number,
limit?: number,
category?: number,
env?: ENV
}

Expand All @@ -28,6 +29,7 @@ export const getSubscribers = async (
channel,
page = 1,
limit = 10,
category,
env = Constants.ENV.PROD,
} = options || {};

Expand All @@ -49,7 +51,10 @@ export const getSubscribers = async (
}
const _channel = await getCAIPAddress(env, channel, 'Channel');
const API_BASE_URL = getAPIBaseUrls(env);
const apiEndpoint = `${API_BASE_URL}/v1/channels/${_channel}/subscribers?page=${page}&limit=${limit}`;
let apiEndpoint = `${API_BASE_URL}/v1/channels/${_channel}/subscribers?page=${page}&limit=${limit}`;
if(category){
apiEndpoint = apiEndpoint+`&category=${category}`
}
return await axios.get(apiEndpoint)
.then((response) => response.data)
.catch((err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ChannelInfoOptions = {
channel?: string;
page?: number;
limit?: number;
category?: number
};

export type SubscribeUnsubscribeOptions = {
Expand Down
1 change: 1 addition & 0 deletions packages/restapi/src/lib/pushNotification/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class Channel extends PushNotificationBaseClass {
env: this.env,
page: options.page,
limit: options.limit ?? 10,
category: options.category
});
} else {
/** @dev - Fallback to deprecated method when page is not provided ( to ensure backward compatibility ) */
Expand Down
29 changes: 21 additions & 8 deletions packages/restapi/src/lib/pushNotification/pushNotificationBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,15 +762,28 @@ export class PushNotificationBaseClass {
const ele = setting[i];
const enabled = ele.enabled ? 1 : 0;
if (ele.enabled) numberOfSettings++;
// slider type

if (Object.keys(ele).includes('value')) {
userSetting =
userSetting +
SLIDER_TYPE +
SETTING_DELIMITER +
enabled +
SETTING_DELIMITER +
ele.value;
// slider type
if (typeof ele.value == 'number')
userSetting =
userSetting +
SLIDER_TYPE +
SETTING_DELIMITER +
enabled +
SETTING_DELIMITER +
ele.value;
else {
userSetting =
userSetting +
RANGE_TYPE +
SETTING_DELIMITER +
enabled +
SETTING_DELIMITER +
ele.value?.lower +
SETTING_DELIMITER +
ele.value?.upper;
}
} else {
// boolean type
userSetting = userSetting + BOOLEAN_TYPE + SETTING_DELIMITER + enabled;
Expand Down
40 changes: 21 additions & 19 deletions packages/restapi/tests/lib/pushNotification/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,41 @@ enum ENV {
LOCAL = 'local',
}
describe.only('test', () => {
const signer = createWalletClient({
account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`),
chain: goerli,
transport: http('https://goerli.blockpi.network/v1/rpc/public'),
});
// const signer = createWalletClient({
// account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`),
// chain: goerli,
// transport: http('https://goerli.blockpi.network/v1/rpc/public'),
// });

const signer3 = createWalletClient({
account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`),
chain: polygonMumbai,
transport: http(),
});
// const signer3 = createWalletClient({
// account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`),
// chain: polygonMumbai,
// transport: http(),
// });

const provider = new ethers.providers.JsonRpcProvider(
'https://goerli.blockpi.network/v1/rpc/public'
);
const signer2 = new ethers.Wallet(
`0x${process.env['WALLET_PRIVATE_KEY']}`,
provider
);
// const provider = new ethers.providers.JsonRpcProvider(
// 'https://goerli.blockpi.network/v1/rpc/public'
// );
// const signer2 = new ethers.Wallet(
// `0x${process.env['WALLET_PRIVATE_KEY']}`,
// provider
// );

// it.only('Test minimal conversion', async () => {
// it('Test minimal conversion', async () => {
// const account2 = await signer2.getAddress();
// const viemUser = new PushNotificationBaseClass(
// signer,
// ENV.STAGING,
// account2
// );
// viemUser.getMinimalUserSetting([
// const res = viemUser.getMinimalUserSetting([
// { enabled: true },
// { enabled: false, value: 10 },
// { enabled: false },
// { enabled: true, value: 10 },
// {enabled: true, value: {lower:10, upper:100}}
// ]);
// console.log(res)
// });
// it('testing with viem', async () => {
// const account2 = await signer2.getAddress();
Expand Down
5 changes: 5 additions & 0 deletions packages/restapi/tests/lib/pushNotification/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ describe('PushAPI.channel functionality', () => {
expect(res).not.null;
});

it('Without signer and account : Should return response without passing the options', async () => {
const res = await userKate.channel.subscribers({page:1, limit:10, category:2});
expect(res).not.null;
});

it('Without signer and account : Should throw error for invalid caip', async () => {
await expect(() =>
userBob.channel.subscribers({
Expand Down
108 changes: 76 additions & 32 deletions packages/restapi/tests/lib/pushNotification/notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,37 @@ describe('PushAPI.notification functionality', () => {
let userViem: PushAPI;
beforeEach(async () => {
signer1 = new ethers.Wallet(
`0x${process.env['NFT_HOLDER_WALLET_PRIVATE_KEY_1']}`
`0x${process.env['WALLET_PRIVATE_KEY']}`
);
account1 = await signer1.getAddress();

const provider = new ethers.providers.JsonRpcProvider(
'https://rpc.sepolia.org'
);

signer2 = new ethers.Wallet(
`0x${process.env['NFT_HOLDER_WALLET_PRIVATE_KEY_1']}`,
`0x${process.env['WALLET_PRIVATE_KEY']}`,
provider
);
account2 = await signer2.getAddress();
viemSigner = createWalletClient({
account: privateKeyToAccount(
`0x${process.env['NFT_HOLDER_WALLET_PRIVATE_KEY_1']}`
`0x${process.env['WALLET_PRIVATE_KEY']}`
),
chain: sepolia,
transport: http(),
});
enum ENV {
PROD = 'prod',
STAGING = 'staging',
DEV = 'dev',
/**
* **This is for local development only**
*/
LOCAL = 'local',
}
// initialisation with signer and provider
userKate = await PushAPI.initialize(signer2);
userKate = await PushAPI.initialize(signer2, {env:ENV.DEV});
// initialisation with signer
userAlice = await PushAPI.initialize(signer1);
// TODO: remove signer1 after signer becomes optional
Expand Down Expand Up @@ -85,7 +94,7 @@ describe('PushAPI.notification functionality', () => {

it('Should return feeds when viem is used', async () => {
const response = await userViem.notification.list('SPAM');
console.log(response)
console.log(response);
expect(response).not.null;
});

Expand All @@ -95,30 +104,30 @@ describe('PushAPI.notification functionality', () => {
channels: ['0xD8634C39BBFd4033c0d3289C4515275102423681'],
raw: true,
});
// console.log(response)
// console.log(response)
expect(response).not.null;
});
});

describe('notification :: subscribe', () => {
beforeEach(async () => {
await userAlice.notification.unsubscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
);
// await userAlice.notification.unsubscribe(
// 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
// );

await userKate.notification.unsubscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
);
});
// await userKate.notification.unsubscribe(
// 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
// );
// });

afterEach(async () => {
await userAlice.notification.unsubscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
);
// afterEach(async () => {
// await userAlice.notification.unsubscribe(
// 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
// );

await userKate.notification.unsubscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
);
// await userKate.notification.unsubscribe(
// 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
// );
});
it.skip('Without signer object: should throw error', async () => {
await expect(() =>
Expand All @@ -138,13 +147,17 @@ describe('PushAPI.notification functionality', () => {

it('With signer object: Should subscribe', async () => {
const res = await userAlice.notification.subscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681', {
settings: [{
enabled: false
},{
enabled: false,
value: 0
}, ]
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681',
{
settings: [
{
enabled: false,
},
{
enabled: false,
value: 0,
},
],
}
);
// console.log(res)
Expand All @@ -159,6 +172,39 @@ describe('PushAPI.notification functionality', () => {
expect(res).not.null;
});

it('With signer and provider: Should subscribe', async () => {
const res = await userKate.notification.subscribe(
'eip155:11155111:0xC8c243a4fd7F34c49901fe441958953402b7C024',
{
settings: [
{
enabled: false,
},
{
enabled: true,
value: 15,
},
{
enabled: true,
value: {
lower: 5,
upper: 10,
},
},
{
enabled: true,
value: {
lower: 5,
upper: 10,
},
},
],
}
);
console.log(res)
expect(res).not.null;
});

it('With viem signer and provider: Should subscribe', async () => {
const res = await userViem.notification.subscribe(
'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681'
Expand All @@ -175,7 +221,7 @@ describe('PushAPI.notification functionality', () => {

it('Signer with no account: Should return response', async () => {
const response = await userAlice.notification.subscriptions();
console.log(response);
console.log(response);
expect(response).not.null;
});

Expand Down Expand Up @@ -208,7 +254,5 @@ describe('PushAPI.notification functionality', () => {
// it("Uploading data to ipfs via push node", async () => {
// await userAlice.uploadToIPFSViaPushNode("test")
// })


});
});
// });

0 comments on commit e9f6aa2

Please sign in to comment.