Skip to content

Commit

Permalink
Remove submission notification/subscription when parent incidents (#2411
Browse files Browse the repository at this point in the history
)

* Remove submission notification/subscription when parent incidents

* Check for subscriptions to submissionPromoted
  • Loading branch information
clari182 authored Nov 15, 2023
1 parent 9bb0dd5 commit 5248f98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { SUBSCRIPTION_TYPE } = require('../../../../src/utils/subscriptions');

const promoteSubmissionToReport = require('../../../../../realm/functions/promoteSubmissionToReport');

//should be on its own /cypress/unit folder or something
Expand Down Expand Up @@ -257,6 +259,12 @@ describe('Functions', () => {
...expectedReport,
modifiedBy: submission.user,
});

expect(subscriptionsCollection.insertOne.firstCall.args[0]).to.deep.equal({
type: SUBSCRIPTION_TYPE.submissionPromoted,
incident_id: 2,
userId: 'user1',
});
});
});

Expand Down Expand Up @@ -414,6 +422,8 @@ describe('Functions', () => {
...expectedReport,
modifiedBy: submission_with_embedding.user,
});

expect(subscriptionsCollection.insertOne.called).to.be.false;
});
});

Expand Down Expand Up @@ -565,6 +575,8 @@ describe('Functions', () => {
...expectedReport,
modifiedBy: submission.user,
});

expect(subscriptionsCollection.insertOne.called).to.be.false;
});
});

Expand Down
15 changes: 1 addition & 14 deletions site/realm/functions/promoteSubmissionToReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,7 @@ exports = async (input) => {
{ incident_id: BSON.Int32(parentIncident.incident_id) },
{ $set: { ...parentIncident, embedding } }
);

if (submission.user) {
await subscriptionsCollection.insertOne({
type: 'submission-promoted',
incident_id: BSON.Int32(parentIncident.incident_id),
userId: submission.user
});

await notificationsCollection.insertOne({
type: 'submission-promoted',
incident_id: BSON.Int32(parentIncident.incident_id),
processed: false
});
}

let incidentValues = parentIncident;

delete incidentValues._id; // Otherwise Mongo complains about duplicate _id in incidentsHistory
Expand Down

0 comments on commit 5248f98

Please sign in to comment.