Skip to content

Commit

Permalink
Get plugins tests
Browse files Browse the repository at this point in the history
  • Loading branch information
annaet committed Nov 6, 2014
1 parent 3e24601 commit 2e7a97f
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions test/red/api/plugins_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright 2014 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

var should = require("should");
var request = require('supertest');
var express = require('express');
var sinon = require('sinon');
var when = require('when');

var app = express();
var redNodes = require("../../../red/nodes");
var server = require("../../../red/server");
var settings = require("../../../red/settings");

var plugins = require("../../../red/api/plugins");

describe("plugins api", function() {

var app;

before(function() {
app = express();
app.use(express.json());
app.get("/plugins",plugins.getAll);
app.get("/plugins/:id",plugins.get);
});

describe('get plugins', function() {
it('returns plugins list', function(done) {
var getPluginList = sinon.stub(redNodes,'getPluginList', function() {
return [1,2,3];
});
request(app)
.get('/plugins')
.expect(200)
.end(function(err,res) {
getPluginList.restore();
if (err) {
throw err;
}
res.body.should.be.an.Array.and.have.lengthOf(3);
done();
});
});

it('returns an individual plugin info', function(done) {
var getPluginInfo = sinon.stub(redNodes,'getPluginInfo', function(id) {
return {"name":"123", "nodes":[1,2,3]};
});
request(app)
.get('/plugins/123')
.expect(200)
.end(function(err,res) {
getPluginInfo.restore();
if (err) {
throw err;
}
res.body.should.have.property("name","123");
res.body.should.have.property("nodes",[1,2,3]);
done();
});
});
});
});

0 comments on commit 2e7a97f

Please sign in to comment.