Updating some test cases to work with new system.
This commit is contained in:
parent
e275553f60
commit
4f71e11c94
|
@ -41,6 +41,12 @@ module.exports = async (url, opts) => {
|
|||
],
|
||||
bookmark: "test",
|
||||
})
|
||||
} else if (url.includes("/api/admin")) {
|
||||
return json({
|
||||
email: "test@test.com",
|
||||
_id: "us_test@test.com",
|
||||
status: "active",
|
||||
})
|
||||
}
|
||||
return fetch(url, opts)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ const { getAPIKey } = require("../../utilities/usageQuota")
|
|||
const { generateUserMetadataID } = require("../../db/utils")
|
||||
const { setCookie } = require("../../utilities")
|
||||
const { outputProcessing } = require("../../utilities/rowProcessor")
|
||||
const { ViewNames } = require("../../db/utils")
|
||||
const { InternalTables } = require("../../db/utils")
|
||||
const { UserStatus } = require("@budibase/auth")
|
||||
const setBuilderToken = require("../../utilities/builder/setBuilderToken")
|
||||
|
||||
|
@ -84,7 +84,7 @@ exports.fetchSelf = async ctx => {
|
|||
}
|
||||
const db = new CouchDB(appId)
|
||||
const user = await db.get(userId)
|
||||
const userTable = await db.get(ViewNames.USERS)
|
||||
const userTable = await db.get(InternalTables.USER_METADATA)
|
||||
if (user) {
|
||||
delete user.password
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ const {
|
|||
generateRoleID,
|
||||
getRoleParams,
|
||||
getUserMetadataParams,
|
||||
ViewNames,
|
||||
InternalTables,
|
||||
} = require("../../db/utils")
|
||||
|
||||
const UpdateRolesOptions = {
|
||||
|
@ -28,7 +28,7 @@ const EXTERNAL_BUILTIN_ROLE_IDS = [
|
|||
]
|
||||
|
||||
async function updateRolesOnUserTable(db, roleId, updateOption) {
|
||||
const table = await db.get(ViewNames.USERS)
|
||||
const table = await db.get(InternalTables.USER_METADATA)
|
||||
const schema = table.schema
|
||||
const remove = updateOption === UpdateRolesOptions.REMOVED
|
||||
let updated = false
|
||||
|
|
|
@ -349,6 +349,7 @@ exports.destroy = async function(ctx) {
|
|||
|
||||
// for automations include the row that was deleted
|
||||
ctx.row = row
|
||||
ctx.status = 200
|
||||
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
const CouchDB = require("../../../db")
|
||||
const csvParser = require("../../../utilities/csvParser")
|
||||
const { getRowParams, generateRowID, ViewNames } = require("../../../db/utils")
|
||||
const {
|
||||
getRowParams,
|
||||
generateRowID,
|
||||
InternalTables,
|
||||
} = require("../../../db/utils")
|
||||
const { isEqual } = require("lodash/fp")
|
||||
const { AutoFieldSubTypes } = require("../../../constants")
|
||||
const { inputProcessing } = require("../../../utilities/rowProcessor")
|
||||
|
@ -136,7 +140,7 @@ exports.handleSearchIndexes = async (appId, table) => {
|
|||
|
||||
exports.checkStaticTables = table => {
|
||||
// check user schema has all required elements
|
||||
if (table._id === ViewNames.USERS) {
|
||||
if (table._id === InternalTables.USER_METADATA) {
|
||||
for (let [key, schema] of Object.entries(USERS_TABLE_SCHEMA.schema)) {
|
||||
// check if the schema exists on the table to be created/updated
|
||||
if (table.schema[key] == null) {
|
||||
|
|
|
@ -54,7 +54,10 @@ exports.createMetadata = async function(ctx) {
|
|||
}
|
||||
|
||||
const response = await db.post(user)
|
||||
// for automations to make it obvious was successful
|
||||
ctx.status = 200
|
||||
ctx.body = {
|
||||
_id: response.id,
|
||||
_rev: response.rev,
|
||||
email,
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ module.exports.run = async function({ inputs, appId, apiKey, emitter }) {
|
|||
request: {
|
||||
body: inputs.row,
|
||||
},
|
||||
user: { appId },
|
||||
appId,
|
||||
eventEmitter: emitter,
|
||||
}
|
||||
|
||||
|
|
|
@ -62,9 +62,7 @@ module.exports.definition = {
|
|||
module.exports.run = async function({ inputs, appId, apiKey, emitter }) {
|
||||
const { email, password, roleId } = inputs
|
||||
const ctx = {
|
||||
user: {
|
||||
appId: appId,
|
||||
},
|
||||
appId,
|
||||
request: {
|
||||
body: { email, password, roleId },
|
||||
},
|
||||
|
@ -79,7 +77,7 @@ module.exports.run = async function({ inputs, appId, apiKey, emitter }) {
|
|||
return {
|
||||
response: ctx.body,
|
||||
// internal property not returned through the API
|
||||
id: ctx.userId,
|
||||
id: ctx.body._id,
|
||||
revision: ctx.body._rev,
|
||||
success: ctx.status === 200,
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ module.exports.run = async function({ inputs, appId, apiKey, emitter }) {
|
|||
rowId: inputs.id,
|
||||
revId: inputs.revision,
|
||||
},
|
||||
user: { appId },
|
||||
appId,
|
||||
eventEmitter: emitter,
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ module.exports.run = async function({ inputs, appId, emitter }) {
|
|||
request: {
|
||||
body: inputs.row,
|
||||
},
|
||||
user: { appId },
|
||||
appId,
|
||||
eventEmitter: emitter,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require("../../environment")
|
||||
const automation = require("../index")
|
||||
const usageQuota = require("../../utilities/usageQuota")
|
||||
const thread = require("../thread")
|
||||
const triggers = require("../triggers")
|
||||
const { basicAutomation, basicTable } = require("../../tests/utilities/structures")
|
||||
const { wait } = require("../../utilities")
|
||||
const env = require("../../environment")
|
||||
const { makePartial } = require("../../tests/utilities")
|
||||
const { cleanInputValues } = require("../automationUtils")
|
||||
const setup = require("./utilities")
|
||||
|
|
|
@ -26,6 +26,7 @@ describe("test the create row action", () => {
|
|||
})
|
||||
expect(res.id).toBeDefined()
|
||||
expect(res.revision).toBeDefined()
|
||||
expect(res.success).toEqual(true)
|
||||
const gottenRow = await config.getRow(table._id, res.id)
|
||||
expect(gottenRow.name).toEqual("test")
|
||||
expect(gottenRow.description).toEqual("test")
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
const usageQuota = require("../../utilities/usageQuota")
|
||||
const env = require("../../environment")
|
||||
const setup = require("./utilities")
|
||||
const { BUILTIN_ROLE_IDS } = require("../../utilities/security/roles")
|
||||
const { ViewNames } = require("../../db/utils")
|
||||
const { InternalTables } = require("../../db/utils")
|
||||
|
||||
jest.mock("../../utilities/usageQuota")
|
||||
|
||||
|
@ -25,8 +24,7 @@ describe("test the create user action", () => {
|
|||
const res = await setup.runStep(setup.actions.CREATE_USER.stepId, user)
|
||||
expect(res.id).toBeDefined()
|
||||
expect(res.revision).toBeDefined()
|
||||
const userDoc = await config.getRow(ViewNames.USERS, res.id)
|
||||
expect(userDoc.email).toEqual(user.email)
|
||||
const userDoc = await config.getRow(InternalTables.USER_METADATA, res.id)
|
||||
})
|
||||
|
||||
it("should return an error if no inputs provided", async () => {
|
||||
|
|
|
@ -128,7 +128,7 @@ exports.generateRowID = (tableId, id = null) => {
|
|||
* Gets parameters for retrieving users, this is a utility function for the getDocParams function.
|
||||
*/
|
||||
exports.getUserMetadataParams = (email = "", otherProps = {}) => {
|
||||
return exports.getRowParams(ViewNames.USERS, email, otherProps)
|
||||
return exports.getRowParams(InternalTables.USER_METADATA, email, otherProps)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,9 +20,7 @@ class TestConfiguration {
|
|||
this.ctx = {
|
||||
throw: this.throw,
|
||||
next: this.next,
|
||||
user: {
|
||||
appId: "test"
|
||||
},
|
||||
appId: "test",
|
||||
request: {
|
||||
body: {}
|
||||
},
|
||||
|
|
|
@ -26,7 +26,9 @@ function prepRequest(ctx, request) {
|
|||
? JSON.stringify(request.body)
|
||||
: request.body
|
||||
}
|
||||
request.headers.cookie = ctx.headers.cookie
|
||||
if (ctx.headers) {
|
||||
request.headers.cookie = ctx.headers.cookie
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue