Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix 46 fix notification settings default #48

Merged
merged 5 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notification-venter",
"version": "1.0.0",
"version": "2.0.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
337 changes: 169 additions & 168 deletions src/repositories/notificationSettingRepository.test.ts
Original file line number Diff line number Diff line change
@@ -1,195 +1,196 @@
import { assert } from 'chai';
import { generateRandomEthereumAddress } from '../../test/testUtils';
import { NotificationSetting } from '../entities/notificationSetting';
import {assert} from 'chai';
import {generateRandomEthereumAddress} from '../../test/testUtils';
import {NotificationSetting} from '../entities/notificationSetting';
import {
findNotificationSettingByNotificationTypeAndUserAddress,
getUserNotificationSettings,
updateUserNotificationSetting,
findNotificationSettingByNotificationTypeAndUserAddress,
getUserNotificationSettings,
updateUserNotificationSetting,
} from './notificationSettingRepository';
import { createNewUserAddressIfNotExists } from './userAddressRepository';
import { getNotificationTypeByEventName } from './notificationTypeRepository';
import { SegmentEvents } from '../services/segment/segmentAnalyticsSingleton';
import {createNewUserAddressIfNotExists} from './userAddressRepository';
import {getNotificationTypeByEventName} from './notificationTypeRepository';
import {SegmentEvents} from '../services/segment/segmentAnalyticsSingleton';

// createNotificationSettingsForNewUser tested in userRepository
describe(
'getUserNotificationSettings() test cases',
getUserNotificationSettingsTestCases,
'getUserNotificationSettings() test cases',
getUserNotificationSettingsTestCases,
);

describe(
'updateUserNotificationSetting() test cases',
updateUserNotificationSettingTestCases,
'updateUserNotificationSetting() test cases',
updateUserNotificationSettingTestCases,
);
describe(
'findNotificationSettingByNotificationTypeAndUserAddress() test cases',
findNotificationSettingByNotificationTypeAndUserAddressTestCases,
'findNotificationSettingByNotificationTypeAndUserAddress() test cases',
findNotificationSettingByNotificationTypeAndUserAddressTestCases,
);

const walletAddress = generateRandomEthereumAddress();

function getUserNotificationSettingsTestCases() {
it('return notification settings by user and take and skip', async () => {
const userAddress = await createNewUserAddressIfNotExists(walletAddress);
const take = 50;
const skip = 0;

const [notificationSettings] = await getUserNotificationSettings(
take,
skip,
userAddress.id,
);

assert.isOk(notificationSettings);
notificationSettings.forEach(setting => {
assert.isTrue(setting!.userAddressId === userAddress.id);
assert.isTrue(setting?.notificationType?.showOnSettingPage);
it('return notification settings by user and take and skip', async () => {
const userAddress = await createNewUserAddressIfNotExists(walletAddress);
const take = 50;
const skip = 0;

const [notificationSettings] = await getUserNotificationSettings(
take,
skip,
userAddress.id,
);

assert.isOk(notificationSettings);
notificationSettings.forEach(setting => {
assert.isTrue(setting!.userAddressId === userAddress.id);
assert.isTrue(setting?.notificationType?.showOnSettingPage);
});
});
});
it('return notification settings order by notificationTypeId', async () => {
const userAddress = await createNewUserAddressIfNotExists(
generateRandomEthereumAddress(),
);

const [notificationSettings] = await getUserNotificationSettings(
100,
0,
userAddress.id,
);

assert.isOk(notificationSettings);
notificationSettings.forEach(setting => {
assert.isTrue(setting!.userAddressId === userAddress.id);
assert.isTrue(setting?.notificationType?.showOnSettingPage);
it('return notification settings order by notificationTypeId', async () => {
const userAddress = await createNewUserAddressIfNotExists(
generateRandomEthereumAddress(),
);

const [notificationSettings] = await getUserNotificationSettings(
100,
0,
userAddress.id,
);

assert.isOk(notificationSettings);
notificationSettings.forEach(setting => {
assert.isTrue(setting!.userAddressId === userAddress.id);
assert.isTrue(setting?.notificationType?.showOnSettingPage);
});

for (let i = 1; i < notificationSettings.length; i++) {
assert.isTrue(
notificationSettings[i]?.notificationTypeId >
notificationSettings[i - 1]?.notificationTypeId,
);
}
});

for (let i = 1; i < notificationSettings.length; i++) {
assert.isTrue(
notificationSettings[i]?.notificationTypeId >
notificationSettings[i - 1]?.notificationTypeId,
);
}
});
}

function findNotificationSettingByNotificationTypeAndUserAddressTestCases() {
it('return notification settings for userAddress and notificationType', async () => {
const address = generateRandomEthereumAddress();
const userAddress = await createNewUserAddressIfNotExists(address);
const notificationType = await getNotificationTypeByEventName(
SegmentEvents.PROJECT_LISTED,
);
const notificationSettings =
await findNotificationSettingByNotificationTypeAndUserAddress({
userAddressId: userAddress.id,
notificationTypeId: notificationType?.id as number,
});

assert.isOk(notificationSettings);
assert.equal(
notificationSettings?.notificationTypeId,
notificationType?.id,
);
assert.equal(notificationSettings?.userAddressId, userAddress?.id);
});
it('return null for invalid notificationType', async () => {
const address = generateRandomEthereumAddress();
const userAddress = await createNewUserAddressIfNotExists(address);
const notificationSettings =
await findNotificationSettingByNotificationTypeAndUserAddress({
userAddressId: userAddress.id,
notificationTypeId: 999999,
});

assert.isNull(notificationSettings);
});

it('return null for invalid notificationAddress', async () => {
const notificationType = await getNotificationTypeByEventName(
SegmentEvents.PROJECT_LISTED,
);
const notificationSettings =
await findNotificationSettingByNotificationTypeAndUserAddress({
userAddressId: 99999,
notificationTypeId: notificationType?.id as number,
});
assert.isNull(notificationSettings);
});
it('return notification settings for userAddress and notificationType', async () => {
const address = generateRandomEthereumAddress();
const userAddress = await createNewUserAddressIfNotExists(address);
const notificationType = await getNotificationTypeByEventName(
SegmentEvents.PROJECT_LISTED,
);
const notificationSettings =
await findNotificationSettingByNotificationTypeAndUserAddress({
userAddressId: userAddress.id,
notificationTypeId: notificationType?.id as number,
});

assert.isOk(notificationSettings);
assert.equal(
notificationSettings?.notificationTypeId,
notificationType?.id,
);
assert.equal(notificationSettings?.userAddressId, userAddress?.id);
});
it('return null for invalid notificationType', async () => {
const address = generateRandomEthereumAddress();
const userAddress = await createNewUserAddressIfNotExists(address);
const notificationSettings =
await findNotificationSettingByNotificationTypeAndUserAddress({
userAddressId: userAddress.id,
notificationTypeId: 999999,
});

assert.isNull(notificationSettings);
});

it('return null for invalid notificationAddress', async () => {
const notificationType = await getNotificationTypeByEventName(
SegmentEvents.PROJECT_LISTED,
);
const notificationSettings =
await findNotificationSettingByNotificationTypeAndUserAddress({
userAddressId: 99999,
notificationTypeId: notificationType?.id as number,
});
assert.isNull(notificationSettings);
});
}

function updateUserNotificationSettingTestCases() {
it('update user notification settings', async () => {
const userAddress = await createNewUserAddressIfNotExists(walletAddress);

const userNotificationSetting =
await NotificationSetting.createQueryBuilder('setting')
.leftJoinAndSelect('setting.notificationType', 'notificationType')
.where('setting."userAddressId" = :userAddressId', {
userAddressId: userAddress.id,
})
.andWhere('notificationType.isGroupParent = false')
.andWhere('notificationType.isEmailEditable = true')
.andWhere('notificationType.isWebEditable = true')
.getOne();

assert.isTrue(userNotificationSetting?.userAddressId === userAddress.id);

const updatedSetting = await updateUserNotificationSetting({
notificationSettingId: userNotificationSetting!.id,
userAddressId: userAddress.id,
allowEmailNotification: false,
allowDappPushNotification: false,
it('update user notification settings', async () => {
const userAddress = await createNewUserAddressIfNotExists(walletAddress);

const userNotificationSetting =
await NotificationSetting.createQueryBuilder('setting')
.leftJoinAndSelect('setting.notificationType', 'notificationType')
.where('setting."userAddressId" = :userAddressId', {
userAddressId: userAddress.id,
})
.andWhere('notificationType.isGroupParent = false')
.andWhere('notificationType.isEmailEditable = true')
.andWhere('notificationType.isWebEditable = true')
.getOne();

assert.isTrue(userNotificationSetting?.userAddressId === userAddress.id);

const updatedSetting = await updateUserNotificationSetting({
notificationSettingId: userNotificationSetting!.id,
userAddressId: userAddress.id,
allowEmailNotification: false,
allowDappPushNotification: false,
});
assert.isOk(updatedSetting);
assert.isFalse(updatedSetting?.allowEmailNotification);
assert.isFalse(updatedSetting?.allowDappPushNotification);
});
assert.isOk(updatedSetting);
assert.isFalse(updatedSetting?.allowEmailNotification);
assert.isFalse(updatedSetting?.allowDappPushNotification);
});
it('update user notification settings, cant change when isEmailEditable is false', async () => {
const userAddress = await createNewUserAddressIfNotExists(walletAddress);

const userNotificationSetting =
await NotificationSetting.createQueryBuilder('setting')
.leftJoinAndSelect('setting.notificationType', 'notificationType')
.where('setting."userAddressId" = :userAddressId', {
userAddressId: userAddress.id,
})
.andWhere('notificationType.isGroupParent = false')
.andWhere('notificationType.isEmailEditable = false')
.andWhere('notificationType.isWebEditable = true')
.getOne();

assert.isTrue(userNotificationSetting?.userAddressId === userAddress.id);

const updatedSetting = await updateUserNotificationSetting({
notificationSettingId: userNotificationSetting!.id,
userAddressId: userAddress.id,
allowEmailNotification: false,
allowDappPushNotification: false,
it('update user notification settings, cant change when isEmailEditable is false', async () => {
const userAddress = await createNewUserAddressIfNotExists(walletAddress);

const userNotificationSetting =
await NotificationSetting.createQueryBuilder('setting')
.leftJoinAndSelect('setting.notificationType', 'notificationType')
.where('setting."userAddressId" = :userAddressId', {
userAddressId: userAddress.id,
})
.andWhere('notificationType.isGroupParent = true')
.andWhere('notificationType.isEmailEditable = false')
.andWhere('setting.allowEmailNotification = false')
.andWhere('notificationType.isWebEditable = true')
.getOne();

assert.isTrue(userNotificationSetting?.userAddressId === userAddress.id);

const updatedSetting = await updateUserNotificationSetting({
notificationSettingId: userNotificationSetting!.id,
userAddressId: userAddress.id,
allowEmailNotification: true,
allowDappPushNotification: false,
});
assert.isOk(updatedSetting);
assert.isFalse(updatedSetting?.allowEmailNotification);
assert.isFalse(updatedSetting?.allowDappPushNotification);
});
assert.isOk(updatedSetting);
assert.isTrue(updatedSetting?.allowEmailNotification);
assert.isFalse(updatedSetting?.allowDappPushNotification);
});
it('update user notification settings, cant change when isWebEditable is false', async () => {
const userAddress = await createNewUserAddressIfNotExists(walletAddress);

const userNotificationSetting =
await NotificationSetting.createQueryBuilder('setting')
.leftJoinAndSelect('setting.notificationType', 'notificationType')
.where('setting."userAddressId" = :userAddressId', {
userAddressId: userAddress.id,
})
.andWhere('notificationType.isWebEditable = false')
.getOne();

assert.isTrue(userNotificationSetting?.userAddressId === userAddress.id);

const updatedSetting = await updateUserNotificationSetting({
notificationSettingId: userNotificationSetting!.id,
userAddressId: userAddress.id,
allowEmailNotification: false,
allowDappPushNotification: false,
it('update user notification settings, cant change when isWebEditable is false', async () => {
const userAddress = await createNewUserAddressIfNotExists(walletAddress);

const userNotificationSetting =
await NotificationSetting.createQueryBuilder('setting')
.leftJoinAndSelect('setting.notificationType', 'notificationType')
.where('setting."userAddressId" = :userAddressId', {
userAddressId: userAddress.id,
})
.andWhere('notificationType.isWebEditable = false')
.getOne();

assert.isTrue(userNotificationSetting?.userAddressId === userAddress.id);

const updatedSetting = await updateUserNotificationSetting({
notificationSettingId: userNotificationSetting!.id,
userAddressId: userAddress.id,
allowEmailNotification: false,
allowDappPushNotification: false,
});
assert.isOk(updatedSetting);
assert.isTrue(updatedSetting?.allowDappPushNotification);
});
assert.isOk(updatedSetting);
assert.isTrue(updatedSetting?.allowDappPushNotification);
});
}
Loading