All files / src Config.js

100% Statements 17/17
100% Branches 6/6
100% Functions 1/1
100% Lines 17/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 54 55 56 57 58 59 60 61 62 63 641x   1x   1x             1x 1x 1x       1x             1x 1x 1x       1x                                     1x     3x 1x     2x 16x         1x  
const stampit = require('stampit');
 
const DEFAULT_CONFIG_WARNING_MESSAGE = 'No configuration file or object included. Defaults will be used.';
 
const HeaderConfig = stampit({
  props: {
    banner: undefined,
    link: undefined,
    title: undefined,
  },
  init(options) {
    this.banner = options.banner;
    this.link = options.link;
    this.title = options.title;
  },
});
 
const FeedConfig = stampit({
  props: {
    description: undefined,
    title: undefined,
    url: undefined,
  },
  init(options) {
    this.description = options.description;
    this.title = options.title;
    this.url = options.url;
  },
});
 
const DEFAULT_CONFIG_OBJECT = {
  accentColor: 'red',
  filename: 'example',
  header: HeaderConfig({
    description: 'A short custom feed description',
    title: 'A custom feed title',
    url: 'http://www.feedforall.com/sample.xml',
  }),
  greeting: 'Hey there,',
  intro: 'Thanks for opening the email! Here are some links I want you to check out:',
  feeds: [FeedConfig({
    description: 'A short custom feed description',
    title: 'A custom feed title',
    url: 'http://www.feedforall.com/sample.xml',
  })],
  outro: "Thanks for reading. We'll be back next week with more!",
  signature: 'John Smith, CMO at Example Co.',
};
 
const Config = stampit({
  props: DEFAULT_CONFIG_OBJECT,
  init(options) {
    if (Object.keys(options).length === 0 && options.constructor === Object) {
      throw DEFAULT_CONFIG_WARNING_MESSAGE;
    }
 
    Object.keys(this).forEach((property) => {
      this[property] = options[property] || DEFAULT_CONFIG_OBJECT[property];
    });
  },
});
 
module.exports = Config;