refactor: no-floating-promises
This commit is contained in:
parent
af57cb5d71
commit
4bf82b09fa
4 changed files with 19 additions and 18 deletions
|
@ -34,8 +34,8 @@ let entityManager: EntityManager | undefined;
|
||||||
/**
|
/**
|
||||||
* Execute all the database operations within the function f in a single transaction.
|
* Execute all the database operations within the function f in a single transaction.
|
||||||
*/
|
*/
|
||||||
export function transactional<T>(f: () => Promise<T>): void {
|
export async function transactional<T>(f: () => Promise<T>): Promise<void> {
|
||||||
entityManager?.transactional(f);
|
await entityManager?.transactional(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
function repositoryGetter<T extends AnyEntity, R extends EntityRepository<T>>(entity: EntityName<T>): () => R {
|
function repositoryGetter<T extends AnyEntity, R extends EntityRepository<T>>(entity: EntityName<T>): () => R {
|
||||||
|
|
|
@ -10,9 +10,12 @@ import { LearningObjectIdentifier } from '../../../src/entities/content/learning
|
||||||
|
|
||||||
const NEWER_TEST_SUFFIX = 'nEweR';
|
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();
|
const olderExample = example.createLearningObject();
|
||||||
learningObjectRepo.save(olderExample);
|
await learningObjectRepo.save(olderExample);
|
||||||
|
|
||||||
const newerExample = example.createLearningObject();
|
const newerExample = example.createLearningObject();
|
||||||
newerExample.title = 'Newer example';
|
newerExample.title = 'Newer example';
|
||||||
|
@ -32,23 +35,21 @@ describe('AttachmentRepository', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await setupTestApp();
|
await setupTestApp();
|
||||||
attachmentRepo = getAttachmentRepository();
|
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));
|
attachmentsOlderLearningObject = Object.values(example.createAttachment).map((fn) => fn(exampleLearningObjects.older));
|
||||||
|
|
||||||
for (const attachment of attachmentsOlderLearningObject) {
|
await Promise.all(attachmentsOlderLearningObject.map(async (attachment) => attachmentRepo.save(attachment)));
|
||||||
attachmentRepo.save(attachment);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let attachmentOnlyNewer: 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 = Object.values(example.createAttachment)[0](exampleLearningObjects.newer);
|
||||||
attachmentOnlyNewer.content.write(NEWER_TEST_SUFFIX);
|
attachmentOnlyNewer.content.write(NEWER_TEST_SUFFIX);
|
||||||
|
|
||||||
attachmentRepo.save(attachmentOnlyNewer);
|
await attachmentRepo.save(attachmentOnlyNewer);
|
||||||
});
|
});
|
||||||
|
|
||||||
let olderLearningObjectId: LearningObjectIdentifier;
|
let olderLearningObjectId: LearningObjectIdentifier;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import auth from "@/services/auth/auth-service.ts";
|
import auth from "@/services/auth/auth-service.ts";
|
||||||
auth.loadUser();
|
await auth.loadUser();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
import dwengoLogo from "../../../assets/img/dwengo-groen-zwart.svg";
|
import dwengoLogo from "../../../assets/img/dwengo-groen-zwart.svg";
|
||||||
import auth from "@/services/auth/auth-service.ts";
|
import auth from "@/services/auth/auth-service.ts";
|
||||||
|
|
||||||
function loginAsStudent(): void {
|
async function loginAsStudent(): Promise<void> {
|
||||||
auth.loginAs("student");
|
await auth.loginAs("student");
|
||||||
}
|
}
|
||||||
|
|
||||||
function loginAsTeacher(): void {
|
async function loginAsTeacher(): Promise<void> {
|
||||||
auth.loginAs("teacher");
|
await auth.loginAs("teacher");
|
||||||
}
|
}
|
||||||
|
|
||||||
function performLogout(): void {
|
async function performLogout(): Promise<void> {
|
||||||
auth.logout();
|
await auth.logout();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue