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