diff --git a/.eslintrc.json b/.eslintrc.json index ae9512152f..4b2b523137 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -34,18 +34,42 @@ }, { "files": ["**/*.ts"], + "excludedFiles": ["qa-core/**"], "parser": "@typescript-eslint/parser", "extends": ["eslint:recommended"], "rules": { "no-unused-vars": "off", "no-inner-declarations": "off", "no-case-declarations": "off", - "no-useless-escape": "off", "no-undef": "off", "no-prototype-builtins": "off", - "local-rules/no-budibase-imports": "error", + "local-rules/no-budibase-imports": "error" + } + }, + { + "files": ["**/*.spec.ts"], + "excludedFiles": ["qa-core/**"], + "parser": "@typescript-eslint/parser", + "plugins": ["jest"], + "extends": ["eslint:recommended", "plugin:jest/recommended"], + "env": { + "jest/globals": true + }, + "rules": { + "no-unused-vars": "off", + "no-inner-declarations": "off", + "no-case-declarations": "off", + "no-undef": "off", + "no-prototype-builtins": "off", "local-rules/no-test-com": "error", - "local-rules/email-domain-example-com": "error" + "local-rules/email-domain-example-com": "error", + "no-console": "warn", + // We have a lot of tests that don't have assertions, they use our test + // API client that does the assertions for them + "jest/expect-expect": "off", + // We do this in some tests where the behaviour of internal tables + // differs to external, but the API is broadly the same + "jest/no-conditional-expect": "off" } }, { diff --git a/eslint-local-rules/index.js b/eslint-local-rules/index.js index 202e52e70e..a4866bc1f8 100644 --- a/eslint-local-rules/index.js +++ b/eslint-local-rules/index.js @@ -25,11 +25,9 @@ module.exports = { docs: { description: "disallow the use of 'test.com' in strings and replace it with 'example.com'", - category: "Possible Errors", - recommended: false, }, - schema: [], // no options - fixable: "code", // Indicates that this rule supports automatic fixing + schema: [], + fixable: "code", }, create: function (context) { return { @@ -58,8 +56,6 @@ module.exports = { docs: { description: "enforce using the example.com domain for generator.email calls", - category: "Possible Errors", - recommended: false, }, fixable: "code", schema: [], diff --git a/lerna.json b/lerna.json index b0003be838..01e56982d5 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.22.2", + "version": "2.22.3", "npmClient": "yarn", "packages": [ "packages/*", diff --git a/package.json b/package.json index 0a20f01d52..af7aac0025 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "esbuild-node-externals": "^1.8.0", "eslint": "^8.52.0", "eslint-plugin-import": "^2.29.0", + "eslint-plugin-jest": "^27.9.0", "eslint-plugin-local-rules": "^2.0.0", "eslint-plugin-svelte": "^2.34.0", "husky": "^8.0.3", diff --git a/packages/account-portal b/packages/account-portal index 23a1219732..6465dc9c2a 160000 --- a/packages/account-portal +++ b/packages/account-portal @@ -1 +1 @@ -Subproject commit 23a1219732bd778654c0bcc4f49910c511e2d51f +Subproject commit 6465dc9c2a38e1380b32204cad4ae0c1f33e065a diff --git a/packages/backend-core/scripts/test.sh b/packages/backend-core/scripts/test.sh index 7d19ec96cc..b9937e3a4a 100644 --- a/packages/backend-core/scripts/test.sh +++ b/packages/backend-core/scripts/test.sh @@ -4,10 +4,10 @@ set -e if [[ -n $CI ]] then # --runInBand performs better in ci where resources are limited - echo "jest --coverage --runInBand --forceExit" - jest --coverage --runInBand --forceExit + echo "jest --coverage --runInBand --forceExit $@" + jest --coverage --runInBand --forceExit $@ else # --maxWorkers performs better in development - echo "jest --coverage --detectOpenHandles" - jest --coverage --detectOpenHandles + echo "jest --coverage --forceExit --detectOpenHandles $@" + jest --coverage --forceExit --detectOpenHandles $@ fi \ No newline at end of file diff --git a/packages/backend-core/src/auth/tests/auth.spec.ts b/packages/backend-core/src/auth/tests/auth.spec.ts index 3ae691be58..a80e1ea739 100644 --- a/packages/backend-core/src/auth/tests/auth.spec.ts +++ b/packages/backend-core/src/auth/tests/auth.spec.ts @@ -8,7 +8,7 @@ describe("platformLogout", () => { await testEnv.withTenant(async () => { const ctx = structures.koa.newContext() await auth.platformLogout({ ctx, userId: "test" }) - expect(events.auth.logout).toBeCalledTimes(1) + expect(events.auth.logout).toHaveBeenCalledTimes(1) }) }) }) diff --git a/packages/backend-core/src/cache/docWritethrough.ts b/packages/backend-core/src/cache/docWritethrough.ts index 1b129bb26a..05f13a0d91 100644 --- a/packages/backend-core/src/cache/docWritethrough.ts +++ b/packages/backend-core/src/cache/docWritethrough.ts @@ -1,6 +1,6 @@ import { AnyDocument, Database } from "@budibase/types" -import { JobQueue, createQueue } from "../queue" +import { JobQueue, Queue, createQueue } from "../queue" import * as dbUtils from "../db" interface ProcessDocMessage { @@ -12,18 +12,26 @@ interface ProcessDocMessage { const PERSIST_MAX_ATTEMPTS = 100 let processor: DocWritethroughProcessor | undefined -export const docWritethroughProcessorQueue = createQueue( - JobQueue.DOC_WRITETHROUGH_QUEUE, - { - jobOptions: { - attempts: PERSIST_MAX_ATTEMPTS, - }, - } -) +export class DocWritethroughProcessor { + private static _queue: Queue + + public static get queue() { + if (!DocWritethroughProcessor._queue) { + DocWritethroughProcessor._queue = createQueue( + JobQueue.DOC_WRITETHROUGH_QUEUE, + { + jobOptions: { + attempts: PERSIST_MAX_ATTEMPTS, + }, + } + ) + } + + return DocWritethroughProcessor._queue + } -class DocWritethroughProcessor { init() { - docWritethroughProcessorQueue.process(async message => { + DocWritethroughProcessor.queue.process(async message => { try { await this.persistToDb(message.data) } catch (err: any) { @@ -76,7 +84,7 @@ export class DocWritethrough { } async patch(data: Record) { - await docWritethroughProcessorQueue.add({ + await DocWritethroughProcessor.queue.add({ dbName: this.db.name, docId: this.docId, data, diff --git a/packages/backend-core/src/cache/tests/docWritethrough.spec.ts b/packages/backend-core/src/cache/tests/docWritethrough.spec.ts index 1ae85cfd0b..47b3f0672f 100644 --- a/packages/backend-core/src/cache/tests/docWritethrough.spec.ts +++ b/packages/backend-core/src/cache/tests/docWritethrough.spec.ts @@ -6,7 +6,7 @@ import { getDB } from "../../db" import { DocWritethrough, - docWritethroughProcessorQueue, + DocWritethroughProcessor, init, } from "../docWritethrough" @@ -15,7 +15,7 @@ import InMemoryQueue from "../../queue/inMemoryQueue" const initialTime = Date.now() async function waitForQueueCompletion() { - const queue: InMemoryQueue = docWritethroughProcessorQueue as never + const queue: InMemoryQueue = DocWritethroughProcessor.queue as never await queue.waitForCompletion() } @@ -235,11 +235,11 @@ describe("docWritethrough", () => { return acc }, {}) } - const queueMessageSpy = jest.spyOn(docWritethroughProcessorQueue, "add") + const queueMessageSpy = jest.spyOn(DocWritethroughProcessor.queue, "add") await config.doInTenant(async () => { let patches = await parallelPatch(5) - expect(queueMessageSpy).toBeCalledTimes(5) + expect(queueMessageSpy).toHaveBeenCalledTimes(5) await waitForQueueCompletion() expect(await db.get(documentId)).toEqual( @@ -247,7 +247,7 @@ describe("docWritethrough", () => { ) patches = { ...patches, ...(await parallelPatch(40)) } - expect(queueMessageSpy).toBeCalledTimes(45) + expect(queueMessageSpy).toHaveBeenCalledTimes(45) await waitForQueueCompletion() expect(await db.get(documentId)).toEqual( @@ -255,7 +255,7 @@ describe("docWritethrough", () => { ) patches = { ...patches, ...(await parallelPatch(10)) } - expect(queueMessageSpy).toBeCalledTimes(55) + expect(queueMessageSpy).toHaveBeenCalledTimes(55) await waitForQueueCompletion() expect(await db.get(documentId)).toEqual( @@ -265,6 +265,7 @@ describe("docWritethrough", () => { }) // This is not yet supported + // eslint-disable-next-line jest/no-disabled-tests it.skip("patches will execute in order", async () => { let incrementalValue = 0 const keyToOverride = generator.word() diff --git a/packages/backend-core/src/cache/tests/user.spec.ts b/packages/backend-core/src/cache/tests/user.spec.ts index 80e5bc3063..49a8d51c16 100644 --- a/packages/backend-core/src/cache/tests/user.spec.ts +++ b/packages/backend-core/src/cache/tests/user.spec.ts @@ -55,8 +55,8 @@ describe("user cache", () => { })), }) - expect(UserDB.bulkGet).toBeCalledTimes(1) - expect(UserDB.bulkGet).toBeCalledWith(userIdsToRequest) + expect(UserDB.bulkGet).toHaveBeenCalledTimes(1) + expect(UserDB.bulkGet).toHaveBeenCalledWith(userIdsToRequest) }) it("on a second all, all of them are retrieved from cache", async () => { @@ -82,7 +82,7 @@ describe("user cache", () => { ), }) - expect(UserDB.bulkGet).toBeCalledTimes(1) + expect(UserDB.bulkGet).toHaveBeenCalledTimes(1) }) it("when some users are cached, only the missing ones are retrieved from db", async () => { @@ -110,8 +110,8 @@ describe("user cache", () => { ), }) - expect(UserDB.bulkGet).toBeCalledTimes(1) - expect(UserDB.bulkGet).toBeCalledWith([ + expect(UserDB.bulkGet).toHaveBeenCalledTimes(1) + expect(UserDB.bulkGet).toHaveBeenCalledWith([ userIdsToRequest[1], userIdsToRequest[2], userIdsToRequest[4], diff --git a/packages/backend-core/src/context/tests/index.spec.ts b/packages/backend-core/src/context/tests/index.spec.ts index cfc820e169..2d89131549 100644 --- a/packages/backend-core/src/context/tests/index.spec.ts +++ b/packages/backend-core/src/context/tests/index.spec.ts @@ -246,7 +246,7 @@ describe("context", () => { context.doInAppMigrationContext(db.generateAppID(), async () => { await otherContextCall() }) - ).rejects.toThrowError( + ).rejects.toThrow( "The context cannot be changed, a migration is currently running" ) } diff --git a/packages/backend-core/src/db/lucene.ts b/packages/backend-core/src/db/lucene.ts index f982ee67d0..7055ec8031 100644 --- a/packages/backend-core/src/db/lucene.ts +++ b/packages/backend-core/src/db/lucene.ts @@ -247,7 +247,7 @@ export class QueryBuilder { } // Escape characters if (!this.#noEscaping && escape && originalType === "string") { - value = `${value}`.replace(/[ \/#+\-&|!(){}\]^"~*?:\\]/g, "\\$&") + value = `${value}`.replace(/[ /#+\-&|!(){}\]^"~*?:\\]/g, "\\$&") } // Wrap in quotes diff --git a/packages/backend-core/src/middleware/matchers.ts b/packages/backend-core/src/middleware/matchers.ts index efbdec2dbe..8bede1cc6a 100644 --- a/packages/backend-core/src/middleware/matchers.ts +++ b/packages/backend-core/src/middleware/matchers.ts @@ -11,7 +11,6 @@ export const buildMatcherRegex = ( return patterns.map(pattern => { let route = pattern.route const method = pattern.method - const strict = pattern.strict ? pattern.strict : false // if there is a param in the route // use a wildcard pattern @@ -24,24 +23,17 @@ export const buildMatcherRegex = ( } } - return { regex: new RegExp(route), method, strict, route } + return { regex: new RegExp(route), method, route } }) } export const matches = (ctx: BBContext, options: RegexMatcher[]) => { - return options.find(({ regex, method, strict, route }) => { - let urlMatch - if (strict) { - urlMatch = ctx.request.url === route - } else { - urlMatch = regex.test(ctx.request.url) - } - + return options.find(({ regex, method, route }) => { + const urlMatch = regex.test(ctx.request.url) const methodMatch = method === "ALL" ? true : ctx.request.method.toLowerCase() === method.toLowerCase() - return urlMatch && methodMatch }) } diff --git a/packages/backend-core/src/middleware/passport/sso/tests/sso.spec.ts b/packages/backend-core/src/middleware/passport/sso/tests/sso.spec.ts index d3486a5b14..ea9584c284 100644 --- a/packages/backend-core/src/middleware/passport/sso/tests/sso.spec.ts +++ b/packages/backend-core/src/middleware/passport/sso/tests/sso.spec.ts @@ -114,11 +114,11 @@ describe("sso", () => { // tenant id added ssoUser.tenantId = context.getTenantId() - expect(mockSaveUser).toBeCalledWith(ssoUser, { + expect(mockSaveUser).toHaveBeenCalledWith(ssoUser, { hashPassword: false, requirePassword: false, }) - expect(mockDone).toBeCalledWith(null, ssoUser) + expect(mockDone).toHaveBeenCalledWith(null, ssoUser) }) }) }) @@ -159,11 +159,11 @@ describe("sso", () => { // existing id preserved ssoUser._id = existingUser._id - expect(mockSaveUser).toBeCalledWith(ssoUser, { + expect(mockSaveUser).toHaveBeenCalledWith(ssoUser, { hashPassword: false, requirePassword: false, }) - expect(mockDone).toBeCalledWith(null, ssoUser) + expect(mockDone).toHaveBeenCalledWith(null, ssoUser) }) }) @@ -187,11 +187,11 @@ describe("sso", () => { // existing id preserved ssoUser._id = existingUser._id - expect(mockSaveUser).toBeCalledWith(ssoUser, { + expect(mockSaveUser).toHaveBeenCalledWith(ssoUser, { hashPassword: false, requirePassword: false, }) - expect(mockDone).toBeCalledWith(null, ssoUser) + expect(mockDone).toHaveBeenCalledWith(null, ssoUser) }) }) }) diff --git a/packages/backend-core/src/middleware/tests/builder.spec.ts b/packages/backend-core/src/middleware/tests/builder.spec.ts index 0514dc13f0..0f35b0b833 100644 --- a/packages/backend-core/src/middleware/tests/builder.spec.ts +++ b/packages/backend-core/src/middleware/tests/builder.spec.ts @@ -24,13 +24,13 @@ function buildUserCtx(user: ContextUser) { } function passed(throwFn: jest.Func, nextFn: jest.Func) { - expect(throwFn).not.toBeCalled() - expect(nextFn).toBeCalled() + expect(throwFn).not.toHaveBeenCalled() + expect(nextFn).toHaveBeenCalled() } function threw(throwFn: jest.Func) { // cant check next, the throw function doesn't actually throw - so it still continues - expect(throwFn).toBeCalled() + expect(throwFn).toHaveBeenCalled() } describe("adminOnly middleware", () => { diff --git a/packages/backend-core/src/middleware/tests/matchers.spec.ts b/packages/backend-core/src/middleware/tests/matchers.spec.ts index c39bbb6dd3..1b79db2e68 100644 --- a/packages/backend-core/src/middleware/tests/matchers.spec.ts +++ b/packages/backend-core/src/middleware/tests/matchers.spec.ts @@ -34,23 +34,6 @@ describe("matchers", () => { expect(!!matchers.matches(ctx, built)).toBe(true) }) - it("doesn't wildcard path with strict", () => { - const pattern = [ - { - route: "/api/tests", - method: "POST", - strict: true, - }, - ] - const ctx = structures.koa.newContext() - ctx.request.url = "/api/tests/id/something/else" - ctx.request.method = "POST" - - const built = matchers.buildMatcherRegex(pattern) - - expect(!!matchers.matches(ctx, built)).toBe(false) - }) - it("matches with param", () => { const pattern = [ { @@ -67,23 +50,6 @@ describe("matchers", () => { expect(!!matchers.matches(ctx, built)).toBe(true) }) - // TODO: Support the below behaviour - // Strict does not work when a param is present - // it("matches with param with strict", () => { - // const pattern = [{ - // route: "/api/tests/:testId", - // method: "GET", - // strict: true - // }] - // const ctx = structures.koa.newContext() - // ctx.request.url = "/api/tests/id" - // ctx.request.method = "GET" - // - // const built = matchers.buildMatcherRegex(pattern) - // - // expect(!!matchers.matches(ctx, built)).toBe(true) - // }) - it("doesn't match by path", () => { const pattern = [ { diff --git a/packages/backend-core/src/redis/tests/redis.spec.ts b/packages/backend-core/src/redis/tests/redis.spec.ts index c2c9e4a14e..e2076ad698 100644 --- a/packages/backend-core/src/redis/tests/redis.spec.ts +++ b/packages/backend-core/src/redis/tests/redis.spec.ts @@ -147,17 +147,6 @@ describe("redis", () => { expect(results).toEqual([1, 2, 3, 4, 5]) }) - it("can increment on a new key", async () => { - const key1 = structures.uuid() - const key2 = structures.uuid() - - const result1 = await redis.increment(key1) - expect(result1).toBe(1) - - const result2 = await redis.increment(key2) - expect(result2).toBe(1) - }) - it("can increment multiple times in parallel", async () => { const key = structures.uuid() const results = await Promise.all( @@ -184,7 +173,7 @@ describe("redis", () => { const key = structures.uuid() await redis.store(key, value) - await expect(redis.increment(key)).rejects.toThrowError( + await expect(redis.increment(key)).rejects.toThrow( "ERR value is not an integer or out of range" ) }) diff --git a/packages/backend-core/src/redis/tests/redlockImpl.spec.ts b/packages/backend-core/src/redis/tests/redlockImpl.spec.ts index a1e83d8e6c..e647b63bf5 100644 --- a/packages/backend-core/src/redis/tests/redlockImpl.spec.ts +++ b/packages/backend-core/src/redis/tests/redlockImpl.spec.ts @@ -96,8 +96,8 @@ describe("redlockImpl", () => { task: mockTask, executionTimeMs: lockTtl * 2, }) - ).rejects.toThrowError( - `Unable to fully release the lock on resource \"lock:${config.tenantId}_persist_writethrough\".` + ).rejects.toThrow( + `Unable to fully release the lock on resource "lock:${config.tenantId}_persist_writethrough".` ) } ) diff --git a/packages/backend-core/src/tenancy/tests/tenancy.spec.ts b/packages/backend-core/src/tenancy/tests/tenancy.spec.ts index 95dd76a6dd..34e9f87064 100644 --- a/packages/backend-core/src/tenancy/tests/tenancy.spec.ts +++ b/packages/backend-core/src/tenancy/tests/tenancy.spec.ts @@ -158,8 +158,8 @@ describe("getTenantIDFromCtx", () => { ], } expect(getTenantIDFromCtx(ctx, mockOpts)).toBeUndefined() - expect(ctx.throw).toBeCalledTimes(1) - expect(ctx.throw).toBeCalledWith(403, "Tenant id not set") + expect(ctx.throw).toHaveBeenCalledTimes(1) + expect(ctx.throw).toHaveBeenCalledWith(403, "Tenant id not set") }) it("returns undefined if allowNoTenant is true", () => { diff --git a/packages/backend-core/tests/core/utilities/structures/userGroups.ts b/packages/backend-core/tests/core/utilities/structures/userGroups.ts index 4dc870a00a..4af3f72e51 100644 --- a/packages/backend-core/tests/core/utilities/structures/userGroups.ts +++ b/packages/backend-core/tests/core/utilities/structures/userGroups.ts @@ -3,7 +3,7 @@ import { generator } from "./generator" export function userGroup(): UserGroup { return { - name: generator.word(), + name: generator.guid(), icon: generator.word(), color: generator.word(), } diff --git a/packages/cli/tsconfig.build.json b/packages/cli/tsconfig.build.json index f89ad95c28..e52d886194 100644 --- a/packages/cli/tsconfig.build.json +++ b/packages/cli/tsconfig.build.json @@ -11,6 +11,7 @@ "types": ["node", "jest"], "outDir": "dist", "skipLibCheck": true, + "baseUrl": ".", "paths": { "@budibase/types": ["../types/src"], "@budibase/backend-core": ["../backend-core/src"], diff --git a/packages/client/src/components/app/blocks/MultiStepFormblock.svelte b/packages/client/src/components/app/blocks/MultiStepFormblock.svelte index 2443aea017..762afc1579 100644 --- a/packages/client/src/components/app/blocks/MultiStepFormblock.svelte +++ b/packages/client/src/components/app/blocks/MultiStepFormblock.svelte @@ -75,6 +75,7 @@ .filter(field => !field.autocolumn) .map(field => ({ name: field.name, + active: true, })) } diff --git a/packages/pro b/packages/pro index 65ac3fc8a2..7d1b3eaf33 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 65ac3fc8a20a5244fbe47629cf79678db2d9ae8a +Subproject commit 7d1b3eaf33e560d19d591813e5bba91d75ef3953 diff --git a/packages/server/src/api/routes/tests/appImport.spec.ts b/packages/server/src/api/routes/tests/appImport.spec.ts index 51331323de..b2ef39838d 100644 --- a/packages/server/src/api/routes/tests/appImport.spec.ts +++ b/packages/server/src/api/routes/tests/appImport.spec.ts @@ -25,8 +25,8 @@ describe("/applications/:appId/import", () => { .expect(200) const appPackage = await config.api.application.get(appId!) expect(appPackage.navigation?.links?.length).toBe(2) - expect(expect(appPackage.navigation?.links?.[0].url).toBe("/blank")) - expect(expect(appPackage.navigation?.links?.[1].url).toBe("/derp")) + expect(appPackage.navigation?.links?.[0].url).toBe("/blank") + expect(appPackage.navigation?.links?.[1].url).toBe("/derp") const screens = await config.api.screen.list() expect(screens.length).toBe(2) expect(screens[0].routing.route).toBe("/derp") diff --git a/packages/server/src/api/routes/tests/application.spec.ts b/packages/server/src/api/routes/tests/application.spec.ts index 04edc91bf6..6b0ba89350 100644 --- a/packages/server/src/api/routes/tests/application.spec.ts +++ b/packages/server/src/api/routes/tests/application.spec.ts @@ -30,7 +30,9 @@ describe("/applications", () => { beforeEach(async () => { app = await config.api.application.create({ name: utils.newid() }) const deployment = await config.api.application.publish(app.appId) - expect(deployment.status).toBe("SUCCESS") + if (deployment.status !== "SUCCESS") { + throw new Error("Failed to publish app") + } jest.clearAllMocks() }) @@ -128,7 +130,7 @@ describe("/applications", () => { it("creates empty app", async () => { const app = await config.api.application.create({ name: utils.newid() }) expect(app._id).toBeDefined() - expect(events.app.created).toBeCalledTimes(1) + expect(events.app.created).toHaveBeenCalledTimes(1) }) it("creates app from template", async () => { @@ -139,8 +141,8 @@ describe("/applications", () => { templateString: "{}", }) expect(app._id).toBeDefined() - expect(events.app.created).toBeCalledTimes(1) - expect(events.app.templateImported).toBeCalledTimes(1) + expect(events.app.created).toHaveBeenCalledTimes(1) + expect(events.app.templateImported).toHaveBeenCalledTimes(1) }) it("creates app from file", async () => { @@ -150,8 +152,8 @@ describe("/applications", () => { templateFile: "src/api/routes/tests/data/export.txt", }) expect(app._id).toBeDefined() - expect(events.app.created).toBeCalledTimes(1) - expect(events.app.fileImported).toBeCalledTimes(1) + expect(events.app.created).toHaveBeenCalledTimes(1) + expect(events.app.fileImported).toHaveBeenCalledTimes(1) }) it("should apply authorization to endpoint", async () => { @@ -181,8 +183,8 @@ describe("/applications", () => { expect(app.navigation!.navTextColor).toBe( "var(--spectrum-global-color-gray-50)" ) - expect(events.app.created).toBeCalledTimes(1) - expect(events.app.fileImported).toBeCalledTimes(1) + expect(events.app.created).toHaveBeenCalledTimes(1) + expect(events.app.fileImported).toHaveBeenCalledTimes(1) }) it("should reject with a known name", async () => { @@ -228,32 +230,32 @@ describe("/applications", () => { name: "TEST_APP", }) expect(updatedApp._rev).toBeDefined() - expect(events.app.updated).toBeCalledTimes(1) + expect(events.app.updated).toHaveBeenCalledTimes(1) }) }) describe("publish", () => { it("should publish app with dev app ID", async () => { await config.api.application.publish(app.appId) - expect(events.app.published).toBeCalledTimes(1) + expect(events.app.published).toHaveBeenCalledTimes(1) }) it("should publish app with prod app ID", async () => { await config.api.application.publish(app.appId.replace("_dev", "")) - expect(events.app.published).toBeCalledTimes(1) + expect(events.app.published).toHaveBeenCalledTimes(1) }) }) describe("manage client library version", () => { it("should be able to update the app client library version", async () => { await config.api.application.updateClient(app.appId) - expect(events.app.versionUpdated).toBeCalledTimes(1) + expect(events.app.versionUpdated).toHaveBeenCalledTimes(1) }) it("should be able to revert the app client library version", async () => { await config.api.application.updateClient(app.appId) await config.api.application.revertClient(app.appId) - expect(events.app.versionReverted).toBeCalledTimes(1) + expect(events.app.versionReverted).toHaveBeenCalledTimes(1) }) }) @@ -310,26 +312,26 @@ describe("/applications", () => { describe("unpublish", () => { it("should unpublish app with dev app ID", async () => { await config.api.application.unpublish(app.appId) - expect(events.app.unpublished).toBeCalledTimes(1) + expect(events.app.unpublished).toHaveBeenCalledTimes(1) }) it("should unpublish app with prod app ID", async () => { await config.api.application.unpublish(app.appId.replace("_dev", "")) - expect(events.app.unpublished).toBeCalledTimes(1) + expect(events.app.unpublished).toHaveBeenCalledTimes(1) }) }) describe("delete", () => { it("should delete published app and dev apps with dev app ID", async () => { await config.api.application.delete(app.appId) - expect(events.app.deleted).toBeCalledTimes(1) - expect(events.app.unpublished).toBeCalledTimes(1) + expect(events.app.deleted).toHaveBeenCalledTimes(1) + expect(events.app.unpublished).toHaveBeenCalledTimes(1) }) it("should delete published app and dev app with prod app ID", async () => { await config.api.application.delete(app.appId.replace("_dev", "")) - expect(events.app.deleted).toBeCalledTimes(1) - expect(events.app.unpublished).toBeCalledTimes(1) + expect(events.app.deleted).toHaveBeenCalledTimes(1) + expect(events.app.unpublished).toHaveBeenCalledTimes(1) }) }) @@ -346,7 +348,7 @@ describe("/applications", () => { } ) - expect(events.app.duplicated).toBeCalled() + expect(events.app.duplicated).toHaveBeenCalled() expect(resp.duplicateAppId).toBeDefined() expect(resp.sourceAppId).toEqual(app.appId) expect(resp.duplicateAppId).not.toEqual(app.appId) @@ -374,7 +376,7 @@ describe("/applications", () => { }, { body: { message: "App name is already in use." }, status: 400 } ) - expect(events.app.duplicated).not.toBeCalled() + expect(events.app.duplicated).not.toHaveBeenCalled() }) it("should reject with a known url", async () => { @@ -386,7 +388,7 @@ describe("/applications", () => { }, { body: { message: "App URL is already in use." }, status: 400 } ) - expect(events.app.duplicated).not.toBeCalled() + expect(events.app.duplicated).not.toHaveBeenCalled() }) }) diff --git a/packages/server/src/api/routes/tests/automation.spec.ts b/packages/server/src/api/routes/tests/automation.spec.ts index ee8fc7d544..322694df75 100644 --- a/packages/server/src/api/routes/tests/automation.spec.ts +++ b/packages/server/src/api/routes/tests/automation.spec.ts @@ -95,8 +95,8 @@ describe("/automations", () => { expect(res.body.message).toEqual("Automation created successfully") expect(res.body.automation.name).toEqual("My Automation") expect(res.body.automation._id).not.toEqual(null) - expect(events.automation.created).toBeCalledTimes(1) - expect(events.automation.stepCreated).not.toBeCalled() + expect(events.automation.created).toHaveBeenCalledTimes(1) + expect(events.automation.stepCreated).not.toHaveBeenCalled() }) it("creates an automation with steps", async () => { @@ -114,8 +114,8 @@ describe("/automations", () => { expect(res.body.message).toEqual("Automation created successfully") expect(res.body.automation.name).toEqual("My Automation") expect(res.body.automation._id).not.toEqual(null) - expect(events.automation.created).toBeCalledTimes(1) - expect(events.automation.stepCreated).toBeCalledTimes(2) + expect(events.automation.created).toHaveBeenCalledTimes(1) + expect(events.automation.stepCreated).toHaveBeenCalledTimes(2) }) it("should apply authorization to endpoint", async () => { @@ -158,7 +158,7 @@ describe("/automations", () => { automation = await config.createAutomation(automation) await setup.delay(500) const res = await testAutomation(config, automation) - expect(events.automation.tested).toBeCalledTimes(1) + expect(events.automation.tested).toHaveBeenCalledTimes(1) // this looks a bit mad but we don't actually have a way to wait for a response from the automation to // know that it has finished all of its actions - this is currently the best way // also when this runs in CI it is very temper-mental so for now trying to make run stable by repeating until it works @@ -265,10 +265,10 @@ describe("/automations", () => { `Automation ${automation._id} updated successfully.` ) // events - expect(events.automation.created).not.toBeCalled() - expect(events.automation.stepCreated).not.toBeCalled() - expect(events.automation.stepDeleted).not.toBeCalled() - expect(events.automation.triggerUpdated).not.toBeCalled() + expect(events.automation.created).not.toHaveBeenCalled() + expect(events.automation.stepCreated).not.toHaveBeenCalled() + expect(events.automation.stepDeleted).not.toHaveBeenCalled() + expect(events.automation.triggerUpdated).not.toHaveBeenCalled() }) it("updates a automations name using POST request", async () => { @@ -293,10 +293,10 @@ describe("/automations", () => { `Automation ${automation._id} updated successfully.` ) // events - expect(events.automation.created).not.toBeCalled() - expect(events.automation.stepCreated).not.toBeCalled() - expect(events.automation.stepDeleted).not.toBeCalled() - expect(events.automation.triggerUpdated).not.toBeCalled() + expect(events.automation.created).not.toHaveBeenCalled() + expect(events.automation.stepCreated).not.toHaveBeenCalled() + expect(events.automation.stepDeleted).not.toHaveBeenCalled() + expect(events.automation.triggerUpdated).not.toHaveBeenCalled() }) it("updates an automation trigger", async () => { @@ -310,10 +310,10 @@ describe("/automations", () => { await update(automation) // events - expect(events.automation.created).not.toBeCalled() - expect(events.automation.stepCreated).not.toBeCalled() - expect(events.automation.stepDeleted).not.toBeCalled() - expect(events.automation.triggerUpdated).toBeCalledTimes(1) + expect(events.automation.created).not.toHaveBeenCalled() + expect(events.automation.stepCreated).not.toHaveBeenCalled() + expect(events.automation.stepDeleted).not.toHaveBeenCalled() + expect(events.automation.triggerUpdated).toHaveBeenCalledTimes(1) }) it("adds automation steps", async () => { @@ -327,10 +327,10 @@ describe("/automations", () => { await update(automation) // events - expect(events.automation.stepCreated).toBeCalledTimes(2) - expect(events.automation.created).not.toBeCalled() - expect(events.automation.stepDeleted).not.toBeCalled() - expect(events.automation.triggerUpdated).not.toBeCalled() + expect(events.automation.stepCreated).toHaveBeenCalledTimes(2) + expect(events.automation.created).not.toHaveBeenCalled() + expect(events.automation.stepDeleted).not.toHaveBeenCalled() + expect(events.automation.triggerUpdated).not.toHaveBeenCalled() }) it("removes automation steps", async () => { @@ -344,10 +344,10 @@ describe("/automations", () => { await update(automation) // events - expect(events.automation.stepDeleted).toBeCalledTimes(2) - expect(events.automation.stepCreated).not.toBeCalled() - expect(events.automation.created).not.toBeCalled() - expect(events.automation.triggerUpdated).not.toBeCalled() + expect(events.automation.stepDeleted).toHaveBeenCalledTimes(2) + expect(events.automation.stepCreated).not.toHaveBeenCalled() + expect(events.automation.created).not.toHaveBeenCalled() + expect(events.automation.triggerUpdated).not.toHaveBeenCalled() }) it("adds and removes automation steps", async () => { @@ -360,10 +360,10 @@ describe("/automations", () => { await update(automation) // events - expect(events.automation.stepCreated).toBeCalledTimes(2) - expect(events.automation.stepDeleted).toBeCalledTimes(1) - expect(events.automation.created).not.toBeCalled() - expect(events.automation.triggerUpdated).not.toBeCalled() + expect(events.automation.stepCreated).toHaveBeenCalledTimes(2) + expect(events.automation.stepDeleted).toHaveBeenCalledTimes(1) + expect(events.automation.created).not.toHaveBeenCalled() + expect(events.automation.triggerUpdated).not.toHaveBeenCalled() }) }) @@ -400,7 +400,7 @@ describe("/automations", () => { .expect(200) expect(res.body.id).toEqual(automation._id) - expect(events.automation.deleted).toBeCalledTimes(1) + expect(events.automation.deleted).toHaveBeenCalledTimes(1) }) it("should apply authorization to endpoint", async () => { diff --git a/packages/server/src/api/routes/tests/backup.spec.ts b/packages/server/src/api/routes/tests/backup.spec.ts index c862106d58..7b56145f8e 100644 --- a/packages/server/src/api/routes/tests/backup.spec.ts +++ b/packages/server/src/api/routes/tests/backup.spec.ts @@ -21,7 +21,7 @@ describe("/backups", () => { it("should be able to export app", async () => { const body = await config.api.backup.exportBasicBackup(config.getAppId()!) expect(body instanceof Buffer).toBe(true) - expect(events.app.exported).toBeCalledTimes(1) + expect(events.app.exported).toHaveBeenCalledTimes(1) }) it("should apply authorization to endpoint", async () => { diff --git a/packages/server/src/api/routes/tests/datasource.spec.ts b/packages/server/src/api/routes/tests/datasource.spec.ts index 032da71b80..cbd830aee5 100644 --- a/packages/server/src/api/routes/tests/datasource.spec.ts +++ b/packages/server/src/api/routes/tests/datasource.spec.ts @@ -40,7 +40,7 @@ describe("/datasources", () => { expect(res.body.datasource.name).toEqual("Test") expect(res.body.errors).toEqual({}) - expect(events.datasource.created).toBeCalledTimes(1) + expect(events.datasource.created).toHaveBeenCalledTimes(1) }) }) @@ -56,7 +56,7 @@ describe("/datasources", () => { expect(res.body.datasource.name).toEqual("Updated Test") expect(res.body.errors).toBeUndefined() - expect(events.datasource.updated).toBeCalledTimes(1) + expect(events.datasource.updated).toHaveBeenCalledTimes(1) }) describe("dynamic variables", () => { @@ -196,7 +196,7 @@ describe("/datasources", () => { .expect(200) expect(res.body.length).toEqual(1) - expect(events.datasource.deleted).toBeCalledTimes(1) + expect(events.datasource.deleted).toHaveBeenCalledTimes(1) }) it("should apply authorization to endpoint", async () => { diff --git a/packages/server/src/api/routes/tests/environmentVariables.spec.ts b/packages/server/src/api/routes/tests/environmentVariables.spec.ts index 22114a1da3..9104dedf4f 100644 --- a/packages/server/src/api/routes/tests/environmentVariables.spec.ts +++ b/packages/server/src/api/routes/tests/environmentVariables.spec.ts @@ -138,10 +138,10 @@ describe("/api/env/variables", () => { .expect("Content-Type", /json/) .expect(200) expect(res.body.rows.length).toEqual(0) - expect(events.query.previewed).toBeCalledTimes(1) + expect(events.query.previewed).toHaveBeenCalledTimes(1) // API doesn't include config in response delete response.body.datasource.config - expect(events.query.previewed).toBeCalledWith( + expect(events.query.previewed).toHaveBeenCalledWith( response.body.datasource, queryPreview ) diff --git a/packages/server/src/api/routes/tests/queries/query.seq.spec.ts b/packages/server/src/api/routes/tests/queries/query.seq.spec.ts index fc90ad4247..0ca424c48b 100644 --- a/packages/server/src/api/routes/tests/queries/query.seq.spec.ts +++ b/packages/server/src/api/routes/tests/queries/query.seq.spec.ts @@ -81,8 +81,8 @@ describe("/queries", () => { createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), }) - expect(events.query.created).toBeCalledTimes(1) - expect(events.query.updated).not.toBeCalled() + expect(events.query.created).toHaveBeenCalledTimes(1) + expect(events.query.updated).not.toHaveBeenCalled() }) }) @@ -106,8 +106,8 @@ describe("/queries", () => { createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), }) - expect(events.query.created).not.toBeCalled() - expect(events.query.updated).toBeCalledTimes(1) + expect(events.query.created).not.toHaveBeenCalled() + expect(events.query.updated).toHaveBeenCalledTimes(1) }) }) @@ -210,8 +210,8 @@ describe("/queries", () => { .expect(200) expect(res.body).toEqual([]) - expect(events.query.deleted).toBeCalledTimes(1) - expect(events.query.deleted).toBeCalledWith(datasource, query) + expect(events.query.deleted).toHaveBeenCalledTimes(1) + expect(events.query.deleted).toHaveBeenCalledWith(datasource, query) }) it("should apply authorization to endpoint", async () => { @@ -243,9 +243,12 @@ describe("/queries", () => { b: { type: "number", name: "b" }, }) expect(responseBody.rows.length).toEqual(1) - expect(events.query.previewed).toBeCalledTimes(1) + expect(events.query.previewed).toHaveBeenCalledTimes(1) delete datasource.config - expect(events.query.previewed).toBeCalledWith(datasource, queryPreview) + expect(events.query.previewed).toHaveBeenCalledWith( + datasource, + queryPreview + ) }) it("should apply authorization to endpoint", async () => { diff --git a/packages/server/src/api/routes/tests/table.spec.ts b/packages/server/src/api/routes/tests/table.spec.ts index 4321f012aa..1038808fe1 100644 --- a/packages/server/src/api/routes/tests/table.spec.ts +++ b/packages/server/src/api/routes/tests/table.spec.ts @@ -64,8 +64,8 @@ describe("/tables", () => { "Table TestTable saved successfully." ) expect(res.body.name).toEqual("TestTable") - expect(events.table.created).toBeCalledTimes(1) - expect(events.table.created).toBeCalledWith(res.body) + expect(events.table.created).toHaveBeenCalledTimes(1) + expect(events.table.created).toHaveBeenCalledWith(res.body) }) it("creates all the passed fields", async () => { @@ -135,12 +135,12 @@ describe("/tables", () => { const res = await createTable(table) - expect(events.table.created).toBeCalledTimes(1) - expect(events.table.created).toBeCalledWith(res.body) - expect(events.table.imported).toBeCalledTimes(1) - expect(events.table.imported).toBeCalledWith(res.body) - expect(events.rows.imported).toBeCalledTimes(1) - expect(events.rows.imported).toBeCalledWith(res.body, 1) + expect(events.table.created).toHaveBeenCalledTimes(1) + expect(events.table.created).toHaveBeenCalledWith(res.body) + expect(events.table.imported).toHaveBeenCalledTimes(1) + expect(events.table.imported).toHaveBeenCalledWith(res.body) + expect(events.rows.imported).toHaveBeenCalledTimes(1) + expect(events.rows.imported).toHaveBeenCalledWith(res.body, 1) }) it("should apply authorization to endpoint", async () => { @@ -164,8 +164,8 @@ describe("/tables", () => { .expect("Content-Type", /json/) .expect(200) - expect(events.table.updated).toBeCalledTimes(1) - expect(events.table.updated).toBeCalledWith(res.body) + expect(events.table.updated).toHaveBeenCalledTimes(1) + expect(events.table.updated).toHaveBeenCalledWith(res.body) }) it("updates all the row fields for a table when a schema key is renamed", async () => { @@ -335,8 +335,8 @@ describe("/tables", () => { .expect(200) expect(events.table.created).not.toHaveBeenCalled() - expect(events.rows.imported).toBeCalledTimes(1) - expect(events.rows.imported).toBeCalledWith( + expect(events.rows.imported).toHaveBeenCalledTimes(1) + expect(events.rows.imported).toHaveBeenCalledWith( expect.objectContaining({ name: "TestTable", _id: table._id, @@ -527,8 +527,8 @@ describe("/tables", () => { .expect("Content-Type", /json/) .expect(200) expect(res.body.message).toEqual(`Table ${testTable._id} deleted.`) - expect(events.table.deleted).toBeCalledTimes(1) - expect(events.table.deleted).toBeCalledWith({ + expect(events.table.deleted).toHaveBeenCalledTimes(1) + expect(events.table.deleted).toHaveBeenCalledWith({ ...testTable, tableId: testTable._id, }) diff --git a/packages/server/src/api/routes/tests/view.spec.ts b/packages/server/src/api/routes/tests/view.spec.ts index 893df61fdc..d5a4dd6aeb 100644 --- a/packages/server/src/api/routes/tests/view.spec.ts +++ b/packages/server/src/api/routes/tests/view.spec.ts @@ -75,7 +75,7 @@ describe("/views", () => { describe("create", () => { it("returns a success message when the view is successfully created", async () => { const res = await saveView() - expect(events.view.created).toBeCalledTimes(1) + expect(events.view.created).toHaveBeenCalledTimes(1) }) it("creates a view with a calculation", async () => { @@ -84,14 +84,14 @@ describe("/views", () => { const view = await saveView({ calculation: ViewCalculation.COUNT }) expect(view.tableId).toBe(table._id) - expect(events.view.created).toBeCalledTimes(1) - expect(events.view.updated).not.toBeCalled() - expect(events.view.calculationCreated).toBeCalledTimes(1) - expect(events.view.calculationUpdated).not.toBeCalled() - expect(events.view.calculationDeleted).not.toBeCalled() - expect(events.view.filterCreated).not.toBeCalled() - expect(events.view.filterUpdated).not.toBeCalled() - expect(events.view.filterDeleted).not.toBeCalled() + expect(events.view.created).toHaveBeenCalledTimes(1) + expect(events.view.updated).not.toHaveBeenCalled() + expect(events.view.calculationCreated).toHaveBeenCalledTimes(1) + expect(events.view.calculationUpdated).not.toHaveBeenCalled() + expect(events.view.calculationDeleted).not.toHaveBeenCalled() + expect(events.view.filterCreated).not.toHaveBeenCalled() + expect(events.view.filterUpdated).not.toHaveBeenCalled() + expect(events.view.filterDeleted).not.toHaveBeenCalled() }) it("creates a view with a filter", async () => { @@ -109,14 +109,14 @@ describe("/views", () => { }) expect(view.tableId).toBe(table._id) - expect(events.view.created).toBeCalledTimes(1) - expect(events.view.updated).not.toBeCalled() - expect(events.view.calculationCreated).not.toBeCalled() - expect(events.view.calculationUpdated).not.toBeCalled() - expect(events.view.calculationDeleted).not.toBeCalled() - expect(events.view.filterCreated).toBeCalledTimes(1) - expect(events.view.filterUpdated).not.toBeCalled() - expect(events.view.filterDeleted).not.toBeCalled() + expect(events.view.created).toHaveBeenCalledTimes(1) + expect(events.view.updated).not.toHaveBeenCalled() + expect(events.view.calculationCreated).not.toHaveBeenCalled() + expect(events.view.calculationUpdated).not.toHaveBeenCalled() + expect(events.view.calculationDeleted).not.toHaveBeenCalled() + expect(events.view.filterCreated).toHaveBeenCalledTimes(1) + expect(events.view.filterUpdated).not.toHaveBeenCalled() + expect(events.view.filterDeleted).not.toHaveBeenCalled() }) it("updates the table row with the new view metadata", async () => { @@ -165,14 +165,14 @@ describe("/views", () => { await saveView() - expect(events.view.created).not.toBeCalled() - expect(events.view.updated).toBeCalledTimes(1) - expect(events.view.calculationCreated).not.toBeCalled() - expect(events.view.calculationUpdated).not.toBeCalled() - expect(events.view.calculationDeleted).not.toBeCalled() - expect(events.view.filterCreated).not.toBeCalled() - expect(events.view.filterUpdated).not.toBeCalled() - expect(events.view.filterDeleted).not.toBeCalled() + expect(events.view.created).not.toHaveBeenCalled() + expect(events.view.updated).toHaveBeenCalledTimes(1) + expect(events.view.calculationCreated).not.toHaveBeenCalled() + expect(events.view.calculationUpdated).not.toHaveBeenCalled() + expect(events.view.calculationDeleted).not.toHaveBeenCalled() + expect(events.view.filterCreated).not.toHaveBeenCalled() + expect(events.view.filterUpdated).not.toHaveBeenCalled() + expect(events.view.filterDeleted).not.toHaveBeenCalled() }) it("updates a view calculation", async () => { @@ -181,14 +181,14 @@ describe("/views", () => { await saveView({ calculation: ViewCalculation.COUNT }) - expect(events.view.created).not.toBeCalled() - expect(events.view.updated).toBeCalledTimes(1) - expect(events.view.calculationCreated).not.toBeCalled() - expect(events.view.calculationUpdated).toBeCalledTimes(1) - expect(events.view.calculationDeleted).not.toBeCalled() - expect(events.view.filterCreated).not.toBeCalled() - expect(events.view.filterUpdated).not.toBeCalled() - expect(events.view.filterDeleted).not.toBeCalled() + expect(events.view.created).not.toHaveBeenCalled() + expect(events.view.updated).toHaveBeenCalledTimes(1) + expect(events.view.calculationCreated).not.toHaveBeenCalled() + expect(events.view.calculationUpdated).toHaveBeenCalledTimes(1) + expect(events.view.calculationDeleted).not.toHaveBeenCalled() + expect(events.view.filterCreated).not.toHaveBeenCalled() + expect(events.view.filterUpdated).not.toHaveBeenCalled() + expect(events.view.filterDeleted).not.toHaveBeenCalled() }) it("deletes a view calculation", async () => { @@ -197,14 +197,14 @@ describe("/views", () => { await saveView({ calculation: undefined }) - expect(events.view.created).not.toBeCalled() - expect(events.view.updated).toBeCalledTimes(1) - expect(events.view.calculationCreated).not.toBeCalled() - expect(events.view.calculationUpdated).not.toBeCalled() - expect(events.view.calculationDeleted).toBeCalledTimes(1) - expect(events.view.filterCreated).not.toBeCalled() - expect(events.view.filterUpdated).not.toBeCalled() - expect(events.view.filterDeleted).not.toBeCalled() + expect(events.view.created).not.toHaveBeenCalled() + expect(events.view.updated).toHaveBeenCalledTimes(1) + expect(events.view.calculationCreated).not.toHaveBeenCalled() + expect(events.view.calculationUpdated).not.toHaveBeenCalled() + expect(events.view.calculationDeleted).toHaveBeenCalledTimes(1) + expect(events.view.filterCreated).not.toHaveBeenCalled() + expect(events.view.filterUpdated).not.toHaveBeenCalled() + expect(events.view.filterDeleted).not.toHaveBeenCalled() }) it("updates a view filter", async () => { @@ -229,14 +229,14 @@ describe("/views", () => { ], }) - expect(events.view.created).not.toBeCalled() - expect(events.view.updated).toBeCalledTimes(1) - expect(events.view.calculationCreated).not.toBeCalled() - expect(events.view.calculationUpdated).not.toBeCalled() - expect(events.view.calculationDeleted).not.toBeCalled() - expect(events.view.filterCreated).not.toBeCalled() - expect(events.view.filterUpdated).toBeCalledTimes(1) - expect(events.view.filterDeleted).not.toBeCalled() + expect(events.view.created).not.toHaveBeenCalled() + expect(events.view.updated).toHaveBeenCalledTimes(1) + expect(events.view.calculationCreated).not.toHaveBeenCalled() + expect(events.view.calculationUpdated).not.toHaveBeenCalled() + expect(events.view.calculationDeleted).not.toHaveBeenCalled() + expect(events.view.filterCreated).not.toHaveBeenCalled() + expect(events.view.filterUpdated).toHaveBeenCalledTimes(1) + expect(events.view.filterDeleted).not.toHaveBeenCalled() }) it("deletes a view filter", async () => { @@ -253,14 +253,14 @@ describe("/views", () => { await saveView({ filters: [] }) - expect(events.view.created).not.toBeCalled() - expect(events.view.updated).toBeCalledTimes(1) - expect(events.view.calculationCreated).not.toBeCalled() - expect(events.view.calculationUpdated).not.toBeCalled() - expect(events.view.calculationDeleted).not.toBeCalled() - expect(events.view.filterCreated).not.toBeCalled() - expect(events.view.filterUpdated).not.toBeCalled() - expect(events.view.filterDeleted).toBeCalledTimes(1) + expect(events.view.created).not.toHaveBeenCalled() + expect(events.view.updated).toHaveBeenCalledTimes(1) + expect(events.view.calculationCreated).not.toHaveBeenCalled() + expect(events.view.calculationUpdated).not.toHaveBeenCalled() + expect(events.view.calculationDeleted).not.toHaveBeenCalled() + expect(events.view.filterCreated).not.toHaveBeenCalled() + expect(events.view.filterUpdated).not.toHaveBeenCalled() + expect(events.view.filterDeleted).toHaveBeenCalledTimes(1) }) }) @@ -393,7 +393,7 @@ describe("/views", () => { const deletedView = await config.api.legacyView.destroy(view.name!) expect(deletedView.map).toBeDefined() expect(deletedView.meta?.tableId).toEqual(table._id) - expect(events.view.deleted).toBeCalledTimes(1) + expect(events.view.deleted).toHaveBeenCalledTimes(1) }) }) @@ -443,8 +443,8 @@ describe("/views", () => { const res = await config.api.legacyView.export(table._id!, "json") assertJsonExport(res) - expect(events.table.exported).toBeCalledTimes(1) - expect(events.table.exported).toBeCalledWith(table, "json") + expect(events.table.exported).toHaveBeenCalledTimes(1) + expect(events.table.exported).toHaveBeenCalledWith(table, "json") }) it("should be able to export a table as CSV", async () => { @@ -453,8 +453,8 @@ describe("/views", () => { const res = await config.api.legacyView.export(table._id!, "csv") assertCSVExport(res) - expect(events.table.exported).toBeCalledTimes(1) - expect(events.table.exported).toBeCalledWith(table, "csv") + expect(events.table.exported).toHaveBeenCalledTimes(1) + expect(events.table.exported).toHaveBeenCalledWith(table, "csv") }) it("should be able to export a view as JSON", async () => { @@ -470,8 +470,8 @@ describe("/views", () => { let res = await config.api.legacyView.export(view.name!, "json") assertJsonExport(res) - expect(events.view.exported).toBeCalledTimes(1) - expect(events.view.exported).toBeCalledWith(table, "json") + expect(events.view.exported).toHaveBeenCalledTimes(1) + expect(events.view.exported).toHaveBeenCalledWith(table, "json") }) it("should be able to export a view as CSV", async () => { @@ -487,8 +487,8 @@ describe("/views", () => { let res = await config.api.legacyView.export(view.name!, "csv") assertCSVExport(res) - expect(events.view.exported).toBeCalledTimes(1) - expect(events.view.exported).toBeCalledWith(table, "csv") + expect(events.view.exported).toHaveBeenCalledTimes(1) + expect(events.view.exported).toHaveBeenCalledWith(table, "csv") }) }) }) diff --git a/packages/server/src/api/routes/tests/webhook.spec.ts b/packages/server/src/api/routes/tests/webhook.spec.ts index 48a6da38bf..b741ce0820 100644 --- a/packages/server/src/api/routes/tests/webhook.spec.ts +++ b/packages/server/src/api/routes/tests/webhook.spec.ts @@ -140,7 +140,7 @@ describe("/webhooks", () => { }) }) - it("should trigger a synchronous webhook call ", async () => { + it("should trigger a synchronous webhook call", async () => { mocks.licenses.useSyncAutomations() let automation = collectAutomation() let newAutomation = await config.createAutomation(automation) diff --git a/packages/server/src/appMigrations/tests/migrationsProcessor.spec.ts b/packages/server/src/appMigrations/tests/migrationsProcessor.spec.ts index 3b8e90b526..a2d1dc05c3 100644 --- a/packages/server/src/appMigrations/tests/migrationsProcessor.spec.ts +++ b/packages/server/src/appMigrations/tests/migrationsProcessor.spec.ts @@ -45,7 +45,7 @@ describe("migrationsProcessor", () => { await expect( config.doInContext(appId, () => processMigrations(appId, testMigrations)) - ).rejects.toThrowError( + ).rejects.toThrow( "The context cannot be changed, a migration is currently running" ) }) diff --git a/packages/server/src/integration-test/mysql.spec.ts b/packages/server/src/integration-test/mysql.spec.ts index 8804f87c28..b8f1affd4a 100644 --- a/packages/server/src/integration-test/mysql.spec.ts +++ b/packages/server/src/integration-test/mysql.spec.ts @@ -307,7 +307,7 @@ describe("mysql integrations", () => { } delete expectedTable._add - expect(emitDatasourceUpdateMock).toBeCalledTimes(1) + expect(emitDatasourceUpdateMock).toHaveBeenCalledTimes(1) const emittedDatasource: Datasource = emitDatasourceUpdateMock.mock.calls[0][1] expect(emittedDatasource.entities!["table"]).toEqual(expectedTable) diff --git a/packages/server/src/integrations/oracle.ts b/packages/server/src/integrations/oracle.ts index 08f3058d63..83803906be 100644 --- a/packages/server/src/integrations/oracle.ts +++ b/packages/server/src/integrations/oracle.ts @@ -455,7 +455,7 @@ class OracleIntegration extends Sql implements DatasourcePlus { operation !== Operation.DELETE ) { const lastRow = await this.internalQuery({ - sql: `SELECT * FROM \"${json.endpoint.entityId}\" WHERE ROWID = '${response.lastRowid}'`, + sql: `SELECT * FROM "${json.endpoint.entityId}" WHERE ROWID = '${response.lastRowid}'`, }) return lastRow.rows as Row[] } else { diff --git a/packages/server/src/integrations/tests/googlesheets.spec.ts b/packages/server/src/integrations/tests/googlesheets.spec.ts index 7007693086..c6e073d602 100644 --- a/packages/server/src/integrations/tests/googlesheets.spec.ts +++ b/packages/server/src/integrations/tests/googlesheets.spec.ts @@ -109,9 +109,9 @@ describe("Google Sheets Integration", () => { sheetsByTitle[table.name] = sheet await integration.updateTable(table) - expect(sheet.loadHeaderRow).toBeCalledTimes(1) - expect(sheet.setHeaderRow).toBeCalledTimes(1) - expect(sheet.setHeaderRow).toBeCalledWith(tableColumns) + expect(sheet.loadHeaderRow).toHaveBeenCalledTimes(1) + expect(sheet.setHeaderRow).toHaveBeenCalledTimes(1) + expect(sheet.setHeaderRow).toHaveBeenCalledWith(tableColumns) }) }) @@ -127,9 +127,9 @@ describe("Google Sheets Integration", () => { await integration.updateTable(table) return sheet }) - expect(sheet.loadHeaderRow).toBeCalledTimes(1) - expect(sheet.setHeaderRow).toBeCalledTimes(1) - expect(sheet.setHeaderRow).toBeCalledWith(["name"]) + expect(sheet.loadHeaderRow).toHaveBeenCalledTimes(1) + expect(sheet.setHeaderRow).toHaveBeenCalledTimes(1) + expect(sheet.setHeaderRow).toHaveBeenCalledWith(["name"]) // No undefined are sent expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(1) @@ -148,7 +148,7 @@ describe("Google Sheets Integration", () => { const res = await integration.getTableNames() - expect(mockGoogleIntegration.loadInfo).toBeCalledTimes(1) + expect(mockGoogleIntegration.loadInfo).toHaveBeenCalledTimes(1) expect(res).toEqual(sheetNames) }) }) @@ -159,7 +159,7 @@ describe("Google Sheets Integration", () => { await config.doInContext(structures.uuid(), async () => { const res = await integration.testConnection() - expect(mockGoogleIntegration.loadInfo).toBeCalledTimes(1) + expect(mockGoogleIntegration.loadInfo).toHaveBeenCalledTimes(1) expect(res).toEqual({ connected: true }) }) }) diff --git a/packages/server/src/integrations/tests/mongo.spec.ts b/packages/server/src/integrations/tests/mongo.spec.ts index 93e54c7bc7..74dd9d4ec0 100644 --- a/packages/server/src/integrations/tests/mongo.spec.ts +++ b/packages/server/src/integrations/tests/mongo.spec.ts @@ -12,15 +12,6 @@ class TestConfiguration { } } -function disableConsole() { - jest.spyOn(console, "error") - // @ts-ignore - console.error.mockImplementation(() => {}) - - // @ts-ignore - return console.error.mockRestore -} - describe("MongoDB Integration", () => { let config: any let indexName = "Users" @@ -96,8 +87,6 @@ describe("MongoDB Integration", () => { }) it("throws an error when an invalid query.extra.actionType is passed for each method", async () => { - const restore = disableConsole() - const query = { extra: { collection: "testCollection", actionType: "deleteOne" }, } @@ -109,7 +98,6 @@ describe("MongoDB Integration", () => { error = err } expect(error).toBeDefined() - restore() }) it("creates ObjectIds if the field contains a match on ObjectId", async () => { diff --git a/packages/server/src/integrations/tests/mysql.spec.ts b/packages/server/src/integrations/tests/mysql.spec.ts index 7d45a06735..5180645885 100644 --- a/packages/server/src/integrations/tests/mysql.spec.ts +++ b/packages/server/src/integrations/tests/mysql.spec.ts @@ -76,7 +76,7 @@ describe("MySQL Integration", () => { }) describe("binding type coerce", () => { - it("ignores non-string types ", async () => { + it("ignores non-string types", async () => { const sql = "select * from users;" const date = new Date() await config.integration.read({ @@ -103,7 +103,7 @@ describe("MySQL Integration", () => { ) }) - it.skip("parses strings matching a valid date format", async () => { + it("parses strings matching a valid date format", async () => { const sql = "select * from users;" await config.integration.read({ sql, diff --git a/packages/server/src/integrations/tests/oracle.spec.ts b/packages/server/src/integrations/tests/oracle.spec.ts index 8c05a881d4..80ad969e3b 100644 --- a/packages/server/src/integrations/tests/oracle.spec.ts +++ b/packages/server/src/integrations/tests/oracle.spec.ts @@ -22,11 +22,6 @@ describe("Oracle Integration", () => { config = new TestConfiguration() }) - afterEach(() => { - expect(oracledb.closeMock).toHaveBeenCalled() - expect(oracledb.closeMock).toHaveBeenCalledTimes(1) - }) - it("calls the create method with the correct params", async () => { const sql = "insert into users (name, age) values ('Joe', 123);" await config.integration.create({ @@ -34,6 +29,7 @@ describe("Oracle Integration", () => { }) expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options) expect(oracledb.executeMock).toHaveBeenCalledTimes(1) + expect(oracledb.closeMock).toHaveBeenCalledTimes(1) }) it("calls the read method with the correct params", async () => { @@ -43,6 +39,7 @@ describe("Oracle Integration", () => { }) expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options) expect(oracledb.executeMock).toHaveBeenCalledTimes(1) + expect(oracledb.closeMock).toHaveBeenCalledTimes(1) }) it("calls the update method with the correct params", async () => { @@ -52,6 +49,7 @@ describe("Oracle Integration", () => { }) expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options) expect(oracledb.executeMock).toHaveBeenCalledTimes(1) + expect(oracledb.closeMock).toHaveBeenCalledTimes(1) }) it("calls the delete method with the correct params", async () => { @@ -61,6 +59,7 @@ describe("Oracle Integration", () => { }) expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options) expect(oracledb.executeMock).toHaveBeenCalledTimes(1) + expect(oracledb.closeMock).toHaveBeenCalledTimes(1) }) describe("no rows returned", () => { @@ -75,6 +74,7 @@ describe("Oracle Integration", () => { }) expect(response).toEqual([{ created: true }]) expect(oracledb.executeMock).toHaveBeenCalledTimes(1) + expect(oracledb.closeMock).toHaveBeenCalledTimes(1) }) it("returns the correct response when the update response has no rows", async () => { @@ -84,6 +84,7 @@ describe("Oracle Integration", () => { }) expect(response).toEqual([{ updated: true }]) expect(oracledb.executeMock).toHaveBeenCalledTimes(1) + expect(oracledb.closeMock).toHaveBeenCalledTimes(1) }) it("returns the correct response when the delete response has no rows", async () => { @@ -93,6 +94,7 @@ describe("Oracle Integration", () => { }) expect(response).toEqual([{ deleted: true }]) expect(oracledb.executeMock).toHaveBeenCalledTimes(1) + expect(oracledb.closeMock).toHaveBeenCalledTimes(1) }) }) }) diff --git a/packages/server/src/integrations/tests/rest.spec.ts b/packages/server/src/integrations/tests/rest.spec.ts index bc0c0cac2f..182a6d3f13 100644 --- a/packages/server/src/integrations/tests/rest.spec.ts +++ b/packages/server/src/integrations/tests/rest.spec.ts @@ -418,9 +418,9 @@ describe("REST Integration", () => { }) // @ts-ignore const sentData = fetch.mock.calls[0][1].body - expect(sentData.has(pageParam)) + expect(sentData.has(pageParam)).toEqual(true) expect(sentData.get(pageParam)).toEqual(pageValue.toString()) - expect(sentData.has(sizeParam)) + expect(sentData.has(pageParam)).toEqual(true) expect(sentData.get(sizeParam)).toEqual(sizeValue.toString()) }) }) @@ -551,9 +551,9 @@ describe("REST Integration", () => { }) // @ts-ignore const sentData = fetch.mock.calls[0][1].body - expect(sentData.has(pageParam)) + expect(sentData.has(pageParam)).toEqual(true) expect(sentData.get(pageParam)).toEqual(pageValue.toString()) - expect(sentData.has(sizeParam)) + expect(sentData.has(pageParam)).toEqual(true) expect(sentData.get(sizeParam)).toEqual(sizeValue.toString()) expect(res.pagination.cursor).toEqual(123) }) diff --git a/packages/server/src/integrations/tests/s3.spec.ts b/packages/server/src/integrations/tests/s3.spec.ts index b4b2ad76e7..40f73928f2 100644 --- a/packages/server/src/integrations/tests/s3.spec.ts +++ b/packages/server/src/integrations/tests/s3.spec.ts @@ -79,7 +79,7 @@ describe("S3 Integration", () => { }) }) - it("calls the delete method with the correct params ", async () => { + it("calls the delete method with the correct params", async () => { await config.integration.delete({ bucket: "test", delete: `{ diff --git a/packages/server/src/integrations/tests/sql.spec.ts b/packages/server/src/integrations/tests/sql.spec.ts index f4eaf2859c..c0b92b3849 100644 --- a/packages/server/src/integrations/tests/sql.spec.ts +++ b/packages/server/src/integrations/tests/sql.spec.ts @@ -342,25 +342,6 @@ describe("SQL query builder", () => { }) }) - it("should use greater than when only low range specified", () => { - const date = new Date() - const query = sql._query( - generateReadJson({ - filters: { - range: { - property: { - low: date, - }, - }, - }, - }) - ) - expect(query).toEqual({ - bindings: [date, limit], - sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" > $1 limit $2) as "${TABLE_NAME}"`, - }) - }) - it("should use AND like expression for MS-SQL when filter is contains", () => { const query = new Sql(SqlClient.MS_SQL, 10)._query( generateReadJson({ @@ -408,7 +389,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: [10], - sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"`, + sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age"::jsonb @> '[20]' and "${TABLE_NAME}"."name"::jsonb @> '["John"]' limit $1) as "${TABLE_NAME}"`, }) }) @@ -459,7 +440,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: [10], - sql: `select * from (select * from \"${TABLE_NAME}\" where NOT \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and NOT \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"`, + sql: `select * from (select * from "${TABLE_NAME}" where NOT "${TABLE_NAME}"."age"::jsonb @> '[20]' and NOT "${TABLE_NAME}"."name"::jsonb @> '["John"]' limit $1) as "${TABLE_NAME}"`, }) }) @@ -510,7 +491,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: [10], - sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb ?| array [20,25] and \"${TABLE_NAME}\".\"name\"::jsonb ?| array ['John','Mary'] limit $1) as \"${TABLE_NAME}\"`, + sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age"::jsonb ?| array [20,25] and "${TABLE_NAME}"."name"::jsonb ?| array ['John','Mary'] limit $1) as "${TABLE_NAME}"`, }) }) @@ -591,7 +572,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: ["2000-01-01 00:00:00", 500], - sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"dob\" > $1 limit $2) as \"${TABLE_NAME}\"`, + sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."dob" > $1 limit $2) as "${TABLE_NAME}"`, }) }) @@ -610,7 +591,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: ["2010-01-01 00:00:00", 500], - sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"dob\" < $1 limit $2) as \"${TABLE_NAME}\"`, + sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."dob" < $1 limit $2) as "${TABLE_NAME}"`, }) }) @@ -626,7 +607,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: ["john%", limit], - sql: `select * from (select * from (select * from \"test\" where LOWER(\"test\".\"name\") LIKE :1) where rownum <= :2) \"test\"`, + sql: `select * from (select * from (select * from "test" where LOWER("test"."name") LIKE :1) where rownum <= :2) "test"`, }) query = new Sql(SqlClient.ORACLE, limit)._query( @@ -641,7 +622,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: ["%20%", "%25%", `%"john"%`, `%"mary"%`, limit], - sql: `select * from (select * from (select * from \"test\" where (LOWER(\"test\".\"age\") LIKE :1 AND LOWER(\"test\".\"age\") LIKE :2) and (LOWER(\"test\".\"name\") LIKE :3 AND LOWER(\"test\".\"name\") LIKE :4)) where rownum <= :5) \"test\"`, + sql: `select * from (select * from (select * from "test" where (LOWER("test"."age") LIKE :1 AND LOWER("test"."age") LIKE :2) and (LOWER("test"."name") LIKE :3 AND LOWER("test"."name") LIKE :4)) where rownum <= :5) "test"`, }) query = new Sql(SqlClient.ORACLE, limit)._query( @@ -655,7 +636,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: [`%jo%`, limit], - sql: `select * from (select * from (select * from \"test\" where LOWER(\"test\".\"name\") LIKE :1) where rownum <= :2) \"test\"`, + sql: `select * from (select * from (select * from "test" where LOWER("test"."name") LIKE :1) where rownum <= :2) "test"`, }) }) @@ -682,7 +663,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: ['{ "created_at":"2023-09-09T03:21:06.024Z" }'], - sql: `insert into \"test\" (\"name\") values ($1) returning *`, + sql: `insert into "test" ("name") values ($1) returning *`, }) }) @@ -695,7 +676,7 @@ describe("SQL query builder", () => { ) expect(query).toEqual({ bindings: [dateObj], - sql: `insert into \"test\" (\"name\") values ($1) returning *`, + sql: `insert into "test" ("name") values ($1) returning *`, }) }) diff --git a/packages/server/src/integrations/tests/sqlAlias.spec.ts b/packages/server/src/integrations/tests/sqlAlias.spec.ts index dd82dadac0..ccb164bcfd 100644 --- a/packages/server/src/integrations/tests/sqlAlias.spec.ts +++ b/packages/server/src/integrations/tests/sqlAlias.spec.ts @@ -294,7 +294,7 @@ describe("Captures of real examples", () => { type: "datasource", isSQL: false, }) - ) + ).toEqual(false) }) it("should disable when no fields", () => { diff --git a/packages/server/src/jsRunner/tests/jsRunner.spec.ts b/packages/server/src/jsRunner/tests/jsRunner.spec.ts index dc6e32f52c..7448555aac 100644 --- a/packages/server/src/jsRunner/tests/jsRunner.spec.ts +++ b/packages/server/src/jsRunner/tests/jsRunner.spec.ts @@ -30,12 +30,12 @@ describe("jsRunner (using isolated-vm)", () => { ) } - it("it can run a basic javascript", async () => { + it("can run a basic javascript", async () => { const output = await processJS(`return 1 + 2`) expect(output).toBe(3) }) - it("it can execute sloppy javascript", async () => { + it("can execute sloppy javascript", async () => { const output = await processJS(`a=2;b=3;return a + b`) expect(output).toBe(5) }) diff --git a/packages/server/src/middleware/tests/authorized.spec.ts b/packages/server/src/middleware/tests/authorized.spec.ts index 0741f50e4d..72c286cb01 100644 --- a/packages/server/src/middleware/tests/authorized.spec.ts +++ b/packages/server/src/middleware/tests/authorized.spec.ts @@ -213,11 +213,11 @@ describe("Authorization middleware", () => { it("will fetch resource permissions when resource is set", async () => { await config.executeMiddleware() - expect(config.throw).not.toBeCalled() + expect(config.throw).not.toHaveBeenCalled() expect(config.next).toHaveBeenCalled() - expect(mockedGetResourcePerms).toBeCalledTimes(1) - expect(mockedGetResourcePerms).toBeCalledWith(resourceId) + expect(mockedGetResourcePerms).toHaveBeenCalledTimes(1) + expect(mockedGetResourcePerms).toHaveBeenCalledWith(resourceId) }) }) }) diff --git a/packages/server/src/middleware/tests/trimViewRowInfo.spec.ts b/packages/server/src/middleware/tests/trimViewRowInfo.spec.ts index 40ff88c1e5..243f9a9329 100644 --- a/packages/server/src/middleware/tests/trimViewRowInfo.spec.ts +++ b/packages/server/src/middleware/tests/trimViewRowInfo.spec.ts @@ -133,8 +133,8 @@ describe("trimViewRowInfo middleware", () => { }) expect(config.params.sourceId).toEqual(table._id) - expect(config.next).toBeCalledTimes(1) - expect(config.throw).not.toBeCalled() + expect(config.next).toHaveBeenCalledTimes(1) + expect(config.throw).not.toHaveBeenCalled() }) it("when columns are defined, trimmed data is returned", async () => { @@ -162,7 +162,7 @@ describe("trimViewRowInfo middleware", () => { }) expect(config.params.sourceId).toEqual(table._id) - expect(config.next).toBeCalledTimes(1) - expect(config.throw).not.toBeCalled() + expect(config.next).toHaveBeenCalledTimes(1) + expect(config.throw).not.toHaveBeenCalled() }) }) diff --git a/packages/server/src/migrations/tests/index.spec.ts b/packages/server/src/migrations/tests/index.spec.ts index 236776cd3f..8eb59b8a0e 100644 --- a/packages/server/src/migrations/tests/index.spec.ts +++ b/packages/server/src/migrations/tests/index.spec.ts @@ -66,28 +66,25 @@ describe("migrations", () => { )[0] await migrations.runMigration(migration) - expect(events.app.created).toBeCalledTimes(1) - expect(events.app.published).toBeCalledTimes(1) - expect(events.automation.created).toBeCalledTimes(2) - expect(events.automation.stepCreated).toBeCalledTimes(1) - expect(events.datasource.created).toBeCalledTimes(2) - expect(events.layout.created).toBeCalledTimes(1) - expect(events.query.created).toBeCalledTimes(2) - expect(events.role.created).toBeCalledTimes(2) - expect(events.table.created).toBeCalledTimes(3) - expect(events.view.created).toBeCalledTimes(2) - expect(events.view.calculationCreated).toBeCalledTimes(1) - expect(events.view.filterCreated).toBeCalledTimes(1) - expect(events.screen.created).toBeCalledTimes(2) - expect(events.backfill.appSucceeded).toBeCalledTimes(2) - - const processor = events.processors.analyticsProcessor.processEvent - console.log(processor) + expect(events.app.created).toHaveBeenCalledTimes(1) + expect(events.app.published).toHaveBeenCalledTimes(1) + expect(events.automation.created).toHaveBeenCalledTimes(2) + expect(events.automation.stepCreated).toHaveBeenCalledTimes(1) + expect(events.datasource.created).toHaveBeenCalledTimes(2) + expect(events.layout.created).toHaveBeenCalledTimes(1) + expect(events.query.created).toHaveBeenCalledTimes(2) + expect(events.role.created).toHaveBeenCalledTimes(2) + expect(events.table.created).toHaveBeenCalledTimes(3) + expect(events.view.created).toHaveBeenCalledTimes(2) + expect(events.view.calculationCreated).toHaveBeenCalledTimes(1) + expect(events.view.filterCreated).toHaveBeenCalledTimes(1) + expect(events.screen.created).toHaveBeenCalledTimes(2) + expect(events.backfill.appSucceeded).toHaveBeenCalledTimes(2) // to make sure caching is working as expected expect( events.processors.analyticsProcessor.processEvent - ).toBeCalledTimes(23) + ).toHaveBeenCalledTimes(23) }) }) }) @@ -123,24 +120,24 @@ describe("migrations", () => { )[0] await migrations.runMigration(migration) - expect(events.user.created).toBeCalledTimes(3) - expect(events.role.assigned).toBeCalledTimes(2) - expect(events.user.permissionBuilderAssigned).toBeCalledTimes(1) // default test user - expect(events.user.permissionAdminAssigned).toBeCalledTimes(1) // admin from above - expect(events.rows.created).toBeCalledTimes(1) - expect(events.rows.created).toBeCalledWith(2, timestamp) - expect(events.email.SMTPCreated).toBeCalledTimes(1) - expect(events.auth.SSOCreated).toBeCalledTimes(2) - expect(events.auth.SSOActivated).toBeCalledTimes(2) - expect(events.org.logoUpdated).toBeCalledTimes(1) - expect(events.org.nameUpdated).toBeCalledTimes(1) - expect(events.org.platformURLUpdated).toBeCalledTimes(1) - expect(events.backfill.tenantSucceeded).toBeCalledTimes(1) + expect(events.user.created).toHaveBeenCalledTimes(3) + expect(events.role.assigned).toHaveBeenCalledTimes(2) + expect(events.user.permissionBuilderAssigned).toHaveBeenCalledTimes(1) // default test user + expect(events.user.permissionAdminAssigned).toHaveBeenCalledTimes(1) // admin from above + expect(events.rows.created).toHaveBeenCalledTimes(1) + expect(events.rows.created).toHaveBeenCalledWith(2, timestamp) + expect(events.email.SMTPCreated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOCreated).toHaveBeenCalledTimes(2) + expect(events.auth.SSOActivated).toHaveBeenCalledTimes(2) + expect(events.org.logoUpdated).toHaveBeenCalledTimes(1) + expect(events.org.nameUpdated).toHaveBeenCalledTimes(1) + expect(events.org.platformURLUpdated).toHaveBeenCalledTimes(1) + expect(events.backfill.tenantSucceeded).toHaveBeenCalledTimes(1) // to make sure caching is working as expected - expect(events.processors.analyticsProcessor.processEvent).toBeCalledTimes( - 19 - ) + expect( + events.processors.analyticsProcessor.processEvent + ).toHaveBeenCalledTimes(19) }) }) }) diff --git a/packages/server/src/sdk/app/tables/tests/tables.spec.ts b/packages/server/src/sdk/app/tables/tests/tables.spec.ts index 457988c476..6e2cf9efa8 100644 --- a/packages/server/src/sdk/app/tables/tests/tables.spec.ts +++ b/packages/server/src/sdk/app/tables/tests/tables.spec.ts @@ -84,7 +84,7 @@ describe("table sdk", () => { }, }) - expect(sdk.views.enrichSchema).toBeCalledTimes(3) + expect(sdk.views.enrichSchema).toHaveBeenCalledTimes(3) expect(res).toEqual({ ...basicTable, diff --git a/packages/server/src/sdk/tests/attachments.spec.ts b/packages/server/src/sdk/tests/attachments.spec.ts index f1abb246f8..0fd43ac5a8 100644 --- a/packages/server/src/sdk/tests/attachments.spec.ts +++ b/packages/server/src/sdk/tests/attachments.spec.ts @@ -44,7 +44,7 @@ import { db as dbCore } from "@budibase/backend-core" import sdk from "../index" describe("should be able to re-write attachment URLs", () => { - it("it should update URLs on a number of rows over the limit", async () => { + it("should update URLs on a number of rows over the limit", async () => { const db = dbCore.getDB("app_aaa") await db.put(table) const limit = 30 diff --git a/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts b/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts index 3c58d2c056..cefea7e504 100644 --- a/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts @@ -64,12 +64,12 @@ describe("attachment cleanup", () => { await AttachmentCleanup.tableUpdate(originalTable, [row()], { oldTable: table(), }) - expect(mockedDeleteFiles).toBeCalledWith(BUCKET, [FILE_NAME]) + expect(mockedDeleteFiles).toHaveBeenCalledWith(BUCKET, [FILE_NAME]) }) it("should be able to cleanup a table deletion", async () => { await AttachmentCleanup.tableDelete(table(), [row()]) - expect(mockedDeleteFiles).toBeCalledWith(BUCKET, [FILE_NAME]) + expect(mockedDeleteFiles).toHaveBeenCalledWith(BUCKET, [FILE_NAME]) }) it("should handle table column renaming", async () => { @@ -80,12 +80,12 @@ describe("attachment cleanup", () => { oldTable: table(), rename: { old: "attach", updated: "attach2" }, }) - expect(mockedDeleteFiles).not.toBeCalled() + expect(mockedDeleteFiles).not.toHaveBeenCalled() }) it("shouldn't cleanup if no table changes", async () => { await AttachmentCleanup.tableUpdate(table(), [row()], { oldTable: table() }) - expect(mockedDeleteFiles).not.toBeCalled() + expect(mockedDeleteFiles).not.toHaveBeenCalled() }) it("should handle row updates", async () => { @@ -95,12 +95,12 @@ describe("attachment cleanup", () => { row: updatedRow, oldRow: row(), }) - expect(mockedDeleteFiles).toBeCalledWith(BUCKET, [FILE_NAME]) + expect(mockedDeleteFiles).toHaveBeenCalledWith(BUCKET, [FILE_NAME]) }) it("should handle row deletion", async () => { await AttachmentCleanup.rowDelete(table(), [row()]) - expect(mockedDeleteFiles).toBeCalledWith(BUCKET, [FILE_NAME]) + expect(mockedDeleteFiles).toHaveBeenCalledWith(BUCKET, [FILE_NAME]) }) it("should handle row deletion and not throw when attachments are undefined", async () => { @@ -113,7 +113,7 @@ describe("attachment cleanup", () => { it("shouldn't cleanup attachments if row not updated", async () => { await AttachmentCleanup.rowUpdate(table(), { row: row(), oldRow: row() }) - expect(mockedDeleteFiles).not.toBeCalled() + expect(mockedDeleteFiles).not.toHaveBeenCalled() }) it("should be able to cleanup a column and not throw when attachments are undefined", async () => { @@ -126,8 +126,8 @@ describe("attachment cleanup", () => { oldTable: table(), } ) - expect(mockedDeleteFiles).toBeCalledTimes(1) - expect(mockedDeleteFiles).toBeCalledWith(BUCKET, ["file 1", "file 2"]) + expect(mockedDeleteFiles).toHaveBeenCalledTimes(1) + expect(mockedDeleteFiles).toHaveBeenCalledWith(BUCKET, ["file 1", "file 2"]) }) it("should be able to cleanup a column and not throw when ALL attachments are undefined", async () => { @@ -140,6 +140,6 @@ describe("attachment cleanup", () => { oldTable: table(), } ) - expect(mockedDeleteFiles).not.toBeCalled() + expect(mockedDeleteFiles).not.toHaveBeenCalled() }) }) diff --git a/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts b/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts index b6174861d4..e6ceaae323 100644 --- a/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts @@ -67,8 +67,8 @@ describe("bbReferenceProcessor", () => { ) expect(result).toEqual(userId) - expect(cacheGetUsersSpy).toBeCalledTimes(1) - expect(cacheGetUsersSpy).toBeCalledWith([userId]) + expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1) + expect(cacheGetUsersSpy).toHaveBeenCalledWith([userId]) }) it("throws an error given an invalid id", async () => { @@ -78,9 +78,9 @@ describe("bbReferenceProcessor", () => { config.doInTenant(() => processInputBBReferences(userId, FieldSubtype.USER) ) - ).rejects.toThrowError(new InvalidBBRefError(userId, FieldSubtype.USER)) - expect(cacheGetUsersSpy).toBeCalledTimes(1) - expect(cacheGetUsersSpy).toBeCalledWith([userId]) + ).rejects.toThrow(new InvalidBBRefError(userId, FieldSubtype.USER)) + expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1) + expect(cacheGetUsersSpy).toHaveBeenCalledWith([userId]) }) it("validates valid user ids as csv", async () => { @@ -92,8 +92,8 @@ describe("bbReferenceProcessor", () => { ) expect(result).toEqual(userIds.join(",")) - expect(cacheGetUsersSpy).toBeCalledTimes(1) - expect(cacheGetUsersSpy).toBeCalledWith(userIds) + expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1) + expect(cacheGetUsersSpy).toHaveBeenCalledWith(userIds) }) it("throws an error given an invalid id in a csv", async () => { @@ -110,9 +110,7 @@ describe("bbReferenceProcessor", () => { config.doInTenant(() => processInputBBReferences(userIdCsv, FieldSubtype.USER) ) - ).rejects.toThrowError( - new InvalidBBRefError(wrongId, FieldSubtype.USER) - ) + ).rejects.toThrow(new InvalidBBRefError(wrongId, FieldSubtype.USER)) }) it("validate valid user object", async () => { @@ -123,8 +121,8 @@ describe("bbReferenceProcessor", () => { ) expect(result).toEqual(userId) - expect(cacheGetUsersSpy).toBeCalledTimes(1) - expect(cacheGetUsersSpy).toBeCalledWith([userId]) + expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1) + expect(cacheGetUsersSpy).toHaveBeenCalledWith([userId]) }) it("validate valid user object array", async () => { @@ -135,8 +133,8 @@ describe("bbReferenceProcessor", () => { ) expect(result).toEqual(userIds.join(",")) - expect(cacheGetUsersSpy).toBeCalledTimes(1) - expect(cacheGetUsersSpy).toBeCalledWith(userIds) + expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1) + expect(cacheGetUsersSpy).toHaveBeenCalledWith(userIds) }) it("empty strings will return null", async () => { @@ -185,8 +183,8 @@ describe("bbReferenceProcessor", () => { lastName: user.lastName, }, ]) - expect(cacheGetUsersSpy).toBeCalledTimes(1) - expect(cacheGetUsersSpy).toBeCalledWith([userId]) + expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1) + expect(cacheGetUsersSpy).toHaveBeenCalledWith([userId]) }) it("fetches user given a valid string id csv", async () => { @@ -213,8 +211,8 @@ describe("bbReferenceProcessor", () => { })) ) ) - expect(cacheGetUsersSpy).toBeCalledTimes(1) - expect(cacheGetUsersSpy).toBeCalledWith([userId1, userId2]) + expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1) + expect(cacheGetUsersSpy).toHaveBeenCalledWith([userId1, userId2]) }) }) }) diff --git a/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts index b6c1db9159..859a203133 100644 --- a/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts @@ -62,8 +62,10 @@ describe("rowProcessor - inputProcessing", () => { const { row } = await inputProcessing(userId, table, newRow) - expect(bbReferenceProcessor.processInputBBReferences).toBeCalledTimes(1) - expect(bbReferenceProcessor.processInputBBReferences).toBeCalledWith( + expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledTimes( + 1 + ) + expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledWith( "123", "user" ) @@ -71,7 +73,7 @@ describe("rowProcessor - inputProcessing", () => { expect(row).toEqual({ ...newRow, user }) }) - it("it does not process BB references if on the schema but it is not populated", async () => { + it("does not process BB references if on the schema but it is not populated", async () => { const userId = generator.guid() const table: Table = { @@ -107,12 +109,12 @@ describe("rowProcessor - inputProcessing", () => { const { row } = await inputProcessing(userId, table, newRow) - expect(bbReferenceProcessor.processInputBBReferences).not.toBeCalled() + expect(bbReferenceProcessor.processInputBBReferences).not.toHaveBeenCalled() expect(row).toEqual({ ...newRow, user: undefined }) }) it.each([undefined, null, ""])( - "it does not process BB references the field is $%", + "does not process BB references the field is $%", async userValue => { const userId = generator.guid() @@ -150,12 +152,14 @@ describe("rowProcessor - inputProcessing", () => { const { row } = await inputProcessing(userId, table, newRow) - expect(bbReferenceProcessor.processInputBBReferences).not.toBeCalled() + expect( + bbReferenceProcessor.processInputBBReferences + ).not.toHaveBeenCalled() expect(row).toEqual(newRow) } ) - it("it does not process BB references if not in the schema", async () => { + it("does not process BB references if not in the schema", async () => { const userId = generator.guid() const table: Table = { @@ -191,7 +195,7 @@ describe("rowProcessor - inputProcessing", () => { const { row } = await inputProcessing(userId, table, newRow) - expect(bbReferenceProcessor.processInputBBReferences).not.toBeCalled() + expect(bbReferenceProcessor.processInputBBReferences).not.toHaveBeenCalled() expect(row).toEqual({ name: "Jack", user: 123, diff --git a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts index 95ce340910..a17bd5f393 100644 --- a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts @@ -64,8 +64,10 @@ describe("rowProcessor - outputProcessing", () => { expect(result).toEqual({ name: "Jack", user }) - expect(bbReferenceProcessor.processOutputBBReferences).toBeCalledTimes(1) - expect(bbReferenceProcessor.processOutputBBReferences).toBeCalledWith( + expect( + bbReferenceProcessor.processOutputBBReferences + ).toHaveBeenCalledTimes(1) + expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledWith( "123", FieldSubtype.USER ) @@ -150,7 +152,9 @@ describe("rowProcessor - outputProcessing", () => { expect(result).toEqual({ name: "Jack" }) - expect(bbReferenceProcessor.processOutputBBReferences).toBeCalledTimes(1) + expect( + bbReferenceProcessor.processOutputBBReferences + ).toHaveBeenCalledTimes(1) }) it("does not fetch bb references when not in the schema", async () => { @@ -189,6 +193,8 @@ describe("rowProcessor - outputProcessing", () => { expect(result).toEqual({ name: "Jack", user: "123" }) - expect(bbReferenceProcessor.processOutputBBReferences).not.toBeCalled() + expect( + bbReferenceProcessor.processOutputBBReferences + ).not.toHaveBeenCalled() }) }) diff --git a/packages/string-templates/test/manifest.spec.ts b/packages/string-templates/test/manifest.spec.ts index d8fee0fb1a..de0e3355fd 100644 --- a/packages/string-templates/test/manifest.spec.ts +++ b/packages/string-templates/test/manifest.spec.ts @@ -48,7 +48,7 @@ describe("manifest", () => { const arrays = hbs.match(/\[[^/\]]+\]/) arrays?.forEach((arrayString, i) => { hbs = hbs.replace(new RegExp(escapeRegExp(arrayString)), `array${i}`) - context[`array${i}`] = JSON.parse(arrayString.replace(/\'/g, '"')) + context[`array${i}`] = JSON.parse(arrayString.replace(/'/g, '"')) }) let result = await processString(hbs, context) diff --git a/packages/types/src/sdk/middleware/matchers.ts b/packages/types/src/sdk/middleware/matchers.ts index fc4ceb323e..671505eb13 100644 --- a/packages/types/src/sdk/middleware/matchers.ts +++ b/packages/types/src/sdk/middleware/matchers.ts @@ -8,15 +8,10 @@ export interface EndpointMatcher { * ALL is also accepted to cover all verbs. */ method: string - /** - * The route must match exactly - not just begins with - */ - strict?: boolean } export interface RegexMatcher { regex: RegExp method: string - strict: boolean route: string } diff --git a/packages/worker/src/api/routes/global/tests/auth.spec.ts b/packages/worker/src/api/routes/global/tests/auth.spec.ts index e9edfdf1cf..a81d5db435 100644 --- a/packages/worker/src/api/routes/global/tests/auth.spec.ts +++ b/packages/worker/src/api/routes/global/tests/auth.spec.ts @@ -58,7 +58,7 @@ describe("/api/global/auth", () => { const response = await config.api.auth.login(tenantId, email, password) expectSetAuthCookie(response) - expect(events.auth.login).toBeCalledTimes(1) + expect(events.auth.login).toHaveBeenCalledTimes(1) }) it("should return 403 with incorrect credentials", async () => { @@ -139,7 +139,7 @@ describe("/api/global/auth", () => { describe("POST /api/global/auth/logout", () => { it("should logout", async () => { const response = await config.api.auth.logout() - expect(events.auth.logout).toBeCalledTimes(1) + expect(events.auth.logout).toHaveBeenCalledTimes(1) const authCookie = getAuthCookie(response) expect(authCookie).toBe("") @@ -160,8 +160,8 @@ describe("/api/global/auth", () => { }) expect(sendMailMock).toHaveBeenCalled() expect(code).toBeDefined() - expect(events.user.passwordResetRequested).toBeCalledTimes(1) - expect(events.user.passwordResetRequested).toBeCalledWith(user) + expect(events.user.passwordResetRequested).toHaveBeenCalledTimes(1) + expect(events.user.passwordResetRequested).toHaveBeenCalledWith(user) }) describe("sso user", () => { @@ -211,8 +211,8 @@ describe("/api/global/auth", () => { delete user.password expect(res.body).toEqual({ message: "password reset successfully." }) - expect(events.user.passwordReset).toBeCalledTimes(1) - expect(events.user.passwordReset).toBeCalledWith(user) + expect(events.user.passwordReset).toHaveBeenCalledTimes(1) + expect(events.user.passwordReset).toHaveBeenCalledWith(user) // login using new password await config.api.auth.login(user.tenantId, user.email, newPassword) @@ -360,21 +360,16 @@ describe("/api/global/auth", () => { const res = await config.api.configs.OIDCCallback(configId, preAuthRes) - expect(events.auth.login).toBeCalledWith("oidc", "oauth@example.com") - expect(events.auth.login).toBeCalledTimes(1) + expect(events.auth.login).toHaveBeenCalledWith( + "oidc", + "oauth@example.com" + ) + expect(events.auth.login).toHaveBeenCalledTimes(1) expect(res.status).toBe(302) const location: string = res.get("location") expect(location).toBe("/") expectSetAuthCookie(res) }) }) - - // SINGLE TENANT - - describe("GET /api/global/auth/oidc/callback", () => {}) - - describe("GET /api/global/auth/oidc/callback", () => {}) - - describe("GET /api/admin/auth/oidc/callback", () => {}) }) }) diff --git a/packages/worker/src/api/routes/global/tests/configs.spec.ts b/packages/worker/src/api/routes/global/tests/configs.spec.ts index 4d9f28d2cb..6e3558ba86 100644 --- a/packages/worker/src/api/routes/global/tests/configs.spec.ts +++ b/packages/worker/src/api/routes/global/tests/configs.spec.ts @@ -57,20 +57,22 @@ describe("configs", () => { describe("create", () => { it("should create activated google config", async () => { await saveGoogleConfig() - expect(events.auth.SSOCreated).toBeCalledTimes(1) - expect(events.auth.SSOCreated).toBeCalledWith(ConfigType.GOOGLE) - expect(events.auth.SSODeactivated).not.toBeCalled() - expect(events.auth.SSOActivated).toBeCalledTimes(1) - expect(events.auth.SSOActivated).toBeCalledWith(ConfigType.GOOGLE) + expect(events.auth.SSOCreated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOCreated).toHaveBeenCalledWith(ConfigType.GOOGLE) + expect(events.auth.SSODeactivated).not.toHaveBeenCalled() + expect(events.auth.SSOActivated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOActivated).toHaveBeenCalledWith( + ConfigType.GOOGLE + ) await config.deleteConfig(ConfigType.GOOGLE) }) it("should create deactivated google config", async () => { await saveGoogleConfig({ activated: false }) - expect(events.auth.SSOCreated).toBeCalledTimes(1) - expect(events.auth.SSOCreated).toBeCalledWith(ConfigType.GOOGLE) - expect(events.auth.SSOActivated).not.toBeCalled() - expect(events.auth.SSODeactivated).not.toBeCalled() + expect(events.auth.SSOCreated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOCreated).toHaveBeenCalledWith(ConfigType.GOOGLE) + expect(events.auth.SSOActivated).not.toHaveBeenCalled() + expect(events.auth.SSODeactivated).not.toHaveBeenCalled() await config.deleteConfig(ConfigType.GOOGLE) }) }) @@ -84,11 +86,13 @@ describe("configs", () => { googleConf._id, googleConf._rev ) - expect(events.auth.SSOUpdated).toBeCalledTimes(1) - expect(events.auth.SSOUpdated).toBeCalledWith(ConfigType.GOOGLE) - expect(events.auth.SSOActivated).not.toBeCalled() - expect(events.auth.SSODeactivated).toBeCalledTimes(1) - expect(events.auth.SSODeactivated).toBeCalledWith(ConfigType.GOOGLE) + expect(events.auth.SSOUpdated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.GOOGLE) + expect(events.auth.SSOActivated).not.toHaveBeenCalled() + expect(events.auth.SSODeactivated).toHaveBeenCalledTimes(1) + expect(events.auth.SSODeactivated).toHaveBeenCalledWith( + ConfigType.GOOGLE + ) await config.deleteConfig(ConfigType.GOOGLE) }) @@ -100,11 +104,13 @@ describe("configs", () => { googleConf._id, googleConf._rev ) - expect(events.auth.SSOUpdated).toBeCalledTimes(1) - expect(events.auth.SSOUpdated).toBeCalledWith(ConfigType.GOOGLE) - expect(events.auth.SSODeactivated).not.toBeCalled() - expect(events.auth.SSOActivated).toBeCalledTimes(1) - expect(events.auth.SSOActivated).toBeCalledWith(ConfigType.GOOGLE) + expect(events.auth.SSOUpdated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.GOOGLE) + expect(events.auth.SSODeactivated).not.toHaveBeenCalled() + expect(events.auth.SSOActivated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOActivated).toHaveBeenCalledWith( + ConfigType.GOOGLE + ) await config.deleteConfig(ConfigType.GOOGLE) }) }) @@ -123,20 +129,20 @@ describe("configs", () => { describe("create", () => { it("should create activated OIDC config", async () => { await saveOIDCConfig() - expect(events.auth.SSOCreated).toBeCalledTimes(1) - expect(events.auth.SSOCreated).toBeCalledWith(ConfigType.OIDC) - expect(events.auth.SSODeactivated).not.toBeCalled() - expect(events.auth.SSOActivated).toBeCalledTimes(1) - expect(events.auth.SSOActivated).toBeCalledWith(ConfigType.OIDC) + expect(events.auth.SSOCreated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOCreated).toHaveBeenCalledWith(ConfigType.OIDC) + expect(events.auth.SSODeactivated).not.toHaveBeenCalled() + expect(events.auth.SSOActivated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOActivated).toHaveBeenCalledWith(ConfigType.OIDC) await config.deleteConfig(ConfigType.OIDC) }) it("should create deactivated OIDC config", async () => { await saveOIDCConfig({ activated: false }) - expect(events.auth.SSOCreated).toBeCalledTimes(1) - expect(events.auth.SSOCreated).toBeCalledWith(ConfigType.OIDC) - expect(events.auth.SSOActivated).not.toBeCalled() - expect(events.auth.SSODeactivated).not.toBeCalled() + expect(events.auth.SSOCreated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOCreated).toHaveBeenCalledWith(ConfigType.OIDC) + expect(events.auth.SSOActivated).not.toHaveBeenCalled() + expect(events.auth.SSODeactivated).not.toHaveBeenCalled() await config.deleteConfig(ConfigType.OIDC) }) }) @@ -150,11 +156,13 @@ describe("configs", () => { oidcConf._id, oidcConf._rev ) - expect(events.auth.SSOUpdated).toBeCalledTimes(1) - expect(events.auth.SSOUpdated).toBeCalledWith(ConfigType.OIDC) - expect(events.auth.SSOActivated).not.toBeCalled() - expect(events.auth.SSODeactivated).toBeCalledTimes(1) - expect(events.auth.SSODeactivated).toBeCalledWith(ConfigType.OIDC) + expect(events.auth.SSOUpdated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.OIDC) + expect(events.auth.SSOActivated).not.toHaveBeenCalled() + expect(events.auth.SSODeactivated).toHaveBeenCalledTimes(1) + expect(events.auth.SSODeactivated).toHaveBeenCalledWith( + ConfigType.OIDC + ) await config.deleteConfig(ConfigType.OIDC) }) @@ -166,11 +174,11 @@ describe("configs", () => { oidcConf._id, oidcConf._rev ) - expect(events.auth.SSOUpdated).toBeCalledTimes(1) - expect(events.auth.SSOUpdated).toBeCalledWith(ConfigType.OIDC) - expect(events.auth.SSODeactivated).not.toBeCalled() - expect(events.auth.SSOActivated).toBeCalledTimes(1) - expect(events.auth.SSOActivated).toBeCalledWith(ConfigType.OIDC) + expect(events.auth.SSOUpdated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.OIDC) + expect(events.auth.SSODeactivated).not.toHaveBeenCalled() + expect(events.auth.SSOActivated).toHaveBeenCalledTimes(1) + expect(events.auth.SSOActivated).toHaveBeenCalledWith(ConfigType.OIDC) await config.deleteConfig(ConfigType.OIDC) }) }) @@ -190,8 +198,8 @@ describe("configs", () => { it("should create SMTP config", async () => { await config.deleteConfig(ConfigType.SMTP) await saveSMTPConfig() - expect(events.email.SMTPUpdated).not.toBeCalled() - expect(events.email.SMTPCreated).toBeCalledTimes(1) + expect(events.email.SMTPUpdated).not.toHaveBeenCalled() + expect(events.email.SMTPCreated).toHaveBeenCalledTimes(1) await config.deleteConfig(ConfigType.SMTP) }) }) @@ -201,8 +209,8 @@ describe("configs", () => { const smtpConf = await saveSMTPConfig() jest.clearAllMocks() await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev) - expect(events.email.SMTPCreated).not.toBeCalled() - expect(events.email.SMTPUpdated).toBeCalledTimes(1) + expect(events.email.SMTPCreated).not.toHaveBeenCalled() + expect(events.email.SMTPUpdated).toHaveBeenCalledTimes(1) await config.deleteConfig(ConfigType.SMTP) }) }) @@ -215,9 +223,9 @@ describe("configs", () => { await saveSettingsConfig() - expect(events.org.nameUpdated).not.toBeCalled() - expect(events.org.logoUpdated).not.toBeCalled() - expect(events.org.platformURLUpdated).not.toBeCalled() + expect(events.org.nameUpdated).not.toHaveBeenCalled() + expect(events.org.logoUpdated).not.toHaveBeenCalled() + expect(events.org.platformURLUpdated).not.toHaveBeenCalled() }) it("should create settings config with non-default settings", async () => { @@ -231,9 +239,9 @@ describe("configs", () => { await saveSettingsConfig(conf) - expect(events.org.nameUpdated).toBeCalledTimes(1) - expect(events.org.logoUpdated).toBeCalledTimes(1) - expect(events.org.platformURLUpdated).toBeCalledTimes(1) + expect(events.org.nameUpdated).toHaveBeenCalledTimes(1) + expect(events.org.logoUpdated).toHaveBeenCalledTimes(1) + expect(events.org.platformURLUpdated).toHaveBeenCalledTimes(1) config.cloudHosted() }) }) @@ -253,9 +261,9 @@ describe("configs", () => { settingsConfig._rev ) - expect(events.org.nameUpdated).toBeCalledTimes(1) - expect(events.org.logoUpdated).toBeCalledTimes(1) - expect(events.org.platformURLUpdated).toBeCalledTimes(1) + expect(events.org.nameUpdated).toHaveBeenCalledTimes(1) + expect(events.org.logoUpdated).toHaveBeenCalledTimes(1) + expect(events.org.platformURLUpdated).toHaveBeenCalledTimes(1) config.cloudHosted() }) }) diff --git a/packages/worker/src/api/routes/global/tests/groups.spec.ts b/packages/worker/src/api/routes/global/tests/groups.spec.ts index 414518d763..bc489348df 100644 --- a/packages/worker/src/api/routes/global/tests/groups.spec.ts +++ b/packages/worker/src/api/routes/global/tests/groups.spec.ts @@ -25,9 +25,9 @@ describe("/api/global/groups", () => { it("should be able to create a new group", async () => { const group = structures.groups.UserGroup() await config.api.groups.saveGroup(group) - expect(events.group.created).toBeCalledTimes(1) - expect(events.group.updated).not.toBeCalled() - expect(events.group.permissionsEdited).not.toBeCalled() + expect(events.group.created).toHaveBeenCalledTimes(1) + expect(events.group.updated).not.toHaveBeenCalled() + expect(events.group.permissionsEdited).not.toHaveBeenCalled() }) it("should not allow undefined names", async () => { @@ -57,7 +57,7 @@ describe("/api/global/groups", () => { it("should trim names", async () => { const group = { ...structures.groups.UserGroup(), name: " group name " } await config.api.groups.saveGroup(group) - expect(events.group.created).toBeCalledWith( + expect(events.group.created).toHaveBeenCalledWith( expect.objectContaining({ name: "group name" }) ) }) @@ -100,8 +100,8 @@ describe("/api/global/groups", () => { } await config.api.groups.saveGroup(updatedGroup) - expect(events.group.updated).toBeCalledTimes(1) - expect(events.group.permissionsEdited).not.toBeCalled() + expect(events.group.updated).toHaveBeenCalledTimes(1) + expect(events.group.permissionsEdited).not.toHaveBeenCalled() }) describe("scim", () => { @@ -135,7 +135,7 @@ describe("/api/global/groups", () => { }, }) - expect(events.group.updated).not.toBeCalled() + expect(events.group.updated).not.toHaveBeenCalled() }) it("update will not amend the SCIM fields", async () => { @@ -151,7 +151,7 @@ describe("/api/global/groups", () => { expect: 200, }) - expect(events.group.updated).toBeCalledTimes(1) + expect(events.group.updated).toHaveBeenCalledTimes(1) expect( ( await config.api.groups.find(group._id!, { @@ -176,7 +176,7 @@ describe("/api/global/groups", () => { let oldGroup = await config.api.groups.saveGroup(group) await config.api.groups.deleteGroup(oldGroup.body._id, oldGroup.body._rev) - expect(events.group.deleted).toBeCalledTimes(1) + expect(events.group.deleted).toHaveBeenCalledTimes(1) }) }) diff --git a/packages/worker/src/api/routes/global/tests/license.spec.ts b/packages/worker/src/api/routes/global/tests/license.spec.ts index e08292c061..7c8fdb553c 100644 --- a/packages/worker/src/api/routes/global/tests/license.spec.ts +++ b/packages/worker/src/api/routes/global/tests/license.spec.ts @@ -22,7 +22,7 @@ describe("/api/global/license", () => { it("returns 200", async () => { const res = await config.api.license.refresh() expect(res.status).toBe(200) - expect(licensing.cache.refresh).toBeCalledTimes(1) + expect(licensing.cache.refresh).toHaveBeenCalledTimes(1) }) }) @@ -42,7 +42,9 @@ describe("/api/global/license", () => { licenseKey: "licenseKey", }) expect(res.status).toBe(200) - expect(licensing.keys.activateLicenseKey).toBeCalledWith("licenseKey") + expect(licensing.keys.activateLicenseKey).toHaveBeenCalledWith( + "licenseKey" + ) }) }) @@ -64,7 +66,7 @@ describe("/api/global/license", () => { describe("DELETE /api/global/license/key", () => { it("returns 204", async () => { const res = await config.api.license.deleteLicenseKey() - expect(licensing.keys.deleteLicenseKey).toBeCalledTimes(1) + expect(licensing.keys.deleteLicenseKey).toHaveBeenCalledTimes(1) expect(res.status).toBe(204) }) }) @@ -74,9 +76,9 @@ describe("/api/global/license", () => { const res = await config.api.license.activateOfflineLicense({ offlineLicenseToken: "offlineLicenseToken", }) - expect(licensing.offline.activateOfflineLicenseToken).toBeCalledWith( - "offlineLicenseToken" - ) + expect( + licensing.offline.activateOfflineLicenseToken + ).toHaveBeenCalledWith("offlineLicenseToken") expect(res.status).toBe(200) }) }) @@ -102,7 +104,9 @@ describe("/api/global/license", () => { it("returns 204", async () => { const res = await config.api.license.deleteOfflineLicense() expect(res.status).toBe(204) - expect(licensing.offline.deleteOfflineLicenseToken).toBeCalledTimes(1) + expect(licensing.offline.deleteOfflineLicenseToken).toHaveBeenCalledTimes( + 1 + ) }) }) diff --git a/packages/worker/src/api/routes/global/tests/realEmail.spec.ts b/packages/worker/src/api/routes/global/tests/realEmail.spec.ts index 544c2651dc..ee53f844f9 100644 --- a/packages/worker/src/api/routes/global/tests/realEmail.spec.ts +++ b/packages/worker/src/api/routes/global/tests/realEmail.spec.ts @@ -43,7 +43,6 @@ describe("/api/global/email", () => { } expect(res.body.message).toBeDefined() const testUrl = nodemailer.getTestMessageUrl(res.body) - console.log(`${purpose} URL: ${testUrl}`) expect(testUrl).toBeDefined() response = await fetch(testUrl) text = await response.text() diff --git a/packages/worker/src/api/routes/global/tests/scim.spec.ts b/packages/worker/src/api/routes/global/tests/scim.spec.ts index ad43f089db..258702a3b3 100644 --- a/packages/worker/src/api/routes/global/tests/scim.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim.spec.ts @@ -304,7 +304,7 @@ describe("scim", () => { await postScimUser({ body }) - expect(events.user.created).toBeCalledTimes(1) + expect(events.user.created).toHaveBeenCalledTimes(1) }) it("if the username is an email, the user name will be used as email", async () => { @@ -571,7 +571,7 @@ describe("scim", () => { await patchScimUser({ id: user.id, body }) - expect(events.user.updated).toBeCalledTimes(1) + expect(events.user.updated).toHaveBeenCalledTimes(1) }) }) @@ -603,7 +603,7 @@ describe("scim", () => { it("an event is dispatched", async () => { await deleteScimUser(user.id, { expect: 204 }) - expect(events.user.deleted).toBeCalledTimes(1) + expect(events.user.deleted).toHaveBeenCalledTimes(1) }) it("an account holder cannot be removed even when synched", async () => { diff --git a/packages/worker/src/api/routes/global/tests/self.spec.ts b/packages/worker/src/api/routes/global/tests/self.spec.ts index 274efb0aff..55eed0bca2 100644 --- a/packages/worker/src/api/routes/global/tests/self.spec.ts +++ b/packages/worker/src/api/routes/global/tests/self.spec.ts @@ -41,10 +41,10 @@ describe("/api/global/self", () => { user._rev = dbUser._rev user.dayPassRecordedAt = mocks.date.MOCK_DATE.toISOString() expect(res.body._id).toBe(user._id) - expect(events.user.updated).toBeCalledTimes(1) - expect(events.user.updated).toBeCalledWith(dbUser) - expect(events.user.passwordUpdated).toBeCalledTimes(1) - expect(events.user.passwordUpdated).toBeCalledWith(dbUser) + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.user.updated).toHaveBeenCalledWith(dbUser) + expect(events.user.passwordUpdated).toHaveBeenCalledTimes(1) + expect(events.user.passwordUpdated).toHaveBeenCalledWith(dbUser) }) }) diff --git a/packages/worker/src/api/routes/global/tests/users.spec.ts b/packages/worker/src/api/routes/global/tests/users.spec.ts index 744b0a5578..37f5721881 100644 --- a/packages/worker/src/api/routes/global/tests/users.spec.ts +++ b/packages/worker/src/api/routes/global/tests/users.spec.ts @@ -39,7 +39,7 @@ describe("/api/global/users", () => { expect(sendMailMock).toHaveBeenCalled() expect(code).toBeDefined() - expect(events.user.invited).toBeCalledTimes(1) + expect(events.user.invited).toHaveBeenCalledTimes(1) }) it("should not be able to generate an invitation for existing user", async () => { @@ -52,7 +52,7 @@ describe("/api/global/users", () => { expect(res.body.message).toBe(`Unavailable`) expect(sendMailMock).toHaveBeenCalledTimes(0) expect(code).toBeUndefined() - expect(events.user.invited).toBeCalledTimes(0) + expect(events.user.invited).toHaveBeenCalledTimes(0) }) it("should not invite the same user twice", async () => { @@ -70,7 +70,7 @@ describe("/api/global/users", () => { expect(res.body.message).toBe(`Unavailable`) expect(sendMailMock).toHaveBeenCalledTimes(0) expect(code).toBeUndefined() - expect(events.user.invited).toBeCalledTimes(0) + expect(events.user.invited).toHaveBeenCalledTimes(0) }) it("should be able to create new user from invite", async () => { @@ -86,8 +86,8 @@ describe("/api/global/users", () => { const user = await config.getUser(email) expect(user).toBeDefined() expect(user!._id).toEqual(res.body._id) - expect(events.user.inviteAccepted).toBeCalledTimes(1) - expect(events.user.inviteAccepted).toBeCalledWith(user) + expect(events.user.inviteAccepted).toHaveBeenCalledTimes(1) + expect(events.user.inviteAccepted).toHaveBeenCalledWith(user) }) }) @@ -105,7 +105,7 @@ describe("/api/global/users", () => { expect(body.successful.length).toBe(2) expect(body.unsuccessful.length).toBe(0) expect(sendMailMock).toHaveBeenCalledTimes(2) - expect(events.user.invited).toBeCalledTimes(2) + expect(events.user.invited).toHaveBeenCalledTimes(2) }) it("should not be able to generate an invitation for existing user", async () => { @@ -118,7 +118,7 @@ describe("/api/global/users", () => { expect(body.unsuccessful.length).toBe(1) expect(body.unsuccessful[0].reason).toBe("Unavailable") expect(sendMailMock).toHaveBeenCalledTimes(0) - expect(events.user.invited).toBeCalledTimes(0) + expect(events.user.invited).toHaveBeenCalledTimes(0) }) it("should not be able to generate an invitation for user that has already been invited", async () => { @@ -135,7 +135,7 @@ describe("/api/global/users", () => { expect(body.unsuccessful.length).toBe(1) expect(body.unsuccessful[0].reason).toBe("Unavailable") expect(sendMailMock).toHaveBeenCalledTimes(0) - expect(events.user.invited).toBeCalledTimes(0) + expect(events.user.invited).toHaveBeenCalledTimes(0) }) }) @@ -149,7 +149,7 @@ describe("/api/global/users", () => { expect(response.created?.successful.length).toBe(0) expect(response.created?.unsuccessful.length).toBe(1) expect(response.created?.unsuccessful[0].email).toBe(user.email) - expect(events.user.created).toBeCalledTimes(0) + expect(events.user.created).toHaveBeenCalledTimes(0) }) it("should ignore users existing in other tenants", async () => { @@ -162,7 +162,7 @@ describe("/api/global/users", () => { expect(response.created?.successful.length).toBe(0) expect(response.created?.unsuccessful.length).toBe(1) expect(response.created?.unsuccessful[0].email).toBe(user.email) - expect(events.user.created).toBeCalledTimes(0) + expect(events.user.created).toHaveBeenCalledTimes(0) }) }) @@ -177,7 +177,7 @@ describe("/api/global/users", () => { expect(response.created?.successful.length).toBe(0) expect(response.created?.unsuccessful.length).toBe(1) expect(response.created?.unsuccessful[0].email).toBe(user.email) - expect(events.user.created).toBeCalledTimes(0) + expect(events.user.created).toHaveBeenCalledTimes(0) }) it("should be able to bulk create users", async () => { @@ -196,9 +196,9 @@ describe("/api/global/users", () => { expect(response.created?.successful[1].email).toBe(admin.email) expect(response.created?.successful[2].email).toBe(user.email) expect(response.created?.unsuccessful.length).toBe(0) - expect(events.user.created).toBeCalledTimes(3) - expect(events.user.permissionAdminAssigned).toBeCalledTimes(1) - expect(events.user.permissionBuilderAssigned).toBeCalledTimes(2) + expect(events.user.created).toHaveBeenCalledTimes(3) + expect(events.user.permissionAdminAssigned).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderAssigned).toHaveBeenCalledTimes(2) }) }) @@ -208,10 +208,10 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) - expect(events.user.created).toBeCalledTimes(1) - expect(events.user.updated).not.toBeCalled() - expect(events.user.permissionBuilderAssigned).not.toBeCalled() - expect(events.user.permissionAdminAssigned).not.toBeCalled() + expect(events.user.created).toHaveBeenCalledTimes(1) + expect(events.user.updated).not.toHaveBeenCalled() + expect(events.user.permissionBuilderAssigned).not.toHaveBeenCalled() + expect(events.user.permissionAdminAssigned).not.toHaveBeenCalled() }) it("should be able to create an admin user", async () => { @@ -219,10 +219,10 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) - expect(events.user.created).toBeCalledTimes(1) - expect(events.user.updated).not.toBeCalled() - expect(events.user.permissionBuilderAssigned).toBeCalledTimes(1) - expect(events.user.permissionAdminAssigned).toBeCalledTimes(1) + expect(events.user.created).toHaveBeenCalledTimes(1) + expect(events.user.updated).not.toHaveBeenCalled() + expect(events.user.permissionBuilderAssigned).toHaveBeenCalledTimes(1) + expect(events.user.permissionAdminAssigned).toHaveBeenCalledTimes(1) }) it("should be able to create a builder user", async () => { @@ -230,10 +230,10 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) - expect(events.user.created).toBeCalledTimes(1) - expect(events.user.updated).not.toBeCalled() - expect(events.user.permissionBuilderAssigned).toBeCalledTimes(1) - expect(events.user.permissionAdminAssigned).not.toBeCalled() + expect(events.user.created).toHaveBeenCalledTimes(1) + expect(events.user.updated).not.toHaveBeenCalled() + expect(events.user.permissionBuilderAssigned).toHaveBeenCalledTimes(1) + expect(events.user.permissionAdminAssigned).not.toHaveBeenCalled() }) it("should be able to assign app roles", async () => { @@ -246,11 +246,11 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) const savedUser = await config.getUser(user.email) - expect(events.user.created).toBeCalledTimes(1) - expect(events.user.updated).not.toBeCalled() - expect(events.role.assigned).toBeCalledTimes(2) - expect(events.role.assigned).toBeCalledWith(savedUser, "role1") - expect(events.role.assigned).toBeCalledWith(savedUser, "role2") + expect(events.user.created).toHaveBeenCalledTimes(1) + expect(events.user.updated).not.toHaveBeenCalled() + expect(events.role.assigned).toHaveBeenCalledTimes(2) + expect(events.role.assigned).toHaveBeenCalledWith(savedUser, "role1") + expect(events.role.assigned).toHaveBeenCalledWith(savedUser, "role2") }) it("should not be able to create user that exists in same tenant", async () => { @@ -264,7 +264,7 @@ describe("/api/global/users", () => { expect(response.body.message).toBe( `Email already in use: '${user.email}'` ) - expect(events.user.created).toBeCalledTimes(0) + expect(events.user.created).toHaveBeenCalledTimes(0) }) it("should not be able to create user that exists in other tenant", async () => { @@ -278,7 +278,7 @@ describe("/api/global/users", () => { expect(response.body.message).toBe( `Email already in use: '${user.email}'` ) - expect(events.user.created).toBeCalledTimes(0) + expect(events.user.created).toHaveBeenCalledTimes(0) }) }) @@ -292,7 +292,7 @@ describe("/api/global/users", () => { expect(response.body.message).toBe( `Email already in use: '${user.email}'` ) - expect(events.user.created).toBeCalledTimes(0) + expect(events.user.created).toHaveBeenCalledTimes(0) }) it("should not be able to create a user with the same email and different casing", async () => { @@ -302,7 +302,7 @@ describe("/api/global/users", () => { user.email = user.email.toUpperCase() await config.api.users.saveUser(user, 400) - expect(events.user.created).toBeCalledTimes(1) + expect(events.user.created).toHaveBeenCalledTimes(1) }) it("should not be able to bulk create a user with the same email and different casing", async () => { @@ -312,7 +312,7 @@ describe("/api/global/users", () => { user.email = user.email.toUpperCase() await config.api.users.bulkCreateUsers([user]) - expect(events.user.created).toBeCalledTimes(1) + expect(events.user.created).toHaveBeenCalledTimes(1) }) it("should not allow a non-admin user to create a new user", async () => { @@ -335,11 +335,11 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) - expect(events.user.created).not.toBeCalled() - expect(events.user.updated).toBeCalledTimes(1) - expect(events.user.permissionBuilderAssigned).not.toBeCalled() - expect(events.user.permissionAdminAssigned).not.toBeCalled() - expect(events.user.passwordForceReset).not.toBeCalled() + expect(events.user.created).not.toHaveBeenCalled() + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderAssigned).not.toHaveBeenCalled() + expect(events.user.permissionAdminAssigned).not.toHaveBeenCalled() + expect(events.user.passwordForceReset).not.toHaveBeenCalled() }) it("should not allow a user to update their own admin/builder status", async () => { @@ -367,11 +367,11 @@ describe("/api/global/users", () => { user.password = "tempPassword" await config.api.users.saveUser(user) - expect(events.user.created).not.toBeCalled() - expect(events.user.updated).toBeCalledTimes(1) - expect(events.user.permissionBuilderAssigned).not.toBeCalled() - expect(events.user.permissionAdminAssigned).not.toBeCalled() - expect(events.user.passwordForceReset).toBeCalledTimes(1) + expect(events.user.created).not.toHaveBeenCalled() + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderAssigned).not.toHaveBeenCalled() + expect(events.user.permissionAdminAssigned).not.toHaveBeenCalled() + expect(events.user.passwordForceReset).toHaveBeenCalledTimes(1) }) it("should be able to update a basic user to an admin user", async () => { @@ -380,10 +380,10 @@ describe("/api/global/users", () => { await config.api.users.saveUser(structures.users.adminUser(user)) - expect(events.user.created).not.toBeCalled() - expect(events.user.updated).toBeCalledTimes(1) - expect(events.user.permissionBuilderAssigned).toBeCalledTimes(1) - expect(events.user.permissionAdminAssigned).toBeCalledTimes(1) + expect(events.user.created).not.toHaveBeenCalled() + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderAssigned).toHaveBeenCalledTimes(1) + expect(events.user.permissionAdminAssigned).toHaveBeenCalledTimes(1) }) it("should be able to update a basic user to a builder user", async () => { @@ -392,10 +392,10 @@ describe("/api/global/users", () => { await config.api.users.saveUser(structures.users.builderUser(user)) - expect(events.user.created).not.toBeCalled() - expect(events.user.updated).toBeCalledTimes(1) - expect(events.user.permissionBuilderAssigned).toBeCalledTimes(1) - expect(events.user.permissionAdminAssigned).not.toBeCalled() + expect(events.user.created).not.toHaveBeenCalled() + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderAssigned).toHaveBeenCalledTimes(1) + expect(events.user.permissionAdminAssigned).not.toHaveBeenCalled() }) it("should be able to update an admin user to a basic user", async () => { @@ -406,10 +406,10 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) - expect(events.user.created).not.toBeCalled() - expect(events.user.updated).toBeCalledTimes(1) - expect(events.user.permissionAdminRemoved).toBeCalledTimes(1) - expect(events.user.permissionBuilderRemoved).toBeCalledTimes(1) + expect(events.user.created).not.toHaveBeenCalled() + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.user.permissionAdminRemoved).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderRemoved).toHaveBeenCalledTimes(1) }) it("should be able to update an builder user to a basic user", async () => { @@ -419,10 +419,10 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) - expect(events.user.created).not.toBeCalled() - expect(events.user.updated).toBeCalledTimes(1) - expect(events.user.permissionBuilderRemoved).toBeCalledTimes(1) - expect(events.user.permissionAdminRemoved).not.toBeCalled() + expect(events.user.created).not.toHaveBeenCalled() + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderRemoved).toHaveBeenCalledTimes(1) + expect(events.user.permissionAdminRemoved).not.toHaveBeenCalled() }) it("should be able to assign app roles", async () => { @@ -436,11 +436,11 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) const savedUser = await config.getUser(user.email) - expect(events.user.created).not.toBeCalled() - expect(events.user.updated).toBeCalledTimes(1) - expect(events.role.assigned).toBeCalledTimes(2) - expect(events.role.assigned).toBeCalledWith(savedUser, "role1") - expect(events.role.assigned).toBeCalledWith(savedUser, "role2") + expect(events.user.created).not.toHaveBeenCalled() + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.role.assigned).toHaveBeenCalledTimes(2) + expect(events.role.assigned).toHaveBeenCalledWith(savedUser, "role1") + expect(events.role.assigned).toHaveBeenCalledWith(savedUser, "role2") }) it("should be able to unassign app roles", async () => { @@ -456,11 +456,11 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) const savedUser = await config.getUser(user.email) - expect(events.user.created).not.toBeCalled() - expect(events.user.updated).toBeCalledTimes(1) - expect(events.role.unassigned).toBeCalledTimes(2) - expect(events.role.unassigned).toBeCalledWith(savedUser, "role1") - expect(events.role.unassigned).toBeCalledWith(savedUser, "role2") + expect(events.user.created).not.toHaveBeenCalled() + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.role.unassigned).toHaveBeenCalledTimes(2) + expect(events.role.unassigned).toHaveBeenCalledWith(savedUser, "role1") + expect(events.role.unassigned).toHaveBeenCalledWith(savedUser, "role2") }) it("should be able to update existing app roles", async () => { @@ -479,12 +479,12 @@ describe("/api/global/users", () => { await config.api.users.saveUser(user) const savedUser = await config.getUser(user.email) - expect(events.user.created).not.toBeCalled() - expect(events.user.updated).toBeCalledTimes(1) - expect(events.role.unassigned).toBeCalledTimes(1) - expect(events.role.unassigned).toBeCalledWith(savedUser, "role2") - expect(events.role.assigned).toBeCalledTimes(1) - expect(events.role.assigned).toBeCalledWith(savedUser, "role2-edit") + expect(events.user.created).not.toHaveBeenCalled() + expect(events.user.updated).toHaveBeenCalledTimes(1) + expect(events.role.unassigned).toHaveBeenCalledTimes(1) + expect(events.role.unassigned).toHaveBeenCalledWith(savedUser, "role2") + expect(events.role.assigned).toHaveBeenCalledTimes(1) + expect(events.role.assigned).toHaveBeenCalledWith(savedUser, "role2-edit") }) it("should not be able to update email address", async () => { @@ -534,7 +534,7 @@ describe("/api/global/users", () => { const response = await config.api.users.bulkDeleteUsers([user._id!], 400) expect(response.message).toBe("Unable to delete self.") - expect(events.user.deleted).not.toBeCalled() + expect(events.user.deleted).not.toHaveBeenCalled() }) it("should not be able to bulk delete account owner", async () => { @@ -551,7 +551,7 @@ describe("/api/global/users", () => { "Account holder cannot be deleted" ) expect(response.deleted?.unsuccessful[0]._id).toBe(user._id) - expect(events.user.deleted).not.toBeCalled() + expect(events.user.deleted).not.toHaveBeenCalled() }) it("should be able to bulk delete users", async () => { @@ -574,9 +574,9 @@ describe("/api/global/users", () => { expect(response.deleted?.successful.length).toBe(3) expect(response.deleted?.unsuccessful.length).toBe(0) - expect(events.user.deleted).toBeCalledTimes(3) - expect(events.user.permissionAdminRemoved).toBeCalledTimes(1) - expect(events.user.permissionBuilderRemoved).toBeCalledTimes(2) + expect(events.user.deleted).toHaveBeenCalledTimes(3) + expect(events.user.permissionAdminRemoved).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderRemoved).toHaveBeenCalledTimes(2) }) }) @@ -669,9 +669,9 @@ describe("/api/global/users", () => { await config.api.users.deleteUser(user._id!) - expect(events.user.deleted).toBeCalledTimes(1) - expect(events.user.permissionBuilderRemoved).not.toBeCalled() - expect(events.user.permissionAdminRemoved).not.toBeCalled() + expect(events.user.deleted).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderRemoved).not.toHaveBeenCalled() + expect(events.user.permissionAdminRemoved).not.toHaveBeenCalled() }) it("should be able to destroy an admin user", async () => { @@ -680,9 +680,9 @@ describe("/api/global/users", () => { await config.api.users.deleteUser(user._id!) - expect(events.user.deleted).toBeCalledTimes(1) - expect(events.user.permissionBuilderRemoved).toBeCalledTimes(1) - expect(events.user.permissionAdminRemoved).toBeCalledTimes(1) + expect(events.user.deleted).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderRemoved).toHaveBeenCalledTimes(1) + expect(events.user.permissionAdminRemoved).toHaveBeenCalledTimes(1) }) it("should be able to destroy a builder user", async () => { @@ -691,9 +691,9 @@ describe("/api/global/users", () => { await config.api.users.deleteUser(user._id!) - expect(events.user.deleted).toBeCalledTimes(1) - expect(events.user.permissionBuilderRemoved).toBeCalledTimes(1) - expect(events.user.permissionAdminRemoved).not.toBeCalled() + expect(events.user.deleted).toHaveBeenCalledTimes(1) + expect(events.user.permissionBuilderRemoved).toHaveBeenCalledTimes(1) + expect(events.user.permissionAdminRemoved).not.toHaveBeenCalled() }) it("should not be able to destroy account owner", async () => { diff --git a/packages/worker/src/api/routes/global/tests/workspaces.spec.ts b/packages/worker/src/api/routes/global/tests/workspaces.spec.ts deleted file mode 100644 index 1a30c6525c..0000000000 --- a/packages/worker/src/api/routes/global/tests/workspaces.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { TestConfiguration } from "../../../../tests" - -// TODO - -describe("/api/global/workspaces", () => { - const config = new TestConfiguration() - - beforeAll(async () => { - await config.beforeAll() - }) - - afterAll(async () => { - await config.afterAll() - }) - - afterEach(() => { - jest.clearAllMocks() - }) - - describe("GET /api/global/workspaces", () => { - it("retrieves workspaces", () => {}) - }) - - describe("DELETE /api/global/workspaces/:id", () => {}) - - describe("GET /api/global/workspaces", () => {}) - - describe("GET /api/global/workspaces/:id", () => {}) -}) diff --git a/packages/worker/src/api/routes/system/tests/migrations.spec.ts b/packages/worker/src/api/routes/system/tests/migrations.spec.ts index 950f5c2153..4198d65ee9 100644 --- a/packages/worker/src/api/routes/system/tests/migrations.spec.ts +++ b/packages/worker/src/api/routes/system/tests/migrations.spec.ts @@ -31,13 +31,13 @@ describe("/api/system/migrations", () => { status: 403, }) expect(res.body).toEqual({ message: "Unauthorized", status: 403 }) - expect(migrateFn).toBeCalledTimes(0) + expect(migrateFn).toHaveBeenCalledTimes(0) }) it("runs migrations", async () => { const res = await config.api.migrations.runMigrations() expect(res.text).toBe("OK") - expect(migrateFn).toBeCalledTimes(1) + expect(migrateFn).toHaveBeenCalledTimes(1) }) }) diff --git a/packages/worker/src/api/routes/system/tests/status.spec.ts b/packages/worker/src/api/routes/system/tests/status.spec.ts index e2011dc79a..71e01a0e72 100644 --- a/packages/worker/src/api/routes/system/tests/status.spec.ts +++ b/packages/worker/src/api/routes/system/tests/status.spec.ts @@ -28,7 +28,7 @@ describe("/api/system/status", () => { passing: true, }, }) - expect(accounts.getStatus).toBeCalledTimes(0) + expect(accounts.getStatus).toHaveBeenCalledTimes(0) config.cloudHosted() }) @@ -45,7 +45,7 @@ describe("/api/system/status", () => { const res = await config.api.status.getStatus() - expect(accounts.getStatus).toBeCalledTimes(1) + expect(accounts.getStatus).toHaveBeenCalledTimes(1) expect(res.body).toEqual(value) }) }) diff --git a/qa-core/src/account-api/tests/licensing/offline.spec.ts b/qa-core/src/account-api/tests/licensing/offline.spec.ts index 8374677bd6..e524048153 100644 --- a/qa-core/src/account-api/tests/licensing/offline.spec.ts +++ b/qa-core/src/account-api/tests/licensing/offline.spec.ts @@ -15,7 +15,7 @@ describe("offline", () => { // TODO: Currently requires a self host install + account portal // Ignored until we set this up - xit("creates, activates and deletes offline license", async () => { + it.skip("creates, activates and deletes offline license", async () => { // installation: Delete any token await config.internalApi.license.deleteOfflineLicenseToken() diff --git a/qa-core/src/internal-api/tests/dataSources/mongoDB.integration.spec.ts b/qa-core/src/internal-api/tests/dataSources/mongoDB.integration.spec.ts index ace9ef32c5..efa9eb2dd2 100644 --- a/qa-core/src/internal-api/tests/dataSources/mongoDB.integration.spec.ts +++ b/qa-core/src/internal-api/tests/dataSources/mongoDB.integration.spec.ts @@ -2,7 +2,7 @@ import TestConfiguration from "../../config/TestConfiguration" import * as fixtures from "../../fixtures" import { Query } from "@budibase/types" -xdescribe("Internal API - Data Sources: MongoDB", () => { +describe.skip("Internal API - Data Sources: MongoDB", () => { const config = new TestConfiguration() beforeAll(async () => { diff --git a/yarn.lock b/yarn.lock index b2e0b32d43..9d68117413 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5447,6 +5447,11 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== +"@types/json-schema@^7.0.9": + version "7.0.15" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" + integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== + "@types/json5@^0.0.29": version "0.0.29" resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" @@ -5961,6 +5966,11 @@ resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.7.tgz#b9eb89d7dfa70d5d1ce525bc1411a35347f533a3" integrity sha512-4g1jrL98mdOIwSOUh6LTlB0Cs9I0dQPwINUhBg7C6pN4HLr8GS8xsksJxilW6S6dQHVi2K/o+lQuQcg7LroCnw== +"@types/semver@^7.3.12": + version "7.5.8" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e" + integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ== + "@types/serve-static@*": version "1.15.1" resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.15.1.tgz#86b1753f0be4f9a1bee68d459fcda5be4ea52b5d" @@ -6133,6 +6143,14 @@ "@typescript-eslint/visitor-keys" "6.9.0" debug "^4.3.4" +"@typescript-eslint/scope-manager@5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz#d9457ccc6a0b8d6b37d0eb252a23022478c5460c" + integrity sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w== + dependencies: + "@typescript-eslint/types" "5.62.0" + "@typescript-eslint/visitor-keys" "5.62.0" + "@typescript-eslint/scope-manager@6.9.0": version "6.9.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.9.0.tgz#2626e9a7fe0e004c3e25f3b986c75f584431134e" @@ -6151,11 +6169,29 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.53.0.tgz#f79eca62b97e518ee124086a21a24f3be267026f" integrity sha512-5kcDL9ZUIP756K6+QOAfPkigJmCPHcLN7Zjdz76lQWWDdzfOhZDTj1irs6gPBKiXx5/6O3L0+AvupAut3z7D2A== +"@typescript-eslint/types@5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f" + integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ== + "@typescript-eslint/types@6.9.0": version "6.9.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.9.0.tgz#86a0cbe7ac46c0761429f928467ff3d92f841098" integrity sha512-+KB0lbkpxBkBSiVCuQvduqMJy+I1FyDbdwSpM3IoBS7APl4Bu15lStPjgBIdykdRqQNYqYNMa8Kuidax6phaEw== +"@typescript-eslint/typescript-estree@5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz#7d17794b77fabcac615d6a48fb143330d962eb9b" + integrity sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA== + dependencies: + "@typescript-eslint/types" "5.62.0" + "@typescript-eslint/visitor-keys" "5.62.0" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + semver "^7.3.7" + tsutils "^3.21.0" + "@typescript-eslint/typescript-estree@6.9.0": version "6.9.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.9.0.tgz#d0601b245be873d8fe49f3737f93f8662c8693d4" @@ -6195,6 +6231,20 @@ semver "^7.3.7" tsutils "^3.21.0" +"@typescript-eslint/utils@^5.10.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.62.0.tgz#141e809c71636e4a75daa39faed2fb5f4b10df86" + integrity sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ== + dependencies: + "@eslint-community/eslint-utils" "^4.2.0" + "@types/json-schema" "^7.0.9" + "@types/semver" "^7.3.12" + "@typescript-eslint/scope-manager" "5.62.0" + "@typescript-eslint/types" "5.62.0" + "@typescript-eslint/typescript-estree" "5.62.0" + eslint-scope "^5.1.1" + semver "^7.3.7" + "@typescript-eslint/visitor-keys@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.33.0.tgz#2a22f77a41604289b7a186586e9ec48ca92ef1dd" @@ -6211,6 +6261,14 @@ "@typescript-eslint/types" "5.53.0" eslint-visitor-keys "^3.3.0" +"@typescript-eslint/visitor-keys@5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz#2174011917ce582875954ffe2f6912d5931e353e" + integrity sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw== + dependencies: + "@typescript-eslint/types" "5.62.0" + eslint-visitor-keys "^3.3.0" + "@typescript-eslint/visitor-keys@6.9.0": version "6.9.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.9.0.tgz#cc69421c10c4ac997ed34f453027245988164e80" @@ -10397,6 +10455,13 @@ eslint-plugin-import@^2.29.0: semver "^6.3.1" tsconfig-paths "^3.14.2" +eslint-plugin-jest@^27.9.0: + version "27.9.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-27.9.0.tgz#7c98a33605e1d8b8442ace092b60e9919730000b" + integrity sha512-QIT7FH7fNmd9n4se7FFKHbsLKGQiw885Ds6Y/sxKgCZ6natwCsXdgPOADnYVxN2QrRweF0FZWbJ6S7Rsn7llug== + dependencies: + "@typescript-eslint/utils" "^5.10.0" + eslint-plugin-local-rules@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/eslint-plugin-local-rules/-/eslint-plugin-local-rules-2.0.0.tgz#cda95d7616cc0e2609d76c347c187ca2be1e252e" @@ -10420,7 +10485,7 @@ eslint-plugin-svelte@^2.34.0: semver "^7.5.3" svelte-eslint-parser ">=0.33.0 <1.0.0" -eslint-scope@5.1.1: +eslint-scope@5.1.1, eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==