-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathportal.spec.js
94 lines (71 loc) · 2.05 KB
/
portal.spec.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var request = require('request')
, sinon = require('sinon')
, chai = require('chai')
, config = require('nconf')
, EsriPortal = require('../index');
var expect = chai.expect;
var spyLogger, ago, configObj;
xdescribe('portal', function () {
before(function(done){
//setup a spy logger
spyLogger = {
info : function(obj) {
console.info(obj);
},
error : sinon.spy()
};
//setup the configuration for the tests
configObj = {
"ago": {
"rest": "http://fakeago.com/rest"
}
}
config.add('test', { type: 'literal', store: configObj });
//all done!
done();
});
// after(function(done){
// //reset the stub
// request.get.restore();
// done();
// });
beforeEach(function() {
ago = new EsriPortal({config:config, logger:spyLogger});
});
describe('portal.self', function () {
afterEach(function(done) {
if(request.get.restore){
request.get.restore();
}
done();
});
it("should call portal/self with token", function(done) {
sinon.stub(request, 'get', function(url, cb){
cb(null, {}, JSON.stringify({mock:"data"}) );
});
ago.portal.self('some-fake-token')
.then(function(selfJson){
expect(request.get.called).to.be.true();
expect(request.get.args[0][0]).to.equal('http://fakeago.com/rest/portals/self?f=json&token=some-fake-token');
done();
})
.done();
});
it("should reject on error payload", function(done) {
sinon.stub(request, 'get', function(url, cb){
cb(null, {}, JSON.stringify({error:"fake error"}) );
});
ago.portal.self('some-fake-token')
.then(function(selfJson){
//
expect(true).to.be.false();
})
.fail(function(error){
expect(request.get.called).to.be.true();
expect(request.get.args[0][0]).to.equal('http://fakeago.com/rest/portals/self?f=json&token=some-fake-token');
done();
})
.done();
});
});
});