fix: keep unsubscribed donors as isDonating (#40103)

pull/40160/head
Ahmad Abdolsaheb 2020-11-02 13:15:03 +03:00 committed by GitHub
parent a7eba00690
commit 0a2f01c9d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 14 deletions

View File

@ -149,22 +149,13 @@ export async function cancelDonation(body, app) {
const {
resource: { id, status_update_time = new Date(Date.now()).toISOString() }
} = body;
const { User, Donation } = app.models;
const { Donation } = app.models;
Donation.findOne({ where: { subscriptionId: id } }, (err, donation) => {
if (err || !donation) throw Error(err);
const userId = donation.userId;
log(`Updating donation record: ${donation.subscriptionId}`);
donation.updateAttributes({
endDate: new Date(status_update_time).toISOString()
});
User.findOne({ where: { id: userId } }, (err, user) => {
if (err || !user || !user.donationEmails) throw Error(err);
log('Updating user record for donation cancellation');
user.updateAttributes({
isDonating: false
});
});
});
}

View File

@ -157,10 +157,7 @@ describe('donation', () => {
expect(updateDonationAttr).toHaveBeenCalledWith({
endDate: new Date(status_update_time).toISOString()
});
expect(updateUserAttr).toHaveBeenCalledWith({
isDonating: false
});
expect(updateUserAttr).not.toHaveBeenCalled();
});
});
});