All files / modules/bugreport index.js

100% Statements 13/13
100% Branches 0/0
100% Functions 2/2
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54      1x 1x 1x 1x                         1x 1x 1x             1x 1x 1x                     1x 1x               1x      
/**
 * @module bugreport
 */
const mail = require("../mail");
const adminService = require("../admin");
const log = require("../../util/log");
const octokit = require("../octokit");
 
/**
 * Process bugreport submitted by a user
 * at a specific route: Send the bugreport
 * email to admin, log the bugreport via
 * the admin module and create an anonymised
 * issue on Github.
 * @param {String} originalUrl
 * @param {String} ip
 * @param {String} email
 * @param {String} report text
 */
const processBugReport = async (originalUrl, ip, email, report) => {
    log.info("Processing bug report for route: '%s'", originalUrl);
    const bugreport = {
        timestamp: (new Date()).toUTCString(),
        originalUrl,
        ip,
        email,
        report,
    };
    await sendBugReport(bugreport);
    adminService.logBugReport(bugreport);
    octokit.createBugreportIssue(bugreport);
};
 
/**
 * Send a bug report email to the bug report
 * email address specified in .env. This sets the sender
 * of the email to be the server email address, but the
 * user's email is specified in the body of the email
 * if they provided one.
 * @param {Object} bugreport
 */
const sendBugReport = async (bugreport) => {
    await mail.sendEmail(
        process.env.BUG_REPORT_EMAIL_ADDRESS,
        process.env.BUG_REPORT_EMAIL_ADDRESS,
        `[rdfmapped.com] Bug Report for route: ${bugreport.originalUrl}`,
        `Bugreport: ${JSON.stringify(bugreport)}`,
        `<p>Bugreport: <code>${JSON.stringify(bugreport)}</code></p>`);
};
 
module.exports = {
    processBugReport,
};