
Tinytest.add(
  'Models - Errors - empty',
  function (test) {
    var model = new ErrorModel('_appId');
    var metrics = model.buildPayload().errors;
    test.isTrue(Array.isArray(metrics));
    test.equal(metrics.length, 0);
  }
);

Tinytest.add(
  'Models - Errors - simple',
  function (test) {
    var model = new ErrorModel('_appId');
    var error = {name: '_name', message: '_message', stack: '_stack'};
    var trace = {type: '_type', name: '_name'};
    model.trackError(error, trace);
    var metrics = model.buildPayload().errors;
    test.isTrue(Array.isArray(metrics));
    test.equal(metrics.length, 1);
    var payload = metrics[0];
    var expected = {
      appId: '_appId',
      name: '_message',
      source: '_type:_name',
      // startTime: Date.now(),
      type: 'server',
      trace: trace,
      stacks: [{stack: '_stack'}],
      count: 1,
    };
    test.equal(typeof payload.startTime, 'number');
    delete payload.startTime;
    test.equal(payload, expected);
  }
);

Tinytest.add(
  'Models - Errors - same error',
  function (test) {
    var model = new ErrorModel('_appId');
    var error = {name: '_name', message: '_message', stack: '_stack'};
    var trace = {type: '_type', name: '_name'};
    model.trackError(error, trace);
    model.trackError(error, trace);
    model.trackError(error, trace);
    var metrics = model.buildPayload().errors;
    test.isTrue(Array.isArray(metrics));
    test.equal(metrics.length, 1);
    var payload = metrics[0];
    var expected = {
      appId: '_appId',
      name: '_message',
      source: '_type:_name',
      // startTime: Date.now(),
      type: 'server',
      trace: trace,
      stacks: [{stack: '_stack'}],
      count: 3,
    };
    test.equal(typeof payload.startTime, 'number');
    delete payload.startTime;
    test.equal(payload, expected);
  }
);

Tinytest.add(
  'Models - Errors - different errors',
  function (test) {
    var model = new ErrorModel('_appId');
    [1, 2, 3].forEach(function(n) {
      var error = {name: '_name'+n, message: '_message'+n, stack: '_stack'+n};
      var trace = {type: '_type'+n, name: '_name'+n};
      model.trackError(error, trace);
    });

    var metrics = model.buildPayload().errors;
    test.isTrue(Array.isArray(metrics));
    test.equal(metrics.length, 3);

    [1, 2, 3].forEach(function(n) {
      var payload = metrics[n-1];
      var trace = {type: '_type'+n, name: '_name'+n};
      var expected = {
        appId: '_appId',
        name: '_message'+n,
        source: '_type'+n+':_name'+n,
        // startTime: Date.now(),
        type: 'server',
        trace: trace,
        stacks: [{stack: '_stack'+n}],
        count: 1,
      };
      test.equal(typeof payload.startTime, 'number');
      delete payload.startTime;
      test.equal(payload, expected);
    });
  }
);

@@ -269,14 +269,718 @@
 s - 
-simple
+add errors to model',%0A  function (test) %7B%0A    var model = new ErrorModel('_appId');%0A    var error = %7Bname: '_name', message: '_message', stack: '_stack'%7D;%0A    var trace = %7Btype: '_type', name: '_name'%7D;%0A    model.trackError(error, trace);%0A    var storedMetric = model.errors%5B'_type:_message'%5D;%0A    var expected = %7B%0A      appId: '_appId',%0A      name: '_message',%0A      source: '_type:_name',%0A      // startTime: Date.now(),%0A      type: 'server',%0A      trace: trace,%0A      stacks: %5B%7Bstack: '_stack'%7D%5D,%0A      count: 1,%0A    %7D;%0A    test.equal(typeof storedMetric.startTime, 'number');%0A    delete storedMetric.startTime;%0A    test.equal(storedMetric, expected);%0A  %7D%0A);%0A%0ATinytest.add(%0A  'Models - Errors - buildPayload
 ',%0A 
@@ -1736,16 +1736,486 @@
 Errors -
+ clear data after buildPayload',%0A  function (test) %7B%0A    var model = new ErrorModel('_appId');%0A    var error = %7Bname: '_name', message: '_message', stack: '_stack'%7D;%0A    var trace = %7Btype: '_type', name: '_name'%7D;%0A    model.trackError(error, trace);%0A    test.equal(true, !!model.errors%5B'_type:_message'%5D);%0A    var metrics = model.buildPayload().errors;%0A    test.equal(false, !!model.errors%5B'_type:_message'%5D);%0A  %7D%0A);%0A%0ATinytest.add(%0A  'Models - Errors - buildPayload with
  same er
@@ -2217,16 +2217,24 @@
 me error
+ message
 ',%0A  fun
@@ -3058,16 +3058,34 @@
 Errors -
+ buildPayload with
  differe
@@ -3092,16 +3092,24 @@
 nt error
+ message
 s',%0A  fu

Refactor server tests