Updating some test cases to work with new system.

This commit is contained in:
mike12345567 2021-04-09 17:33:21 +01:00
parent e275553f60
commit 4f71e11c94
16 changed files with 34 additions and 23 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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

View File

@ -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)
}

View File

@ -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) {

View File

@ -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,
}

View File

@ -75,7 +75,7 @@ module.exports.run = async function({ inputs, appId, apiKey, emitter }) {
request: {
body: inputs.row,
},
user: { appId },
appId,
eventEmitter: emitter,
}

View File

@ -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,
}

View File

@ -65,7 +65,7 @@ module.exports.run = async function({ inputs, appId, apiKey, emitter }) {
rowId: inputs.id,
revId: inputs.revision,
},
user: { appId },
appId,
eventEmitter: emitter,
}

View File

@ -78,7 +78,7 @@ module.exports.run = async function({ inputs, appId, emitter }) {
request: {
body: inputs.row,
},
user: { appId },
appId,
eventEmitter: emitter,
}

View File

@ -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")

View File

@ -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")

View File

@ -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 () => {

View File

@ -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)
}
/**

View File

@ -20,9 +20,7 @@ class TestConfiguration {
this.ctx = {
throw: this.throw,
next: this.next,
user: {
appId: "test"
},
appId: "test",
request: {
body: {}
},

View File

@ -26,7 +26,9 @@ function prepRequest(ctx, request) {
? JSON.stringify(request.body)
: request.body
}
if (ctx.headers) {
request.headers.cookie = ctx.headers.cookie
}
return request
}