Remove defaultUserValues from test config
This commit is contained in:
parent
033ab71109
commit
e988890a7e
|
@ -76,14 +76,6 @@ mocks.licenses.useUnlimited()
|
|||
|
||||
dbInit()
|
||||
|
||||
type DefaultUserValues = {
|
||||
globalUserId: string
|
||||
email: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
csrfToken: string
|
||||
}
|
||||
|
||||
export interface TableToBuild extends Omit<Table, "sourceId" | "sourceType"> {
|
||||
sourceId?: string
|
||||
sourceType?: TableSourceType
|
||||
|
@ -105,8 +97,8 @@ export default class TestConfiguration {
|
|||
automation: any
|
||||
datasource?: Datasource
|
||||
tenantId?: string
|
||||
defaultUserValues: DefaultUserValues
|
||||
api: API
|
||||
csrfToken?: string
|
||||
|
||||
constructor(openServer = true) {
|
||||
if (openServer) {
|
||||
|
@ -121,21 +113,10 @@ export default class TestConfiguration {
|
|||
}
|
||||
this.appId = null
|
||||
this.allApps = []
|
||||
this.defaultUserValues = this.populateDefaultUserValues()
|
||||
|
||||
this.api = new API(this)
|
||||
}
|
||||
|
||||
populateDefaultUserValues(): DefaultUserValues {
|
||||
return {
|
||||
globalUserId: `us_${newid()}`,
|
||||
email: generator.email(),
|
||||
firstName: generator.first(),
|
||||
lastName: generator.last(),
|
||||
csrfToken: generator.hash(),
|
||||
}
|
||||
}
|
||||
|
||||
getRequest() {
|
||||
return this.request
|
||||
}
|
||||
|
@ -160,15 +141,6 @@ export default class TestConfiguration {
|
|||
return this.prodAppId
|
||||
}
|
||||
|
||||
getUserDetails() {
|
||||
return {
|
||||
globalId: this.defaultUserValues.globalUserId,
|
||||
email: this.defaultUserValues.email,
|
||||
firstName: this.defaultUserValues.firstName,
|
||||
lastName: this.defaultUserValues.lastName,
|
||||
}
|
||||
}
|
||||
|
||||
async doInContext<T>(
|
||||
appId: string | null,
|
||||
task: () => Promise<T>
|
||||
|
@ -300,15 +272,27 @@ export default class TestConfiguration {
|
|||
}
|
||||
|
||||
// USER / AUTH
|
||||
async globalUser({
|
||||
id = this.defaultUserValues.globalUserId,
|
||||
firstName = this.defaultUserValues.firstName,
|
||||
lastName = this.defaultUserValues.lastName,
|
||||
builder = true,
|
||||
admin = false,
|
||||
email = this.defaultUserValues.email,
|
||||
roles,
|
||||
}: any = {}): Promise<User> {
|
||||
async globalUser(
|
||||
config: {
|
||||
id?: string
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
builder?: boolean
|
||||
admin?: boolean
|
||||
email?: string
|
||||
roles?: any
|
||||
} = {}
|
||||
): Promise<User> {
|
||||
const {
|
||||
id = `us_${newid()}`,
|
||||
firstName = generator.first(),
|
||||
lastName = generator.last(),
|
||||
builder = true,
|
||||
admin = false,
|
||||
email,
|
||||
roles,
|
||||
} = config
|
||||
|
||||
const db = tenancy.getTenantDB(this.getTenantId())
|
||||
let existing
|
||||
try {
|
||||
|
@ -327,7 +311,7 @@ export default class TestConfiguration {
|
|||
await sessions.createASession(id, {
|
||||
sessionId: "sessionid",
|
||||
tenantId: this.getTenantId(),
|
||||
csrfToken: this.defaultUserValues.csrfToken,
|
||||
csrfToken: this.csrfToken,
|
||||
})
|
||||
if (builder) {
|
||||
user.builder = { global: true }
|
||||
|
@ -358,9 +342,9 @@ export default class TestConfiguration {
|
|||
} = {}
|
||||
): Promise<User> {
|
||||
let { id, firstName, lastName, email, builder, admin, roles } = user
|
||||
firstName = firstName || this.defaultUserValues.firstName
|
||||
lastName = lastName || this.defaultUserValues.lastName
|
||||
email = email || this.defaultUserValues.email
|
||||
;(firstName = firstName || generator.first()),
|
||||
(lastName = lastName || generator.last()),
|
||||
(email = email || generator.email())
|
||||
roles = roles || {}
|
||||
if (builder == null) {
|
||||
builder = true
|
||||
|
@ -448,7 +432,7 @@ export default class TestConfiguration {
|
|||
defaultHeaders(extras = {}, prodApp = false) {
|
||||
const tenantId = this.getTenantId()
|
||||
const authObj: AuthToken = {
|
||||
userId: this.defaultUserValues.globalUserId,
|
||||
userId: this.user.globalUserId,
|
||||
sessionId: "sessionid",
|
||||
tenantId,
|
||||
}
|
||||
|
@ -457,7 +441,7 @@ export default class TestConfiguration {
|
|||
const headers: any = {
|
||||
Accept: "application/json",
|
||||
Cookie: [`${constants.Cookie.Auth}=${authToken}`],
|
||||
[constants.Header.CSRF_TOKEN]: this.defaultUserValues.csrfToken,
|
||||
[constants.Header.CSRF_TOKEN]: this.csrfToken,
|
||||
Host: this.tenantHost(),
|
||||
...extras,
|
||||
}
|
||||
|
@ -487,7 +471,7 @@ export default class TestConfiguration {
|
|||
|
||||
async basicRoleHeaders() {
|
||||
return await this.roleHeaders({
|
||||
email: this.defaultUserValues.email,
|
||||
email: generator.email(),
|
||||
builder: false,
|
||||
prodApp: true,
|
||||
roleId: roles.BUILTIN_ROLE_IDS.BASIC,
|
||||
|
@ -495,7 +479,7 @@ export default class TestConfiguration {
|
|||
}
|
||||
|
||||
async roleHeaders({
|
||||
email = this.defaultUserValues.email,
|
||||
email = generator.email(),
|
||||
roleId = roles.BUILTIN_ROLE_IDS.ADMIN,
|
||||
builder = false,
|
||||
prodApp = true,
|
||||
|
@ -519,11 +503,12 @@ export default class TestConfiguration {
|
|||
}
|
||||
|
||||
async newTenant(appName = newid()): Promise<App> {
|
||||
this.defaultUserValues = this.populateDefaultUserValues()
|
||||
this.tenantId = structures.tenant.id()
|
||||
this.user = await this.globalUser()
|
||||
this.globalUserId = this.user._id
|
||||
this.userMetadataId = generateUserMetadataID(this.globalUserId)
|
||||
|
||||
this.csrfToken = generator.hash()
|
||||
return this.createApp(appName)
|
||||
}
|
||||
|
||||
|
@ -533,7 +518,7 @@ export default class TestConfiguration {
|
|||
|
||||
// API
|
||||
|
||||
async generateApiKey(userId = this.defaultUserValues.globalUserId) {
|
||||
async generateApiKey(userId = this.user.globalUserId) {
|
||||
const db = tenancy.getTenantDB(this.getTenantId())
|
||||
const id = dbCore.generateDevInfoID(userId)
|
||||
let devInfo: any
|
||||
|
|
Loading…
Reference in New Issue