[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / test / red / cli / lib / request_spec.js
1 /**
2  * Copyright 2014 IBM Corp.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  **/
16  
17 var should = require("should");
18 var sinon = require("sinon");
19 var fs = require("fs");
20 var request = require("request");
21
22 var apiRequest = require("../../../../red/cli/lib/request");
23 var config = require("../../../../red/cli/lib/config");
24
25 describe("cli request", function() {
26     var sandbox = sinon.sandbox.create();
27     before(function() {
28         sandbox.stub(fs,"readFileSync",function() {
29             return '{"target":"http://example.com:1880"}'
30         });
31     });
32     after(function() {
33         sandbox.restore();
34     });
35                 
36     it('returns the json response to a get', sinon.test(function(done) {
37         this.stub(request, 'get').yields(null, {statusCode:200}, JSON.stringify({a: "b"}));
38             
39         apiRequest("/foo",{}).then(function(res) {
40             res.should.eql({a:"b"});
41             done();
42         }).otherwise(function(err) {
43             done(err);
44         });
45     }));
46 });