Allow pro to be mocked in worker

This commit is contained in:
Rory Powell 2023-07-07 16:55:11 +01:00
parent 6c3d01375b
commit 20c87b44b1
3 changed files with 35 additions and 6 deletions

View File

@ -0,0 +1,26 @@
const actual = jest.requireActual("@budibase/pro")
const pro = {
...actual,
licensing: {
keys: {
activateLicenseKey: jest.fn(),
getLicenseKey: jest.fn(),
deleteLicenseKey: jest.fn(),
},
offline: {
activateOfflineLicense: jest.fn(),
getOfflineLicenseToken: jest.fn(),
deleteOfflineLicenseToken: jest.fn(),
},
cache: {
...actual.licensing.cache,
refresh: jest.fn(),
}
},
quotas: {
...actual.quotas,
getQuotaUsage: jest.fn()
},
}
export = pro

View File

@ -1,8 +1,7 @@
import mocks from "./mocks" import mocks from "./mocks"
// init the licensing mock // init the licensing mock
import * as pro from "@budibase/pro" mocks.licenses.init(mocks.pro)
mocks.licenses.init(pro)
// use unlimited license by default // use unlimited license by default
mocks.licenses.useUnlimited() mocks.licenses.useUnlimited()
@ -238,21 +237,21 @@ class TestConfiguration {
const db = context.getGlobalDB() const db = context.getGlobalDB()
const id = dbCore.generateDevInfoID(this.user._id) const id = dbCore.generateDevInfoID(this.user!._id)
// TODO: dry // TODO: dry
this.apiKey = encryption.encrypt( this.apiKey = encryption.encrypt(
`${this.tenantId}${dbCore.SEPARATOR}${utils.newid()}` `${this.tenantId}${dbCore.SEPARATOR}${utils.newid()}`
) )
const devInfo = { const devInfo = {
_id: id, _id: id,
userId: this.user._id, userId: this.user!._id,
apiKey: this.apiKey, apiKey: this.apiKey,
} }
await db.put(devInfo) await db.put(devInfo)
}) })
} }
async getUser(email: string): Promise<User> { async getUser(email: string): Promise<User | undefined> {
return context.doInTenant(this.getTenantId(), () => { return context.doInTenant(this.getTenantId(), () => {
return users.getGlobalUserByEmail(email) return users.getGlobalUserByEmail(email)
}) })
@ -264,7 +263,7 @@ class TestConfiguration {
} }
const response = await this._req(user, null, controllers.users.save) const response = await this._req(user, null, controllers.users.save)
const body = response as SaveUserResponse const body = response as SaveUserResponse
return this.getUser(body.email) return this.getUser(body.email) as Promise<User>
} }
// CONFIGS // CONFIGS

View File

@ -1,7 +1,11 @@
import * as email from "./email" import * as email from "./email"
import { mocks } from "@budibase/backend-core/tests" import { mocks } from "@budibase/backend-core/tests"
import * as _pro from "@budibase/pro"
const pro = jest.mocked(_pro, true)
export default { export default {
email, email,
pro,
...mocks, ...mocks,
} }