All files / src/elements OpenGraphElement.js

100% Statements 8/8
100% Branches 5/5
100% Functions 1/1
100% Lines 8/8

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        4x 4x   4x       4x 3x 1x   2x     3x          
import { OPEN_GRAPH_MAX_BUTTONS } from '../constants';
 
class OpenGraphElement {
  constructor({ url, buttons = [] }) {
    this.url = url;
    this.buttons = buttons;
 
    const res = {
      url: this.url,
    };
 
    if (this.buttons.length) {
      if (this.buttons.length > OPEN_GRAPH_MAX_BUTTONS) {
        throw new Error(`Open graph templates sent via the Send API support a maximum of ${OPEN_GRAPH_MAX_BUTTONS} buttons of any type.`);
      }
      res.buttons = this.buttons;
    }
 
    return res;
  }
}
 
export default OpenGraphElement;