From 31a554d94fb96e93edab1bb59aa3ce165985dc53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Sat, 3 Mar 2018 14:46:58 +0100 Subject: [PATCH] updating tests to use cartodb-redis --- test/acceptance/rate-limit.test.js | 5 +- test/unit/cartodb/rate-limit.test.js | 108 --------------------------- 2 files changed, 2 insertions(+), 111 deletions(-) delete mode 100644 test/unit/cartodb/rate-limit.test.js diff --git a/test/acceptance/rate-limit.test.js b/test/acceptance/rate-limit.test.js index afcf8952..c14a1c9d 100644 --- a/test/acceptance/rate-limit.test.js +++ b/test/acceptance/rate-limit.test.js @@ -8,7 +8,6 @@ const TestClient = require('../support/test-client'); const UserLimitsApi = require('../../lib/cartodb/api/user_limits_api'); const rateLimitMiddleware = require('../../lib/cartodb/middleware/rate-limit'); const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitMiddleware; -const { getStoreKey } = require('../../lib/cartodb/api/user_limits_api'); let userLimitsApi; let rateLimit; @@ -75,7 +74,7 @@ function setLimit(count, period, burst) { return; } - const key = getStoreKey(user, RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS); + const key = `limits:rate:store:${user}:maps:${RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS}`; redisClient.rpush(key, burst); redisClient.rpush(key, count); redisClient.rpush(key, period); @@ -109,7 +108,7 @@ function assertGetLayergroupRequest (status, limit, remaining, reset, retry, don 'X-Rate-Limit-Retry-After': retry } }; - + testClient.getLayergroup({ response }, err => { assert.ifError(err); if (done) { diff --git a/test/unit/cartodb/rate-limit.test.js b/test/unit/cartodb/rate-limit.test.js deleted file mode 100644 index 1dc6dfc4..00000000 --- a/test/unit/cartodb/rate-limit.test.js +++ /dev/null @@ -1,108 +0,0 @@ -require('../../support/test_helper'); - -const assert = require('assert'); -const { getLowerRateLimit } = require('../../../lib/cartodb/api/user_limits_api'); - - -describe('Lower rate limit', function () { - it("1 limit: not limited", function (done) { - const limits = [[0, 3, 1, -1, 1]]; - const result = getLowerRateLimit(limits); - assert.deepEqual(limits[0], result); - done(); - }); - - it("1 limit: limited", function (done) { - const limits = [[1, 3, 0, 0, 1]]; - const result = getLowerRateLimit(limits); - assert.deepEqual(limits[0], result); - done(); - }); - - it("empty or invalid", function (done) { - let limits = []; - let result = getLowerRateLimit(limits); - assert.deepEqual(null, result); - - limits = undefined; - result = getLowerRateLimit(limits); - assert.deepEqual(null, result); - - limits = null; - result = getLowerRateLimit(limits); - assert.deepEqual(null, result); - - limits = [[]]; - result = getLowerRateLimit(limits); - assert.deepEqual(null, result); - - limits = [[], []]; - result = getLowerRateLimit(limits); - assert.deepEqual(null, result); - - limits = {}; - result = getLowerRateLimit(limits); - assert.deepEqual(null, result); - - limits = [{}]; - result = getLowerRateLimit(limits); - assert.deepEqual(null, result); - - limits = [[1, 2]]; - result = getLowerRateLimit(limits); - assert.deepEqual(null, result); - - done(); - }); - - it("multiple limits: valid and invalid", function (done) { - const limit1 = [0, 3, 0]; - const limit2 = [0, 3, 1, 0, 1]; - - let limits = [limit1, limit2]; - let result = getLowerRateLimit(limits); - assert.deepEqual(limit2, result); - - limits = [limit2, limit1]; - result = getLowerRateLimit(limits); - assert.deepEqual(limit2, result); - - done(); - }); - - it("multiple limits: not limited", function (done) { - const limit1 = [0, 3, 2, 0, 1]; - const limit2 = [0, 3, 3, 0, 1]; - const limit3 = [0, 3, 1, 0, 1]; - const limit4 = [0, 3, 4, 0, 1]; - const limit5 = [0, 3, 5, 0, 1]; - - let limits = [limit1, limit2, limit3, limit4, limit5]; - let result = getLowerRateLimit(limits); - assert.deepEqual(limit3, result); - - limits = [limit1, limit2]; - result = getLowerRateLimit(limits); - assert.deepEqual(limit1, result); - - done(); - }); - - it("multiple limits: limited", function (done) { - const limit1 = [0, 3, 2, 0, 1]; - const limit2 = [0, 3, 3, 0, 1]; - const limit3 = [0, 3, 1, 0, 1]; - const limit4 = [0, 3, 4, 0, 1]; - const limit5 = [1, 3, 5, 0, 1]; - - let limits = [limit1, limit2, limit3, limit4, limit5]; - let result = getLowerRateLimit(limits); - assert.deepEqual(limit5, result); - - limits = [limit1, limit2, limit5, limit3, limit4]; - result = getLowerRateLimit(limits); - assert.deepEqual(limit5, result); - - done(); - }); -});