Add account password login integration with global setup
This commit is contained in:
parent
d8d4686e01
commit
6f7ef18084
|
@ -1,15 +1,17 @@
|
|||
import AccountInternalAPIClient from "./AccountInternalAPIClient"
|
||||
import { AccountAPI, LicenseAPI } from "./apis"
|
||||
import { AccountAPI, LicenseAPI, AuthAPI } from "./apis"
|
||||
import { State } from "../../types"
|
||||
|
||||
export default class AccountInternalAPI {
|
||||
client: AccountInternalAPIClient
|
||||
|
||||
auth: AuthAPI
|
||||
accounts: AccountAPI
|
||||
licenses: LicenseAPI
|
||||
|
||||
constructor(state: State) {
|
||||
this.client = new AccountInternalAPIClient(state)
|
||||
this.auth = new AuthAPI(this.client)
|
||||
this.accounts = new AccountAPI(this.client)
|
||||
this.licenses = new LicenseAPI(this.client)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
import { Response } from "node-fetch"
|
||||
import AccountInternalAPIClient from "../AccountInternalAPIClient"
|
||||
import { APIRequestOpts } from "../../../types"
|
||||
|
||||
export default class AuthAPI {
|
||||
client: AccountInternalAPIClient
|
||||
|
||||
constructor(client: AccountInternalAPIClient) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async login(
|
||||
email: string,
|
||||
password: string,
|
||||
opts: APIRequestOpts = { doExpect: true }
|
||||
): Promise<[Response, string]> {
|
||||
const [response, json] = await this.client.post(
|
||||
`/api/auth/login`,
|
||||
{
|
||||
body: {
|
||||
username: email,
|
||||
password: password,
|
||||
},
|
||||
}
|
||||
)
|
||||
if (opts.doExpect) {
|
||||
expect(response).toHaveStatusCode(200)
|
||||
}
|
||||
const cookie = response.headers.get("set-cookie")
|
||||
return [response, cookie!]
|
||||
}
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
export { default as AuthAPI } from "./AuthAPI"
|
||||
export { default as AccountAPI } from "./AccountAPI"
|
||||
export { default as LicenseAPI } from "./LicenseAPI"
|
||||
|
|
|
@ -68,8 +68,7 @@ async function loginAsAdmin() {
|
|||
}
|
||||
|
||||
async function loginAsAccount(account: CreateAccountRequest) {
|
||||
const [res, cookie] = await internalApi.auth.login(
|
||||
account.tenantId,
|
||||
const [res, cookie] = await accountsApi.auth.login(
|
||||
account.email,
|
||||
account.password,
|
||||
API_OPTS
|
||||
|
|
Loading…
Reference in New Issue