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 AccountInternalAPIClient from "./AccountInternalAPIClient"
|
||||||
import { AccountAPI, LicenseAPI } from "./apis"
|
import { AccountAPI, LicenseAPI, AuthAPI } from "./apis"
|
||||||
import { State } from "../../types"
|
import { State } from "../../types"
|
||||||
|
|
||||||
export default class AccountInternalAPI {
|
export default class AccountInternalAPI {
|
||||||
client: AccountInternalAPIClient
|
client: AccountInternalAPIClient
|
||||||
|
|
||||||
|
auth: AuthAPI
|
||||||
accounts: AccountAPI
|
accounts: AccountAPI
|
||||||
licenses: LicenseAPI
|
licenses: LicenseAPI
|
||||||
|
|
||||||
constructor(state: State) {
|
constructor(state: State) {
|
||||||
this.client = new AccountInternalAPIClient(state)
|
this.client = new AccountInternalAPIClient(state)
|
||||||
|
this.auth = new AuthAPI(this.client)
|
||||||
this.accounts = new AccountAPI(this.client)
|
this.accounts = new AccountAPI(this.client)
|
||||||
this.licenses = new LicenseAPI(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 AccountAPI } from "./AccountAPI"
|
||||||
export { default as LicenseAPI } from "./LicenseAPI"
|
export { default as LicenseAPI } from "./LicenseAPI"
|
||||||
|
|
|
@ -68,8 +68,7 @@ async function loginAsAdmin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loginAsAccount(account: CreateAccountRequest) {
|
async function loginAsAccount(account: CreateAccountRequest) {
|
||||||
const [res, cookie] = await internalApi.auth.login(
|
const [res, cookie] = await accountsApi.auth.login(
|
||||||
account.tenantId,
|
|
||||||
account.email,
|
account.email,
|
||||||
account.password,
|
account.password,
|
||||||
API_OPTS
|
API_OPTS
|
||||||
|
|
Loading…
Reference in New Issue