Adding a dep:clean function, cleaning up lock files and fixing backend-core test which did not utilise tenancy (no global db).
This commit is contained in:
parent
345bbf603c
commit
7083470baa
|
@ -72,6 +72,7 @@
|
|||
"mode:cloud": "yarn env:selfhost:disable && yarn env:multi:enable && yarn env:account:disable",
|
||||
"mode:account": "yarn mode:cloud && yarn env:account:enable",
|
||||
"security:audit": "node scripts/audit.js",
|
||||
"postinstall": "husky install"
|
||||
"postinstall": "husky install",
|
||||
"dep:clean": "yarn clean && yarn bootstrap"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,13 @@
|
|||
|
||||
require("../../../tests/utilities/dbConfig")
|
||||
|
||||
const { dangerousGetDB } = require("../../../db")
|
||||
const { authenticateThirdParty } = require("../third-party-common")
|
||||
const { data } = require("./utilities/mock-data")
|
||||
const { DEFAULT_TENANT_ID } = require("../../../constants")
|
||||
|
||||
const {
|
||||
StaticDatabases,
|
||||
generateGlobalUserID
|
||||
} = require("../../../db/utils")
|
||||
const { generateGlobalUserID } = require("../../../db/utils")
|
||||
const { newid } = require("../../../hashing")
|
||||
|
||||
let db
|
||||
const { doWithGlobalDB, doInTenant } = require("../../../tenancy")
|
||||
|
||||
const done = jest.fn()
|
||||
|
||||
|
@ -21,7 +17,15 @@ const getErrorMessage = () => {
|
|||
}
|
||||
|
||||
const saveUser = async (user) => {
|
||||
return doWithGlobalDB(DEFAULT_TENANT_ID, async db => {
|
||||
return await db.put(user)
|
||||
})
|
||||
}
|
||||
|
||||
function authenticate(user, requireLocal, saveFn) {
|
||||
return doInTenant(DEFAULT_TENANT_ID, () => {
|
||||
return authenticateThirdParty(user, requireLocal, done, saveFn)
|
||||
})
|
||||
}
|
||||
|
||||
describe("third party common", () => {
|
||||
|
@ -29,35 +33,36 @@ describe("third party common", () => {
|
|||
let thirdPartyUser
|
||||
|
||||
beforeEach(() => {
|
||||
db = dangerousGetDB(StaticDatabases.GLOBAL.name)
|
||||
thirdPartyUser = data.buildThirdPartyUser()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
return doWithGlobalDB(DEFAULT_TENANT_ID, async db => {
|
||||
jest.clearAllMocks()
|
||||
await db.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
describe("validation", () => {
|
||||
const testValidation = async (message) => {
|
||||
await authenticateThirdParty(thirdPartyUser, false, done, saveUser)
|
||||
await authenticate(thirdPartyUser, false, saveUser)
|
||||
expect(done.mock.calls.length).toBe(1)
|
||||
expect(getErrorMessage()).toContain(message)
|
||||
}
|
||||
|
||||
it("provider fails", async () => {
|
||||
delete thirdPartyUser.provider
|
||||
testValidation("third party user provider required")
|
||||
await testValidation("third party user provider required")
|
||||
})
|
||||
|
||||
it("user id fails", async () => {
|
||||
delete thirdPartyUser.userId
|
||||
testValidation("third party user id required")
|
||||
await testValidation("third party user id required")
|
||||
})
|
||||
|
||||
it("email fails", async () => {
|
||||
delete thirdPartyUser.email
|
||||
testValidation("third party user email required")
|
||||
await testValidation("third party user email required")
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -81,7 +86,7 @@ describe("third party common", () => {
|
|||
describe("when the user doesn't exist", () => {
|
||||
describe("when a local account is required", () => {
|
||||
it("returns an error message", async () => {
|
||||
await authenticateThirdParty(thirdPartyUser, true, done, saveUser)
|
||||
await authenticate(thirdPartyUser, true, saveUser)
|
||||
expect(done.mock.calls.length).toBe(1)
|
||||
expect(getErrorMessage()).toContain("Email does not yet exist. You must set up your local budibase account first.")
|
||||
})
|
||||
|
@ -89,7 +94,7 @@ describe("third party common", () => {
|
|||
|
||||
describe("when a local account isn't required", () => {
|
||||
it("creates and authenticates the user", async () => {
|
||||
await authenticateThirdParty(thirdPartyUser, false, done, saveUser)
|
||||
await authenticate(thirdPartyUser, false, saveUser)
|
||||
const user = expectUserIsAuthenticated()
|
||||
expectUserIsSynced(user, thirdPartyUser)
|
||||
expect(user.roles).toStrictEqual({})
|
||||
|
@ -103,12 +108,15 @@ describe("third party common", () => {
|
|||
let email
|
||||
|
||||
const createUser = async () => {
|
||||
return doWithGlobalDB(DEFAULT_TENANT_ID, async db => {
|
||||
dbUser = {
|
||||
_id: id,
|
||||
email: email,
|
||||
}
|
||||
const response = await db.put(dbUser)
|
||||
dbUser._rev = response.rev
|
||||
return dbUser
|
||||
})
|
||||
}
|
||||
|
||||
const expectUserIsUpdated = (user) => {
|
||||
|
@ -126,7 +134,7 @@ describe("third party common", () => {
|
|||
})
|
||||
|
||||
it("syncs and authenticates the user", async () => {
|
||||
await authenticateThirdParty(thirdPartyUser, true, done, saveUser)
|
||||
await authenticate(thirdPartyUser, true, saveUser)
|
||||
|
||||
const user = expectUserIsAuthenticated()
|
||||
expectUserIsSynced(user, thirdPartyUser)
|
||||
|
@ -142,7 +150,7 @@ describe("third party common", () => {
|
|||
})
|
||||
|
||||
it("syncs and authenticates the user", async () => {
|
||||
await authenticateThirdParty(thirdPartyUser, true, done, saveUser)
|
||||
await authenticate(thirdPartyUser, true, saveUser)
|
||||
|
||||
const user = expectUserIsAuthenticated()
|
||||
expectUserIsSynced(user, thirdPartyUser)
|
||||
|
@ -160,7 +168,7 @@ describe("third party common", () => {
|
|||
})
|
||||
|
||||
it("syncs and authenticates the user", async () => {
|
||||
await authenticateThirdParty(thirdPartyUser, true, done, saveUser)
|
||||
await authenticate(thirdPartyUser, true, saveUser)
|
||||
|
||||
const user = expectUserIsAuthenticated()
|
||||
expectUserIsSynced(user, thirdPartyUser)
|
||||
|
|
|
@ -4063,7 +4063,7 @@ pouchdb-utils@7.2.2:
|
|||
pouchdb-md5 "7.2.2"
|
||||
uuid "8.1.0"
|
||||
|
||||
pouchdb@^7.3.0:
|
||||
pouchdb@7.3.0:
|
||||
version "7.3.0"
|
||||
resolved "https://registry.yarnpkg.com/pouchdb/-/pouchdb-7.3.0.tgz#440fbef12dfd8f9002320802528665e883a3b7f8"
|
||||
integrity sha512-OwsIQGXsfx3TrU1pLruj6PGSwFH+h5k4hGNxFkZ76Um7/ZI8F5TzUHFrpldVVIhfXYi2vP31q0q7ot1FSLFYOw==
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue