Changes for Account API Testing
This commit is contained in:
parent
6f7ef18084
commit
fa94b8b9fc
|
@ -53,6 +53,8 @@ async function passportCallback(
|
||||||
}
|
}
|
||||||
|
|
||||||
export const login = async (ctx: Ctx<LoginRequest>, next: any) => {
|
export const login = async (ctx: Ctx<LoginRequest>, next: any) => {
|
||||||
|
const tenantId = context.getTenantId()
|
||||||
|
console.log(tenantId)
|
||||||
const email = ctx.request.body.username
|
const email = ctx.request.body.username
|
||||||
|
|
||||||
const user = await userSdk.getUserByEmail(email)
|
const user = await userSdk.getUserByEmail(email)
|
||||||
|
|
|
@ -73,6 +73,13 @@ export default class AccountAPI {
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deleteCurrentAccount() {
|
||||||
|
const [response, json] = await this.client.del(
|
||||||
|
`/api/accounts`
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
async verifyAccount(
|
async verifyAccount(
|
||||||
verificationCode: string,
|
verificationCode: string,
|
||||||
opts: APIRequestOpts = { doExpect: true }
|
opts: APIRequestOpts = { doExpect: true }
|
||||||
|
|
|
@ -18,7 +18,7 @@ export default class AuthAPI {
|
||||||
`/api/auth/login`,
|
`/api/auth/login`,
|
||||||
{
|
{
|
||||||
body: {
|
body: {
|
||||||
username: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,6 @@ export default class TestConfiguration<T> extends BudibaseTestConfiguration {
|
||||||
this.state.apiKey = apiKeyResponse.apiKey
|
this.state.apiKey = apiKeyResponse.apiKey
|
||||||
}
|
}
|
||||||
|
|
||||||
async setCookieAuth() {
|
|
||||||
const apiKeyResponse = await this.internalApi.self.getApiKey()
|
|
||||||
this.state.apiKey = apiKeyResponse.apiKey
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ describe("Account API - Create Account", () => {
|
||||||
|
|
||||||
it("Creates a new account", async () => {
|
it("Creates a new account", async () => {
|
||||||
await config.api.accounts.create({
|
await config.api.accounts.create({
|
||||||
...fixtures.accounts.generateAccount()
|
...fixtures.accounts.generateAccount()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
|
@ -12,9 +12,26 @@ describe("Account API - Delete Account", () => {
|
||||||
await config.afterAll()
|
await config.afterAll()
|
||||||
})
|
})
|
||||||
|
|
||||||
// it("Deletes an account", async () => {
|
it("Deletes an account", async () => {
|
||||||
//
|
// Create account
|
||||||
// })
|
const createAccountRequest = fixtures.accounts.generateAccount()
|
||||||
|
|
||||||
|
await config.api.accounts.create(
|
||||||
|
createAccountRequest
|
||||||
|
)
|
||||||
|
|
||||||
|
// Login - Get cookie
|
||||||
|
await config.login(
|
||||||
|
createAccountRequest.email,
|
||||||
|
createAccountRequest.password,
|
||||||
|
createAccountRequest.tenantId
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete account
|
||||||
|
const [ res ] = await config.api.accounts.deleteCurrentAccount()
|
||||||
|
|
||||||
|
expect(res.status).toBe(204)
|
||||||
|
})
|
||||||
|
|
||||||
it("Deletes an account by ID", async () => {
|
it("Deletes an account by ID", async () => {
|
||||||
const [response, account] = await config.api.accounts.create({
|
const [response, account] = await config.api.accounts.create({
|
||||||
|
|
|
@ -18,10 +18,12 @@ describe("Account API - Validate Account", () => {
|
||||||
|
|
||||||
|
|
||||||
it("Validates an email", async () => {
|
it("Validates an email", async () => {
|
||||||
|
|
||||||
await config.api.accounts.validateEmail(email)
|
await config.api.accounts.validateEmail(email)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Validates a tenant ID", async () => {
|
it("Validates a tenant ID", async () => {
|
||||||
|
|
||||||
await config.api.accounts.validateTenantId(tenant)
|
await config.api.accounts.validateTenantId(tenant)
|
||||||
})
|
})
|
||||||
})
|
})
|
|
@ -15,10 +15,24 @@ describe("Account API - Verify Account", () => {
|
||||||
|
|
||||||
|
|
||||||
it("Verify an account", async () => {
|
it("Verify an account", async () => {
|
||||||
|
// Create account
|
||||||
|
await config.api.accounts.create({
|
||||||
|
...fixtures.accounts.generateAccount()
|
||||||
|
})
|
||||||
|
// Invite user
|
||||||
|
|
||||||
|
// Verify account via code
|
||||||
await config.api.accounts.verifyAccount()
|
await config.api.accounts.verifyAccount()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Send account verification email ", async () => {
|
it("Send account verification email ", async () => {
|
||||||
|
// Create account
|
||||||
|
await config.api.accounts.create({
|
||||||
|
...fixtures.accounts.generateAccount()
|
||||||
|
})
|
||||||
|
// Invite user
|
||||||
|
|
||||||
|
// Verify account via email
|
||||||
await config.api.accounts.verifyAccountSendEmail()
|
await config.api.accounts.verifyAccountSendEmail()
|
||||||
})
|
})
|
||||||
})
|
})
|
|
@ -43,7 +43,8 @@ export default class BudibaseTestConfiguration {
|
||||||
async login(email: string, password: string, tenantId?: string) {
|
async login(email: string, password: string, tenantId?: string) {
|
||||||
if (!tenantId && this.state.tenantId) {
|
if (!tenantId && this.state.tenantId) {
|
||||||
tenantId = this.state.tenantId
|
tenantId = this.state.tenantId
|
||||||
} else {
|
}
|
||||||
|
if (!tenantId) {
|
||||||
throw new Error("Could not determine tenant id")
|
throw new Error("Could not determine tenant id")
|
||||||
}
|
}
|
||||||
const [res, cookie] = await this.internalApi.auth.login(
|
const [res, cookie] = await this.internalApi.auth.login(
|
||||||
|
|
Loading…
Reference in New Issue