All files / src index.js

82.35% Statements 14/17
50% Branches 2/4
83.33% Functions 5/6
82.35% Lines 14/17

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      1x 1x 1x       3x         2x     2x   2x                             1x     1x   1x       3x 6x   6x         1x  
/**
 * Entrypoint for Javascript/Node applications
 */
const Config = require('./Config');
const Feed = require('./Feed');
const Email = require('./Email');
 
class RssToEmail {
  constructor(config) {
    this.config = new Config(config);
  }
 
  async getEmail(format) {
    // Create an array of feeds
    const feeds = await this.getFeeds();
 
    // Generate Email
    const email = new Email(this.config, feeds);
 
    return format === 'mjml' ? email.getMjml() : email.getHtml();
  }
 
  async saveEmail(format) {
    // Create an array of feeds
    const feeds = await this.getFeeds();
 
    // Generate Email
    const email = new Email(this.config, feeds);
 
    return format === 'mjml' ? email.saveMjml() : email.saveHtml();
  }
 
  async saveEmails() {
    // Create an array of feeds
    const feeds = await this.getFeeds();
 
    // Generate Email
    const email = new Email(this.config, feeds);
 
    return email.save();
  }
 
  getFeeds() {
    return Promise.all(this.config.feeds.map(async (feedConfig) => {
      const feed = new Feed(feedConfig);
 
      return await feed.resolve();
    }));
  }
}
 
module.exports = RssToEmail;