From b064b84af01268670437de153470a13a35defc09 Mon Sep 17 00:00:00 2001 From: greg-adams Date: Wed, 16 Oct 2024 12:08:01 -0700 Subject: [PATCH] debug test --- .../lib/grants-collaboration.test.js | 49 ++++++++++++++++--- .../lib/grantsCollaboration/grantActivity.js | 7 ++- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/packages/server/__tests__/lib/grants-collaboration.test.js b/packages/server/__tests__/lib/grants-collaboration.test.js index 339efbe122..cff46eb778 100644 --- a/packages/server/__tests__/lib/grants-collaboration.test.js +++ b/packages/server/__tests__/lib/grants-collaboration.test.js @@ -17,6 +17,7 @@ const emailConstants = require('../../src/lib/email/constants'); use(chaiAsPromised); beforeEach(async () => { + console.log('SEED......................'); await seed(knex); }); @@ -254,7 +255,7 @@ describe('Grants Collaboration', () => { }); }); - context('Grant Activity', () => { + context.only('Grant Activity', () => { // Helper functions const getUserIdsForActivities = (grants) => { const ids = grants.reduce((userIds, grant) => { @@ -286,8 +287,8 @@ describe('Grants Collaboration', () => { let grant1NoteStaff; beforeEach(async () => { - subscribeUser(adminUser); - subscribeUser(staffUser); + await subscribeUser(adminUser); + await subscribeUser(staffUser); periodStart = DateTime.now().minus({ days: 1 }).toJSDate(); @@ -323,7 +324,7 @@ describe('Grants Collaboration', () => { .insert({ grant_id: grant2.grant_id, user_id: staffUser.id }, 'id'); await knex('grant_notes_revisions') - .insert({ grant_note_id: grant2NoteStaff.id, text: 'Staff note' }, 'id'); + .insert({ grant_note_id: grant2NoteStaff.id, text: 'Another Staff note' }, 'id'); periodEnd = new Date(); }); @@ -361,21 +362,53 @@ describe('Grants Collaboration', () => { expect(grantActivities[0].follows[0].userId).to.equal(staffUser.id); }); - it('retrieves email recipients only if OTHER users took action', async () => { + it.only('retrieves email recipients only if OTHER users took action', async () => { + const logState = async () => { + // test + const followers = await knex.select('*').from('grant_followers'); + const notes = await knex.select('*').from('grant_notes'); + const revisions = await knex.select('*').from('grant_notes_revisions'); + const subs = await knex.select('*').from('email_subscriptions'); + + console.log('---followers-------------------------'); + console.log(followers); + console.log('----notes------------------------'); + console.log(notes); + console.log('----revisions------------------------'); + console.log(revisions); + console.log('----subs------------------------'); + console.log(subs); + + console.log('NOW', new Date()); + }; + await logState(); periodStart = new Date(); // Admin edits note - await knex('grant_notes_revisions') - .insert({ grant_note_id: grant1NoteAdmin.id, text: 'Edit for Admin note' }, 'id'); + const [revised] = await knex('grant_notes_revisions') + .insert({ grant_note_id: grant1NoteAdmin.id, text: 'Edit for Admin note' }, 'created_at'); + + await new Promise((resolve) => setTimeout(resolve, 60)); + const end = new Date(); + console.log('revised note:', revised, end); - const recipients1 = await getGrantActivityEmailRecipients(knex, periodStart, new Date()); + const recipients1 = await getGrantActivityEmailRecipients(knex, periodStart, end); + console.log('--recipients1----------------------'); + console.log(recipients1); + + await logState(); expect(_.map(recipients1, 'userId')).to.have.members([staffUser.id]); // Staff edits note await knex('grant_notes_revisions') .insert({ grant_note_id: grant1NoteStaff.id, text: 'Edit for Staff note' }, 'id'); + await new Promise((resolve) => setTimeout(resolve, 60)); const recipients2 = await getGrantActivityEmailRecipients(knex, periodStart, new Date()); + console.log('--recipients2----------------------'); + console.log(recipients2); + + await logState(); expect(_.map(recipients2, 'userId')).to.have.members([staffUser.id, adminUser.id]); }); diff --git a/packages/server/src/lib/grantsCollaboration/grantActivity.js b/packages/server/src/lib/grantsCollaboration/grantActivity.js index d980ad942f..9b01c6b4d5 100644 --- a/packages/server/src/lib/grantsCollaboration/grantActivity.js +++ b/packages/server/src/lib/grantsCollaboration/grantActivity.js @@ -37,6 +37,9 @@ const getActivitiesQuery = (knex) => { }; async function getGrantActivityEmailRecipients(knex, periodStart, periodEnd) { + await new Promise((resolve) => setTimeout(resolve, 100)); + + console.log('Performing query...', periodStart, ' to ', periodEnd); const query = knex .select([ 'recipient_users.id AS recipient_user_id', @@ -54,8 +57,8 @@ async function getGrantActivityEmailRecipients(knex, periodStart, periodEnd) { .on(`recipient_followers.user_id`, '=', `recipient_subscriptions.user_id`) .on(`recipient_subscriptions.notification_type`, '=', knex.raw('?', [emailConstants.notificationType.grantActivity])); }) - .where('activity.activity_at', '>', periodStart) - .andWhere('activity.activity_at', '<', periodEnd) + .where('activity.activity_at', '>=', periodStart) + .andWhere('activity.activity_at', '<=', periodEnd) .andWhere('recipient_subscriptions.status', emailConstants.emailSubscriptionStatus.subscribed) // only consider actions taken by users in the same organization as the recipient: .andWhereRaw('recipient_users.tenant_id = activity_users.tenant_id')