3 var BackendMuxer = require('../lib/backend-muxer');
4 var assert = require('assert');
5 var Promise = require('bluebird');
7 describe('backend-muxer', function() {
8 describe('getFirstResultForBackends', function() {
9 var getFirstResultForBackends = BackendMuxer.testOnly.getFirstResultForBackends;
10 var backend1, backend2, results;
12 beforeEach(function() {
15 backendFn: function() {
16 return Promise.resolve(results[0]);
20 backendFn: function() {
21 return Promise.resolve(results[1]);
26 it('should handle zero backends', function() {
27 var fn = getFirstResultForBackends('backendFn', []);
28 return fn([]).then(function(result) {
33 it('should handle a single backends', function() {
34 var fn = getFirstResultForBackends('backendFn', []);
36 return fn([backend1]).then(function(result) {
37 assert.strictEqual(result, 1);
41 it('should return the first backend if it returns a result', function() {
42 var fn = getFirstResultForBackends('backendFn', []);
45 return fn([backend1, backend2]).then(function(result) {
46 assert.strictEqual(result, 1);
50 it('should return the first second if the first does not return a result', function() {
51 var fn = getFirstResultForBackends('backendFn', []);
54 return fn([backend1, backend2]).then(function(result) {
55 assert.strictEqual(result, 2);
59 it('should return nothing if no backends return a result', function() {
60 var fn = getFirstResultForBackends('backendFn', []);
62 return fn([backend1, backend2]).then(function(result) {
68 describe('resolveUserBackends', function() {
69 it('should return an empty array for an anonymous user', function() {
70 var resolveUserBackends = BackendMuxer.testOnly.resolveUserBackends;
71 return resolveUserBackends(null).then(function(backends) {
72 assert.strictEqual(backends.length, 0);