/** * 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://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 fs = require("fs"); var path = require("path"); var settings = require("../../../red/settings"); var events = require("../../../red/events"); var ui = require("../../../red/api/ui"); describe("ui api", function() { var app; describe("slash handler", function() { before(function() { app = express(); app.get("/foo",ui.ensureSlash,function(req,res) { res.send(200);}); }); it('redirects if the path does not end in a slash',function(done) { request(app) .get('/foo') .expect(301,done); }); it('does not redirect if the path ends in a slash',function(done) { request(app) .get('/foo/') .expect(200,done); }); }); describe("icon handler", function() { before(function() { app = express(); app.get("/icons/:icon",ui.icon); }); function binaryParser(res, callback) { res.setEncoding('binary'); res.data = ''; res.on('data', function (chunk) { res.data += chunk; }); res.on('end', function () { callback(null, new Buffer(res.data, 'binary')); }); } function compareBuffers(b1,b2) { b1.length.should.equal(b2.length); for (var i=0;i