diff --git a/packages/server/__mocks__/ioredis.ts b/packages/server/__mocks__/ioredis.ts deleted file mode 100644 index 889f4355c4..0000000000 --- a/packages/server/__mocks__/ioredis.ts +++ /dev/null @@ -1,15 +0,0 @@ -// @ts-nocheck - -const Redis = function () { - this.get = jest.fn().mockResolvedValue({ response: "value" }) - this.set = jest.fn().mockResolvedValue({ response: "OK" }) - this.del = jest.fn().mockResolvedValue({ value: 1 }) - this.disconnect = jest.fn() - this.pipeline = jest.fn(() => ({ - exec: jest.fn().mockResolvedValue([[null, ["result"]]]), - })) - - this.close = jest.fn() -} - -module.exports = Redis diff --git a/packages/server/package.json b/packages/server/package.json index cfcba8059c..8fcc56cb80 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -155,6 +155,7 @@ "copyfiles": "^2.4.1", "docker-compose": "^0.23.6", "eslint": "^6.8.0", + "ioredis-mock": "^7.2.0", "is-wsl": "^2.2.0", "jest": "^27.0.5", "jest-openapi": "^0.14.2", diff --git a/packages/server/src/integrations/tests/redis.spec.js b/packages/server/src/integrations/tests/redis.spec.js index f68bc03fc2..219584bdb2 100644 --- a/packages/server/src/integrations/tests/redis.spec.js +++ b/packages/server/src/integrations/tests/redis.spec.js @@ -1,10 +1,16 @@ -const redis = require("ioredis") +const Redis = require("ioredis-mock") const RedisIntegration = require("../redis") -jest.mock("ioredis") class TestConfiguration { constructor(config = {}) { this.integration = new RedisIntegration.integration(config) + this.redis = new Redis({ + data: { + test: 'test', + result: "1" + }, + }) + this.integration.client = this.redis } } @@ -21,7 +27,7 @@ describe("Redis Integration", () => { value: "value" } const response = await config.integration.create(body) - expect(config.integration.client.set).toHaveBeenCalledWith(body.key, body.value) + expect(await config.redis.get("key")).toEqual("value") }) it("calls the read method with the correct params", async () => { @@ -29,17 +35,15 @@ describe("Redis Integration", () => { key: "test" } const response = await config.integration.read(body) - expect(config.integration.client.get).toHaveBeenCalledWith(body.key) - expect(response).toEqual(expect.any(Object)) + expect(response).toEqual("test") }) it("calls the delete method with the correct params", async () => { const body = { key: "test" } - const response = await config.integration.delete(body) - expect(config.integration.client.del).toHaveBeenCalledWith(body.key) - expect(response).toEqual(expect.any(Object)) + await config.integration.delete(body) + expect(await config.redis.get(body.key)).toEqual(null) }) it("calls the command method with the correct params", async () => { @@ -47,9 +51,10 @@ describe("Redis Integration", () => { json: "KEYS *" } - const response = await config.integration.command(body) + // ioredis-mock doesn't support pipelines + config.integration.client.pipeline = jest.fn(() => ({ exec: jest.fn(() => [[]]) })) + await config.integration.command(body) expect(config.integration.client.pipeline).toHaveBeenCalledWith([["KEYS", "*"]]) - expect(response).toEqual(expect.any(Array)) }) }) \ No newline at end of file diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 845185f12c..ec2bbc9398 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -995,10 +995,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@^1.0.98-alpha.9": - version "1.0.103" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.103.tgz#283f2ccf14fd32962c6abe1f653796fb315b2c06" - integrity sha512-swnmPWQwgjQoNinl2G8rGZHts/fZ9mYI5zzzZpLMHVElrxp7Y7FueNNXX1x6wYlfSlNH4eVhbkWkyh/5Q07j9Q== +"@budibase/backend-core@^1.0.105-alpha.0": + version "1.0.113" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.113.tgz#4ae128eea13126227e9147a1f1703ad12a25c1c6" + integrity sha512-lYV8AYGxj1ggbhEmE1IPLgguEJa8lkCbilmDGLCSttXwz4teXGlxmWl1Wrssheh2StJTvD7AJth414DUHvNmNw== dependencies: "@techpass/passport-openidconnect" "^0.3.0" aws-sdk "^2.901.0" @@ -1068,13 +1068,13 @@ svelte-flatpickr "^3.2.3" svelte-portal "^1.0.0" -"@budibase/bbui@^1.0.103": - version "1.0.103" - resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.0.103.tgz#c600821766a7fe4e9fc21f223fd870326d275cdf" - integrity sha512-F15dxHTD95WAlql7lxL+tw8+uAzYmjArOAOzEhS8DjWU1QPkJsAi+OnGnarz00OrxbXvFLJeh6E+ez3TknkxJA== +"@budibase/bbui@^1.0.113": + version "1.0.113" + resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.0.113.tgz#8d1823d5b0bda4319232643456dc9ca9d14ebbd4" + integrity sha512-PCMwwmeapT6Ec/a+oZtasBwIzozSJPW9bM/fJvusm197M8jp7Qm77Ywk28NU2yE/KsTQ8So7aDgH60S/F5cPoQ== dependencies: "@adobe/spectrum-css-workflow-icons" "^1.2.1" - "@budibase/string-templates" "^1.0.103" + "@budibase/string-templates" "^1.0.113" "@spectrum-css/actionbutton" "^1.0.1" "@spectrum-css/actiongroup" "^1.0.1" "@spectrum-css/avatar" "^3.0.2" @@ -1120,14 +1120,14 @@ svelte-flatpickr "^3.2.3" svelte-portal "^1.0.0" -"@budibase/client@^1.0.98-alpha.9": - version "1.0.103" - resolved "https://registry.yarnpkg.com/@budibase/client/-/client-1.0.103.tgz#041b15476c7aa284cbabf1b429aa00d2bf4b9367" - integrity sha512-6R2Z89Mm8mjlTavIW+LfvnIIt+gJ4AJPLygm2QHpl4FfjgwHq3Kp7tuyjs7Fgwz54YwPS2GeAoOGWZFkHn5usA== +"@budibase/client@^1.0.105-alpha.0": + version "1.0.113" + resolved "https://registry.yarnpkg.com/@budibase/client/-/client-1.0.113.tgz#1da61320d487991aca562dd316641b81ae7fcd4f" + integrity sha512-kv529O0z/ZeSeseqkEf87Lq7U4tZ1Vo3cyDi+QDvYhzwANJsDcOVks9Egy7bfeJuoN/KzvO8nNsih8A7ac/v9A== dependencies: - "@budibase/bbui" "^1.0.103" - "@budibase/frontend-core" "^1.0.103" - "@budibase/string-templates" "^1.0.103" + "@budibase/bbui" "^1.0.113" + "@budibase/frontend-core" "^1.0.113" + "@budibase/string-templates" "^1.0.113" "@spectrum-css/button" "^3.0.3" "@spectrum-css/card" "^3.0.3" "@spectrum-css/divider" "^1.0.3" @@ -1150,12 +1150,12 @@ svelte-flatpickr "^3.1.0" svelte-spa-router "^3.0.5" -"@budibase/frontend-core@^1.0.103": - version "1.0.103" - resolved "https://registry.yarnpkg.com/@budibase/frontend-core/-/frontend-core-1.0.103.tgz#68f6b903dd71188bd4ed181853ceccbf3cb2e99e" - integrity sha512-A+nC1H2MyH486qvAT5AkKIW3kwaf6EvsiWez0wXqGJsF4ujQrjytYZm1sIArj+Js/71cgJBFSd+tX5jALzEbUA== +"@budibase/frontend-core@^1.0.113": + version "1.0.113" + resolved "https://registry.yarnpkg.com/@budibase/frontend-core/-/frontend-core-1.0.113.tgz#833909617a96f752ce16beb9b4005b825ebd1930" + integrity sha512-5abbJJ9ZUETNtELda559mkEDHtUD68zgo3gEaixJx6pq0A2Uni6KUAsRlkBJN1ucR8fXf5RJ3RexeoeQTXQ/MA== dependencies: - "@budibase/bbui" "^1.0.103" + "@budibase/bbui" "^1.0.113" lodash "^4.17.21" svelte "^3.46.2" @@ -1202,10 +1202,10 @@ svelte-apexcharts "^1.0.2" svelte-flatpickr "^3.1.0" -"@budibase/string-templates@^1.0.103", "@budibase/string-templates@^1.0.98-alpha.9": - version "1.0.103" - resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-1.0.103.tgz#7d9eb5e066af29fa488c9eeb88bf470838b7bb51" - integrity sha512-CpPP4kBrvWtXYatMz1uROuLPN5VYqcvNmMcfal3pw2kCimGycFGYz/A2wkQ0UTt5ZSmNGAAGDSqgIH2PwCaTzg== +"@budibase/string-templates@^1.0.105-alpha.0", "@budibase/string-templates@^1.0.113": + version "1.0.113" + resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-1.0.113.tgz#96c1d578d40795495c634f9d0fe021188c0dc410" + integrity sha512-Dr3YMAc6nF/THiakPCxUPOiAVn/cApkdYXomnPvYrmmfMxOMz3s4GJCXHIpoSY/tbhkM+MFNW0foHn6HMAubYw== dependencies: "@budibase/handlebars-helpers" "^0.11.8" dayjs "^1.10.4" @@ -5903,6 +5903,20 @@ fecha@^4.2.0: resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.1.tgz#0a83ad8f86ef62a091e22bb5a039cd03d23eecce" integrity sha512-MMMQ0ludy/nBs1/o0zVOiKTpG7qMbonKUzjJgQFEuvq6INZ1OraKPRAWkBq5vlKLOUMpmNYG1JoN3oDPUQ9m3Q== +fengari-interop@^0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/fengari-interop/-/fengari-interop-0.1.3.tgz#3ad37a90e7430b69b365441e9fc0ba168942a146" + integrity sha512-EtZ+oTu3kEwVJnoymFPBVLIbQcCoy9uWCVnMA6h3M/RqHkUBsLYp29+RRHf9rKr6GwjubWREU1O7RretFIXjHw== + +fengari@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/fengari/-/fengari-0.1.4.tgz#72416693cd9e43bd7d809d7829ddc0578b78b0bb" + integrity sha512-6ujqUuiIYmcgkGz8MGAdERU57EIluGGPSUgGPTsco657EHa+srq0S3/YUl/r9kx1+D+d4rGfYObd+m8K22gB1g== + dependencies: + readline-sync "^1.4.9" + sprintf-js "^1.1.1" + tmp "^0.0.33" + fetch-cookie@0.10.1: version "0.10.1" resolved "https://registry.yarnpkg.com/fetch-cookie/-/fetch-cookie-0.10.1.tgz#5ea88f3d36950543c87997c27ae2aeafb4b5c4d4" @@ -7058,6 +7072,16 @@ invert-kv@^2.0.0: resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02" integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA== +ioredis-mock@^7.2.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/ioredis-mock/-/ioredis-mock-7.2.0.tgz#48f006c07ef7f1f93f75e60d8f9035fa46c4ef0a" + integrity sha512-xzABBG3NhfDBGxH1KX9n6vs7WGNn9lhcxMT3b+vjynVImxlUV+vOXU+tjGzSUnGmx4IYllA8RqbXN8z6ROMPVA== + dependencies: + fengari "^0.1.4" + fengari-interop "^0.1.3" + redis-commands "^1.7.0" + standard-as-callback "^2.1.0" + ioredis@^4.27.0: version "4.28.0" resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.28.0.tgz#5a2be3f37ff2075e2332f280eaeb02ab4d9ff0d3" @@ -11285,6 +11309,11 @@ readdirp@~3.6.0: dependencies: picomatch "^2.2.1" +readline-sync@^1.4.9: + version "1.4.10" + resolved "https://registry.yarnpkg.com/readline-sync/-/readline-sync-1.4.10.tgz#41df7fbb4b6312d673011594145705bf56d8873b" + integrity sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw== + realpath-native@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/realpath-native/-/realpath-native-1.1.0.tgz#2003294fea23fb0672f2476ebe22fcf498a2d65c" @@ -11326,7 +11355,7 @@ rechoir@^0.7.0: dependencies: resolve "^1.9.0" -redis-commands@1.7.0: +redis-commands@1.7.0, redis-commands@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.7.0.tgz#15a6fea2d58281e27b1cd1acfb4b293e278c3a89" integrity sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ== @@ -12179,7 +12208,7 @@ split2@^3.1.1: dependencies: readable-stream "^3.0.0" -sprintf-js@^1.1.2: +sprintf-js@^1.1.1, sprintf-js@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.2.tgz#da1765262bf8c0f571749f2ad6c26300207ae673" integrity sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==