Skip to content

Commit

Permalink
modify some emailPref tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thelmaboamah committed Nov 23, 2023
1 parent 43bb7e1 commit 0e12022
Showing 1 changed file with 56 additions and 7 deletions.
63 changes: 56 additions & 7 deletions packages/server/__tests__/db/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ describe('db', () => {
});

context('createUser', () => {
it('sets default email unsubuscribe when new users are created', async () => {
it('sets default email to subscribed when new users are created', async () => {
const response = await db.createUser(
{
email: '[email protected]',
Expand All @@ -869,9 +869,10 @@ describe('db', () => {
},
);
const createdUser = await db.getUser(response.id);
expect(createdUser.emailPreferences.GRANT_ASSIGNMENT).to.equal(emailConstants.emailSubscriptionStatus.unsubscribed);
expect(createdUser.emailPreferences.GRANT_DIGEST).to.equal(emailConstants.emailSubscriptionStatus.unsubscribed);
expect(createdUser.emailPreferences.GRANT_INTEREST).to.equal(emailConstants.emailSubscriptionStatus.unsubscribed);
expect(createdUser.emailPreferences.GRANT_ASSIGNMENT).to.equal(emailConstants.emailSubscriptionStatus.subscribed);
expect(createdUser.emailPreferences.GRANT_DIGEST).to.equal(emailConstants.emailSubscriptionStatus.subscribed);
expect(createdUser.emailPreferences.GRANT_FINDER_UPDATES).to.equal(emailConstants.emailSubscriptionStatus.subscribed);
expect(createdUser.emailPreferences.GRANT_INTEREST).to.equal(emailConstants.emailSubscriptionStatus.subscribed);
await db.deleteUser(response.id);
});
});
Expand All @@ -893,6 +894,40 @@ describe('db', () => {
expect(updatedUser.name).to.equal(NAME);
await db.deleteUser(user.id);
});

it('Updates user\'s avatar', async () => {
const user = await db.createUser(
{
email: '[email protected]',
name: 'sample name',
role_id: fixtures.roles.adminRole.id,
agency_id: fixtures.agencies.accountancy.id,
tenant_id: fixtures.tenants.SBA.id,
id: 99991,
},
);
const HEX_COLOR = '#44337A';
const updatedUser = await db.updateUser({ id: user.id, avatar_color: HEX_COLOR });
expect(updatedUser.avatar_color).to.equal(HEX_COLOR);
await db.deleteUser(user.id);
});

it('Updates fields independently', async () => {
const user = await db.createUser(
{
email: '[email protected]',
name: 'sample name',
role_id: fixtures.roles.adminRole.id,
agency_id: fixtures.agencies.accountancy.id,
tenant_id: fixtures.tenants.SBA.id,
id: 99991,
},
);
const NAME = 'new name';
const updatedUser = await db.updateUser({ id: user.id, name: NAME }); // only changing name
expect(updatedUser.avatar_color).to.include('#'); // avatar_color is a hex color starting with #
await db.deleteUser(user.id);
})

Check failure on line 930 in packages/server/__tests__/db/db.test.js

View workflow job for this annotation

GitHub Actions / Server and Client Unit Tests

Missing semicolon
});

context('deleteUser', () => {
Expand All @@ -908,9 +943,10 @@ describe('db', () => {
},
);
const createdUser = await db.getUser(response.id);
expect(createdUser.emailPreferences.GRANT_ASSIGNMENT).to.equal(emailConstants.emailSubscriptionStatus.unsubscribed);
expect(createdUser.emailPreferences.GRANT_DIGEST).to.equal(emailConstants.emailSubscriptionStatus.unsubscribed);
expect(createdUser.emailPreferences.GRANT_INTEREST).to.equal(emailConstants.emailSubscriptionStatus.unsubscribed);
expect(createdUser.emailPreferences.GRANT_ASSIGNMENT).to.equal(emailConstants.emailSubscriptionStatus.subscribed);
expect(createdUser.emailPreferences.GRANT_DIGEST).to.equal(emailConstants.emailSubscriptionStatus.subscribed);
expect(createdUser.emailPreferences.GRANT_FINDER_UPDATES).to.equal(emailConstants.emailSubscriptionStatus.subscribed);
expect(createdUser.emailPreferences.GRANT_INTEREST).to.equal(emailConstants.emailSubscriptionStatus.subscribed);
await db.deleteUser(response.id);

const existingSubscriptions = await knex('email_subscriptions').where('user_id', response.id);
Expand Down Expand Up @@ -953,6 +989,12 @@ describe('db', () => {
notification_type: emailConstants.notificationType.grantInterest,
status: emailConstants.emailSubscriptionStatus.subscribed,
},
{
user_id: fixtures.users.adminUser.id,
agency_id: fixtures.agencies.accountancy.id,
notification_type: emailConstants.notificationType.grantFinderUpdates,
status: emailConstants.emailSubscriptionStatus.subscribed,
},
];
await knex('email_subscriptions').insert(preferences);
const result = await db.getUserEmailSubscriptionPreference(fixtures.users.adminUser.id, fixtures.agencies.accountancy.id);
Expand Down Expand Up @@ -1039,6 +1081,8 @@ describe('db', () => {
const digestSubscribers = digestResult.map((r) => r.email);
const interestResult = await db.getSubscribersForNotification(fixtures.agencies.accountancy.id, emailConstants.notificationType.grantInterest);
const interestSubscribers = interestResult.map((r) => r.email);
const finderUpdatesResult = await db.getSubscribersForNotification(fixtures.agencies.accountancy.id, emailConstants.notificationType.grantFinderUpdates);
const finderUpdatesSubscribers = finderUpdatesResult.map((r) => r.email);

expect(assignmentResult.length).to.equal(2);
expect(assignmentSubscribers.includes(fixtures.users.staffUser.email)).to.equal(true);
Expand All @@ -1051,6 +1095,10 @@ describe('db', () => {
expect(interestResult.length).to.equal(2);
expect(interestSubscribers.includes(fixtures.users.staffUser.email)).to.equal(true);
expect(interestSubscribers.includes(fixtures.users.adminUser.email)).to.equal(true);

expect(finderUpdatesResult.length).to.equal(2);
expect(finderUpdatesSubscribers.includes(fixtures.users.staffUser.email)).to.equal(true);
expect(finderUpdatesSubscribers.includes(fixtures.users.adminUser.email)).to.equal(true);
});
it('gets subscribed users for an agency', async () => {
await db.setUserEmailSubscriptionPreference(
Expand All @@ -1068,6 +1116,7 @@ describe('db', () => {
{
[emailConstants.notificationType.grantAssignment]: emailConstants.emailSubscriptionStatus.subscribed,
[emailConstants.notificationType.grantDigest]: emailConstants.emailSubscriptionStatus.unsubscribed,
[emailConstants.notificationType.grantFinderUpdates]: emailConstants.emailSubscriptionStatus.subscribed,
[emailConstants.notificationType.grantInterest]: emailConstants.emailSubscriptionStatus.unsubscribed,
},
);
Expand Down

0 comments on commit 0e12022

Please sign in to comment.