From 6f3a22d0a71c0491acd12ef19737a49de7e45282 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Wed, 13 Dec 2023 14:04:33 +0100 Subject: [PATCH] Added email_recipient_failures to data generator ref PROD-244 --- .../EmailRecipientFailuresImporter.js | 67 +++++++++++++++++++ ghost/data-generator/lib/importers/index.js | 1 + 2 files changed, 68 insertions(+) create mode 100644 ghost/data-generator/lib/importers/EmailRecipientFailuresImporter.js diff --git a/ghost/data-generator/lib/importers/EmailRecipientFailuresImporter.js b/ghost/data-generator/lib/importers/EmailRecipientFailuresImporter.js new file mode 100644 index 0000000000..eedfac8e90 --- /dev/null +++ b/ghost/data-generator/lib/importers/EmailRecipientFailuresImporter.js @@ -0,0 +1,67 @@ +const TableImporter = require('./TableImporter'); +const {faker} = require('@faker-js/faker'); + +class EmailRecipientFailuresImporter extends TableImporter { + static table = 'email_recipient_failures'; + static dependencies = ['email_recipients']; + + constructor(knex, transaction) { + super(EmailRecipientFailuresImporter.table, knex, transaction); + } + + async import(quantity) { + const recipients = await this.transaction + .select( + 'id', + 'email_id', + 'member_id', + 'failed_at') + .from('email_recipients') + .whereNotNull('failed_at'); + + await this.importForEach(recipients, quantity ? quantity / recipients.length : 1); + } + + generate() { + const errors = [ + { + severity: 'permanent', + code: 605, + enhanced_code: null, + message: 'Not delivering to previously bounced address' + }, + { + severity: 'permanent', + code: 451, + enhanced_code: '4.7.652', + message: '4.7.652 The mail server [xxx.xxx.xxx.xxx] has exceeded the maximum number of connections.' + }, + { + message: 'No MX for example.com', + code: 498, + enhanced_code: null, + severity: 'permanent' + }, + { + severity: 'temporary', + code: 552, + enhanced_code: null, + message: '5.2.2 : user is over quota' + } + ]; + + const error = faker.helpers.arrayElement(errors); + + return { + id: faker.database.mongodbObjectId(), + email_id: this.model.email_id, + member_id: this.model.member_id, + email_recipient_id: this.model.id, + event_id: faker.random.alphaNumeric(20), + ...error, + failed_at: this.model.failed_at + }; + } +} + +module.exports = EmailRecipientFailuresImporter; diff --git a/ghost/data-generator/lib/importers/index.js b/ghost/data-generator/lib/importers/index.js index 4ccbfc32ea..ea75a23412 100644 --- a/ghost/data-generator/lib/importers/index.js +++ b/ghost/data-generator/lib/importers/index.js @@ -19,6 +19,7 @@ module.exports = [ require('./EmailsImporter'), require('./EmailBatchesImporter'), require('./EmailRecipientsImporter'), + require('./EmailRecipientFailuresImporter'), require('./RedirectsImporter'), require('./MembersClickEventsImporter'), require('./OffersImporter'),