refactor: no-floating-promises

This commit is contained in:
Tibo De Peuter 2025-03-23 13:55:26 +01:00
parent af57cb5d71
commit 4bf82b09fa
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
4 changed files with 19 additions and 18 deletions

View file

@ -34,8 +34,8 @@ let entityManager: EntityManager | undefined;
/**
* Execute all the database operations within the function f in a single transaction.
*/
export function transactional<T>(f: () => Promise<T>): void {
entityManager?.transactional(f);
export async function transactional<T>(f: () => Promise<T>): Promise<void> {
await entityManager?.transactional(f);
}
function repositoryGetter<T extends AnyEntity, R extends EntityRepository<T>>(entity: EntityName<T>): () => R {

View file

@ -10,9 +10,12 @@ import { LearningObjectIdentifier } from '../../../src/entities/content/learning
const NEWER_TEST_SUFFIX = 'nEweR';
function createTestLearningObjects(learningObjectRepo: LearningObjectRepository): { older: LearningObject; newer: LearningObject } {
async function createTestLearningObjects(learningObjectRepo: LearningObjectRepository): Promise<{
older: LearningObject;
newer: LearningObject
}> {
const olderExample = example.createLearningObject();
learningObjectRepo.save(olderExample);
await learningObjectRepo.save(olderExample);
const newerExample = example.createLearningObject();
newerExample.title = 'Newer example';
@ -32,23 +35,21 @@ describe('AttachmentRepository', () => {
beforeAll(async () => {
await setupTestApp();
attachmentRepo = getAttachmentRepository();
exampleLearningObjects = createTestLearningObjects(getLearningObjectRepository());
exampleLearningObjects = await createTestLearningObjects(getLearningObjectRepository());
});
it('can add attachments to learning objects without throwing an error', () => {
it('can add attachments to learning objects without throwing an error', async () => {
attachmentsOlderLearningObject = Object.values(example.createAttachment).map((fn) => fn(exampleLearningObjects.older));
for (const attachment of attachmentsOlderLearningObject) {
attachmentRepo.save(attachment);
}
await Promise.all(attachmentsOlderLearningObject.map(async (attachment) => attachmentRepo.save(attachment)));
});
let attachmentOnlyNewer: Attachment;
it('allows us to add attachments with the same name to a different learning object without throwing an error', () => {
it('allows us to add attachments with the same name to a different learning object without throwing an error', async () => {
attachmentOnlyNewer = Object.values(example.createAttachment)[0](exampleLearningObjects.newer);
attachmentOnlyNewer.content.write(NEWER_TEST_SUFFIX);
attachmentRepo.save(attachmentOnlyNewer);
await attachmentRepo.save(attachmentOnlyNewer);
});
let olderLearningObjectId: LearningObjectIdentifier;

View file

@ -1,6 +1,6 @@
<script setup lang="ts">
import auth from "@/services/auth/auth-service.ts";
auth.loadUser();
await auth.loadUser();
</script>
<template>

View file

@ -2,16 +2,16 @@
import dwengoLogo from "../../../assets/img/dwengo-groen-zwart.svg";
import auth from "@/services/auth/auth-service.ts";
function loginAsStudent(): void {
auth.loginAs("student");
async function loginAsStudent(): Promise<void> {
await auth.loginAs("student");
}
function loginAsTeacher(): void {
auth.loginAs("teacher");
async function loginAsTeacher(): Promise<void> {
await auth.loginAs("teacher");
}
function performLogout(): void {
auth.logout();
async function performLogout(): Promise<void> {
await auth.logout();
}
</script>