Code coverage report for models/AjaxFormCall.js

Statements: 100% (84 / 84)      Branches: 100% (36 / 36)      Functions: 100% (16 / 16)      Lines: 100% (24 / 24)      Ignored: 16 statements, 15 branches     

All files » models/ » AjaxFormCall.js
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 64 65 66 67 68 69 70 71 72 73 74 75 76                    1 1                           1 7 7 7       34       7 7       16       17 17       2       10 10   10 7     10   10       2 2 2   2        
/**
 * AjaxFormCall class
 *
 * @module AjaxFormCall
 *
 * @author Luca Pau <luca.pau82@gmail.com>
 */
 
import AjaxCall from './AjaxCall';
 
let _errors = Symbol();
let _countErrors = Symbol();
 
/**
 * AjaxFormCall class
 *
 * Perform ajax call for forms
 *
 * @class AjaxFormCall
 * @extends AjaxCall
 */
class AjaxFormCall extends AjaxCall {
  /**
   * @constructor
   */
  constructor() {
    super();
    this.errors = {};
    this.countErrors = 0;
  }
 
  get errors() {
    return this[_errors];
  }
 
  set errors(errors) {
    this[_errors] = errors;
    return this;
  }
 
  get countErrors() {
    return this[_countErrors];
  }
 
  set countErrors(countErrors) {
    this[_countErrors] = countErrors;
    return this;
  }
 
  hasError() {
    return this.countErrors !== 0;
  }
 
  addError(name, error) {
    this.result = 400;
    this.countErrors++;
 
    if (!(name in this.errors)) {
      this.errors[name] = [];
    }
 
    this.errors[name].push(error);
 
    return this;
  }
 
  getStruct() {
    var superStruct = super.getStruct();
    superStruct.errors = this.errors;
    superStruct.countErrors = this.countErrors;
 
    return superStruct;
  }
}
 
export default AjaxFormCall;