From 045641bb6c76898262b56a75f8b3a8ac76e5e308 Mon Sep 17 00:00:00 2001 From: analog-nico Date: Mon, 21 Sep 2015 21:08:45 +0200 Subject: [PATCH] More tests --- test/spec/local-server.js | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/test/spec/local-server.js b/test/spec/local-server.js index 9ad1888..caf46ec 100644 --- a/test/spec/local-server.js +++ b/test/spec/local-server.js @@ -505,6 +505,58 @@ describe('Local Server', function () { }); + it('should limit all resources with a rule that defines none', function () { + + var quotaManager = new quota.Manager(); + quotaManager.addRule({ + limit: 2, + throttling: 'limit-absolute', + resource: 'resA' + }); + quotaManager.addRule({ + limit: 2, + throttling: 'limit-absolute', + resource: 'resB' + }); + quotaManager.addRule({ + limit: 1, + throttling: 'limit-absolute' + }); + + var quotaServer = new quota.Server(); + quotaServer.addManager('test', quotaManager); + + var quotaClient = new quota.Client(quotaServer); + + return BPromise.resolve() + .then(function () { + return quotaClient.requestQuota('test', undefined, { 'resA': 1 }); + }) + .then(function () { + + return quotaClient.requestQuota('test', undefined, { 'resA': 1 }) + .then(function () { + throw new Error('Expected OutOfQuotaError'); + }) + .catch(quota.OutOfQuotaError, function (err) { + return; // Expected + }); + + }) + .then(function () { + + return quotaClient.requestQuota('test', undefined, { 'resB': 1 }) + .then(function () { + throw new Error('Expected OutOfQuotaError'); + }) + .catch(quota.OutOfQuotaError, function (err) { + return; // Expected + }); + + }); + + }); + it('should not grant request for unknown resource', function () { var quotaManager = new quota.Manager(); @@ -529,6 +581,30 @@ describe('Local Server', function () { }); + it('should not grant request for empty resource object', function () { + + var quotaManager = new quota.Manager(); + quotaManager.addRule({ + limit: 1, + throttling: 'limit-absolute', + resource: 'known' + }); + + var quotaServer = new quota.Server(); + quotaServer.addManager('test', quotaManager); + + var quotaClient = new quota.Client(quotaServer); + + return quotaClient.requestQuota('test', undefined, { }) + .then(function () { + throw new Error('Expected OutOfQuotaError'); + }) + .catch(quota.OutOfQuotaError, function (err) { + return; // Expected + }); + + }); + }); describe('with two managers', function () {