aboutsummaryrefslogtreecommitdiffstats
path: root/helpers/FakeHttpProvider2.js
blob: e287a0745108a6846cfddb38a54ab77086e4bf63 (plain) (blame)
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
var FakeHttpProvider = require('./FakeHttpProvider');

var FakeHttpProvider2 = function () {
    this.counter = 0;
    this.resultList = [];
};

FakeHttpProvider2.prototype = new FakeHttpProvider();
FakeHttpProvider2.prototype.constructor = FakeHttpProvider2;

FakeHttpProvider2.prototype.injectResultList = function (list) {
    this.resultList = list;
};

FakeHttpProvider2.prototype.getResponse = function () {
    var result = this.resultList[this.counter];
    this.counter++;

    // add fallback result value
    if(!result)
        result = {
            result: undefined
        };

    if (result.type === 'batch') {
        this.injectBatchResults(result.result);
    } else {
        this.injectResult(result.result);
    }

    this.counter = 0;

    return this.response;
};

module.exports = FakeHttpProvider2;