Fix Login problems
This commit is contained in:
parent
b913e4c938
commit
ca489b531f
|
@ -49,12 +49,17 @@ class InternalAPIClient {
|
|||
// @ts-ignore
|
||||
const response = await fetch(`https://${process.env.TENANT_ID}.${this.host}${url}`, requestOptions)
|
||||
|
||||
if (response.status == 404 || response.status == 500) {
|
||||
if (
|
||||
response.status == 404 ||
|
||||
response.status == 500 ||
|
||||
response.status == 403
|
||||
) {
|
||||
console.error("Error in apiCall")
|
||||
console.error("Response:")
|
||||
console.error(response)
|
||||
const json = await response.json()
|
||||
console.error("Response body:")
|
||||
console.error(response.body)
|
||||
console.error(json)
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
|
|
@ -59,8 +59,16 @@ class PublicAPIClient {
|
|||
// @ts-ignore
|
||||
const response = await fetch(`https://${process.env.TENANT_ID}.${this.host}${url}`, requestOptions)
|
||||
|
||||
if (response.status !== 200) {
|
||||
if (
|
||||
response.status == 404 ||
|
||||
response.status == 500 ||
|
||||
response.status == 403
|
||||
) {
|
||||
console.error("Error in apiCall")
|
||||
console.error("Response:")
|
||||
console.error(response)
|
||||
console.error("Response body:")
|
||||
console.error(response.body)
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ export default class AuthApi {
|
|||
}
|
||||
|
||||
async login(email: String, password: String): Promise<[Response, any]> {
|
||||
const response = await this.api.post(`/auth/login`, {
|
||||
const response = await this.api.post(`/global/auth/default/login`, {
|
||||
body: {
|
||||
email: email,
|
||||
username: email,
|
||||
password: password,
|
||||
},
|
||||
})
|
||||
|
|
|
@ -7,6 +7,9 @@ import AuthApi from "./auth"
|
|||
import AccountsApiClient from "./accountsAPIClient"
|
||||
import AccountsApi from "./accounts"
|
||||
import { generateAccount } from "../fixtures/accounts"
|
||||
import internalApplicationsApi from "../../internal-api/TestConfiguration/applications"
|
||||
|
||||
import InternalAPIClient from "../../internal-api/TestConfiguration/InternalAPIClient"
|
||||
|
||||
export default class TestConfiguration<T> {
|
||||
applications: ApplicationApi
|
||||
|
@ -18,20 +21,28 @@ export default class TestConfiguration<T> {
|
|||
accounts: AccountsApi
|
||||
apiClient: PublicAPIClient
|
||||
accountsApiClient: AccountsApiClient
|
||||
internalApiClient: InternalAPIClient
|
||||
internalApplicationsApi: internalApplicationsApi
|
||||
|
||||
constructor(
|
||||
apiClient: PublicAPIClient,
|
||||
accountsApiClient: AccountsApiClient
|
||||
accountsApiClient: AccountsApiClient,
|
||||
internalApiClient: InternalAPIClient
|
||||
) {
|
||||
this.apiClient = apiClient
|
||||
this.accountsApiClient = accountsApiClient
|
||||
this.internalApiClient = internalApiClient
|
||||
|
||||
this.auth = new AuthApi(this.accountsApiClient)
|
||||
this.auth = new AuthApi(this.internalApiClient)
|
||||
this.accounts = new AccountsApi(this.accountsApiClient)
|
||||
this.applications = new ApplicationApi(apiClient)
|
||||
this.users = new UserApi(apiClient)
|
||||
this.tables = new TableApi(apiClient)
|
||||
this.rows = new RowApi(apiClient)
|
||||
this.internalApplicationsApi = new internalApplicationsApi(
|
||||
internalApiClient
|
||||
)
|
||||
|
||||
this.context = <T>{}
|
||||
}
|
||||
|
||||
|
@ -43,7 +54,13 @@ export default class TestConfiguration<T> {
|
|||
await this.accounts.create(account)
|
||||
await this.updateApiClients(<string>account.tenantName)
|
||||
await this.auth.login(<string>account.email, <string>account.password)
|
||||
await this.applications.createFirstApp()
|
||||
const body = {
|
||||
name: "My first app",
|
||||
url: "my-first-app",
|
||||
useTemplate: false,
|
||||
sampleData: true,
|
||||
}
|
||||
await this.internalApplicationsApi.create(body)
|
||||
}
|
||||
|
||||
async setApiKey() {
|
||||
|
@ -54,7 +71,11 @@ export default class TestConfiguration<T> {
|
|||
this.apiClient.setTenantName(tenantName)
|
||||
this.applications = new ApplicationApi(this.apiClient)
|
||||
this.rows = new RowApi(this.apiClient)
|
||||
|
||||
this.internalApiClient.setTenantName(tenantName)
|
||||
this.internalApplicationsApi = new internalApplicationsApi(
|
||||
this.internalApiClient
|
||||
)
|
||||
this.auth = new AuthApi(this.internalApiClient)
|
||||
this.context = <T>{}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,14 +4,22 @@ import AccountsAPIClient from "../../../config/public-api/TestConfiguration/acco
|
|||
import generateApp from "../../../config/public-api/fixtures/applications"
|
||||
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||
import { db as dbCore } from "@budibase/backend-core"
|
||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||
|
||||
describe.skip("Public API - /applications endpoints", () => {
|
||||
describe("Public API - /applications endpoints", () => {
|
||||
const api = new PublicAPIClient()
|
||||
const accountsAPI = new AccountsAPIClient()
|
||||
const config = new TestConfiguration<Application>(api, accountsAPI)
|
||||
const internalAPI = new InternalAPIClient()
|
||||
const config = new TestConfiguration<Application>(
|
||||
api,
|
||||
accountsAPI,
|
||||
internalAPI
|
||||
)
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
await config.setupAccountAndTenant()
|
||||
await config.setApiKey()
|
||||
|
||||
const [response, app] = await config.applications.seed()
|
||||
config.context = app
|
||||
})
|
||||
|
|
|
@ -3,14 +3,18 @@ import { generateRow } from "../../../config/public-api/fixtures/tables"
|
|||
import TestConfiguration from "../../../config/public-api/TestConfiguration"
|
||||
import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient"
|
||||
import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient"
|
||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||
|
||||
describe.skip("Public API - /rows endpoints", () => {
|
||||
describe("Public API - /rows endpoints", () => {
|
||||
const api = new PublicAPIClient()
|
||||
const accountsAPI = new AccountsAPIClient()
|
||||
const config = new TestConfiguration<Row>(api, accountsAPI)
|
||||
const internalAPI = new InternalAPIClient()
|
||||
const config = new TestConfiguration<Row>(api, accountsAPI, internalAPI)
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
await config.setupAccountAndTenant()
|
||||
await config.setApiKey()
|
||||
|
||||
const [aResp, app] = await config.applications.seed()
|
||||
|
||||
config.tables.api.appId = app._id
|
||||
|
|
|
@ -3,14 +3,18 @@ import { generateTable } from "../../../config/public-api/fixtures/tables"
|
|||
import TestConfiguration from "../../../config/public-api/TestConfiguration"
|
||||
import PublicAPIClient from "../../../config/public-api/TestConfiguration/PublicAPIClient"
|
||||
import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient"
|
||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||
|
||||
describe.skip("Public API - /tables endpoints", () => {
|
||||
describe("Public API - /tables endpoints", () => {
|
||||
const api = new PublicAPIClient()
|
||||
const accountsAPI = new AccountsAPIClient()
|
||||
const config = new TestConfiguration<Table>(api, accountsAPI)
|
||||
const internalAPI = new InternalAPIClient()
|
||||
const config = new TestConfiguration<Table>(api, accountsAPI, internalAPI)
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.beforeAll()
|
||||
await config.setupAccountAndTenant()
|
||||
await config.setApiKey()
|
||||
|
||||
const [appResp, app] = await config.applications.seed()
|
||||
config.tables.api.appId = app._id
|
||||
|
||||
|
|
|
@ -3,11 +3,13 @@ import PublicAPIClient from "../../../config/public-api/TestConfiguration/Public
|
|||
import generateUser from "../../../config/public-api/fixtures/users"
|
||||
import { User } from "@budibase/server/api/controllers/public/mapping/types"
|
||||
import AccountsAPIClient from "../../../config/public-api/TestConfiguration/accountsAPIClient"
|
||||
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
||||
|
||||
describe("Public API - /users endpoints", () => {
|
||||
const api = new PublicAPIClient()
|
||||
const accountsAPI = new AccountsAPIClient()
|
||||
const config = new TestConfiguration<User>(api, accountsAPI)
|
||||
const internalAPI = new InternalAPIClient()
|
||||
const config = new TestConfiguration<User>(api, accountsAPI, internalAPI)
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.setupAccountAndTenant()
|
||||
|
|
Loading…
Reference in New Issue