Added caching and implemented UserService

This commit is contained in:
2026-04-07 11:19:38 +02:00
parent aa451e4786
commit 4f96b1d687
11 changed files with 488 additions and 3 deletions

50
tests/userService.test.ts Normal file
View File

@@ -0,0 +1,50 @@
import {describe, expect, it} from "vitest";
import {UserService} from "../src/services/userService";
import {DatabaseMock} from "../src/mocks/storage/database";
import {RGB} from "../src/domain/common.schema"
const USER_SERVICE_TESTING_USER_ID = "000000000000000000000000"
const USER_SERVICE_TESTING_TOKEN = "testingToken"
describe("UserService Integration Testing", () => {
const service = new UserService(USER_SERVICE_TESTING_USER_ID, USER_SERVICE_TESTING_TOKEN, new DatabaseMock())
it('should not throw on username change', async () => {
await service.changeUsername("bob2")
});
it('should not throw on displayName change', async () => {
await service.changeDisplayName("New Display Name")
});
it('should set new password', async () => {
await service.changePassword("newPasswd", "") // The filler user doesn't have a password set yet
});
it('should set new e-mail', async () => {
const code = await service.changeEmail("bob2@example.com", "")
expect(code).not.toBeNull()
if (code != null) {
await service.verifyEmailChange(code.codeCurr??0, code.codeNew??0, "bob2@example.com")
}
});
it('should upload a new pfp', async () => {
const pfpId = await service.uploadNewPfpCdn(null, "A", <RGB>{r: 255, g: 255, b: 255})
await service.uploadNewPfp(pfpId)
});
it('should get sessions', async () => {
const sessions = await service.getSessions()
expect(sessions[0].token).toBe(USER_SERVICE_TESTING_TOKEN)
});
it('should set new phone', async () => {
const code = await service.changePhoneNumber("", "+36201234567")
expect(code).not.toBeNull()
if (code != null) {
await service.verifyPhoneNumberChange("+36201234567", code.codeCurr??0, code.codeNew??0)
}
});
})