Finished implementing NetworkService

This commit is contained in:
2026-04-02 17:26:23 +02:00
parent bf4bd3e218
commit f61fcb4daa
13 changed files with 1304 additions and 37 deletions

View File

@@ -4,8 +4,9 @@ import {VerificationTypeEmail} from "../domain/authService.schema";
import {faker} from "@faker-js/faker/locale/en";
describe("AuthService", () => {
const service = new AuthService();
it("should return authMethods", async () => {
const service = new AuthService();
const methods = await service.getAuthMethods("")
expect(methods.sms).toBeFalsy()
expect(methods.email).toBeTruthy()
@@ -13,57 +14,47 @@ describe("AuthService", () => {
})
it("should send OTP code", async () => {
const service = new AuthService();
const code = await service.otpSendCode("bob@example.com", VerificationTypeEmail)
expect(code).toBe(5000)
})
it("should send password reset code", async () => {
const service = new AuthService();
const code = await service.resetPassword("bob@example.com")
expect(code).toBe(5000)
})
it("should send PLE code", async () => {
const service = new AuthService();
const code = await service.pleSendVCode("bob@example.com", VerificationTypeEmail)
expect(code).toBe(5000)
})
it("should throw on wrong OTP code", async () => {
const service = new AuthService();
await expect(service.otpVerifyCode("bob@example.com", VerificationTypeEmail, 9999)).rejects.toThrow()
})
it("should throw on wrong password reset code", async () => {
const service = new AuthService();
await expect(service.verifyPasswordReset("bob@example.com", 9999, "newPassword")).rejects.toThrow()
})
it("should throw on wrong PLE code", async () => {
const service = new AuthService();
await expect(service.pleVerifyCode("bob@example.com", VerificationTypeEmail, 9999)).rejects.toThrow()
})
it("should throw on wrong password", async () => {
const service = new AuthService();
await expect(service.loginPasswordAuth("bob@example.com", "wrongPasswd")).rejects.toThrow();
})
it("should detect taken username", async () => {
const service = new AuthService();
const taken = await service.isUsernameUsed("username")
expect(taken).toBeTruthy()
})
it("should detect taken e-mail address", async () => {
const service = new AuthService();
const taken = await service.isEmailUsed("taken@example.com")
expect(taken).toBeTruthy()
})
it("should register passwordless account", async () => {
const service = new AuthService();
const username = faker.internet.username()
const displayName = faker.internet.displayName()
const userData = await service.finishPLEAccount(