style: fix linting issues met Prettier
This commit is contained in:
parent
aa1a85e64e
commit
2a2881ec30
84 changed files with 846 additions and 1013 deletions
|
@ -1,21 +1,21 @@
|
|||
import {beforeAll, describe, expect, it} from "vitest";
|
||||
import {setupTestApp} from "../../setup-tests";
|
||||
import {getAttachmentRepository, getLearningObjectRepository} from "../../../src/data/repositories";
|
||||
import {AttachmentRepository} from "../../../src/data/content/attachment-repository";
|
||||
import {LearningObjectRepository} from "../../../src/data/content/learning-object-repository";
|
||||
import example from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example";
|
||||
import {LearningObject} from "../../../src/entities/content/learning-object.entity";
|
||||
import {Attachment} from "../../../src/entities/content/attachment.entity";
|
||||
import {LearningObjectIdentifier} from "../../../src/entities/content/learning-object-identifier";
|
||||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import { setupTestApp } from '../../setup-tests';
|
||||
import { getAttachmentRepository, getLearningObjectRepository } from '../../../src/data/repositories';
|
||||
import { AttachmentRepository } from '../../../src/data/content/attachment-repository';
|
||||
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository';
|
||||
import example from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example';
|
||||
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
|
||||
import { Attachment } from '../../../src/entities/content/attachment.entity';
|
||||
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
|
||||
|
||||
const NEWER_TEST_SUFFIX = "nEweR";
|
||||
const NEWER_TEST_SUFFIX = 'nEweR';
|
||||
|
||||
function createTestLearningObjects(learningObjectRepo: LearningObjectRepository): {older: LearningObject, newer: LearningObject} {
|
||||
function createTestLearningObjects(learningObjectRepo: LearningObjectRepository): { older: LearningObject; newer: LearningObject } {
|
||||
const olderExample = example.createLearningObject();
|
||||
learningObjectRepo.save(olderExample);
|
||||
|
||||
const newerExample = example.createLearningObject();
|
||||
newerExample.title = "Newer example";
|
||||
newerExample.title = 'Newer example';
|
||||
newerExample.version = 100;
|
||||
|
||||
return {
|
||||
|
@ -24,9 +24,9 @@ function createTestLearningObjects(learningObjectRepo: LearningObjectRepository)
|
|||
};
|
||||
}
|
||||
|
||||
describe("AttachmentRepository", () => {
|
||||
describe('AttachmentRepository', () => {
|
||||
let attachmentRepo: AttachmentRepository;
|
||||
let exampleLearningObjects: {older: LearningObject, newer: LearningObject};
|
||||
let exampleLearningObjects: { older: LearningObject; newer: LearningObject };
|
||||
let attachmentsOlderLearningObject: Attachment[];
|
||||
|
||||
beforeAll(async () => {
|
||||
|
@ -35,10 +35,8 @@ describe("AttachmentRepository", () => {
|
|||
exampleLearningObjects = createTestLearningObjects(getLearningObjectRepository());
|
||||
});
|
||||
|
||||
it("can add attachments to learning objects without throwing an error", () => {
|
||||
attachmentsOlderLearningObject = Object
|
||||
.values(example.createAttachment)
|
||||
.map(fn => fn(exampleLearningObjects.older));
|
||||
it('can add attachments to learning objects without throwing an error', () => {
|
||||
attachmentsOlderLearningObject = Object.values(example.createAttachment).map((fn) => fn(exampleLearningObjects.older));
|
||||
|
||||
for (const attachment of attachmentsOlderLearningObject) {
|
||||
attachmentRepo.save(attachment);
|
||||
|
@ -46,7 +44,7 @@ describe("AttachmentRepository", () => {
|
|||
});
|
||||
|
||||
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', () => {
|
||||
attachmentOnlyNewer = Object.values(example.createAttachment)[0](exampleLearningObjects.newer);
|
||||
attachmentOnlyNewer.content.write(NEWER_TEST_SUFFIX);
|
||||
|
||||
|
@ -54,29 +52,23 @@ describe("AttachmentRepository", () => {
|
|||
});
|
||||
|
||||
let olderLearningObjectId: LearningObjectIdentifier;
|
||||
it("returns the correct attachment when queried by learningObjectId and attachment name", async () => {
|
||||
it('returns the correct attachment when queried by learningObjectId and attachment name', async () => {
|
||||
olderLearningObjectId = {
|
||||
hruid: exampleLearningObjects.older.hruid,
|
||||
language: exampleLearningObjects.older.language,
|
||||
version: exampleLearningObjects.older.version
|
||||
version: exampleLearningObjects.older.version,
|
||||
};
|
||||
|
||||
const result = await attachmentRepo.findByLearningObjectIdAndName(
|
||||
olderLearningObjectId,
|
||||
attachmentsOlderLearningObject[0].name
|
||||
);
|
||||
const result = await attachmentRepo.findByLearningObjectIdAndName(olderLearningObjectId, attachmentsOlderLearningObject[0].name);
|
||||
expect(result).toBe(attachmentsOlderLearningObject[0]);
|
||||
});
|
||||
|
||||
it("returns null when queried by learningObjectId and non-existing attachment name", async () => {
|
||||
const result = await attachmentRepo.findByLearningObjectIdAndName(
|
||||
olderLearningObjectId,
|
||||
"non-existing name"
|
||||
);
|
||||
it('returns null when queried by learningObjectId and non-existing attachment name', async () => {
|
||||
const result = await attachmentRepo.findByLearningObjectIdAndName(olderLearningObjectId, 'non-existing name');
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
|
||||
it("returns the newer version of the attachment when only queried by hruid, language and attachment name (but not version)", async () => {
|
||||
it('returns the newer version of the attachment when only queried by hruid, language and attachment name (but not version)', async () => {
|
||||
const result = await attachmentRepo.findByMostRecentVersionOfLearningObjectAndName(
|
||||
exampleLearningObjects.older.hruid,
|
||||
exampleLearningObjects.older.language,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import {beforeAll, describe, it, expect} from "vitest";
|
||||
import {LearningObjectRepository} from "../../../src/data/content/learning-object-repository";
|
||||
import {setupTestApp} from "../../setup-tests";
|
||||
import {getLearningObjectRepository} from "../../../src/data/repositories";
|
||||
import example from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example.js"
|
||||
import {LearningObject} from "../../../src/entities/content/learning-object.entity";
|
||||
import {expectToBeCorrectEntity} from "../../test-utils/expectations";
|
||||
import { beforeAll, describe, it, expect } from 'vitest';
|
||||
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository';
|
||||
import { setupTestApp } from '../../setup-tests';
|
||||
import { getLearningObjectRepository } from '../../../src/data/repositories';
|
||||
import example from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example.js';
|
||||
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
|
||||
import { expectToBeCorrectEntity } from '../../test-utils/expectations';
|
||||
|
||||
describe("LearningObjectRepository", () => {
|
||||
describe('LearningObjectRepository', () => {
|
||||
let learningObjectRepository: LearningObjectRepository;
|
||||
|
||||
let exampleLearningObject: LearningObject;
|
||||
|
@ -16,55 +16,57 @@ describe("LearningObjectRepository", () => {
|
|||
learningObjectRepository = getLearningObjectRepository();
|
||||
});
|
||||
|
||||
it("should be able to add a learning object to it without an error", async () => {
|
||||
it('should be able to add a learning object to it without an error', async () => {
|
||||
exampleLearningObject = example.createLearningObject();
|
||||
await learningObjectRepository.insert(exampleLearningObject);
|
||||
});
|
||||
|
||||
it("should return the learning object when queried by id", async () => {
|
||||
it('should return the learning object when queried by id', async () => {
|
||||
const result = await learningObjectRepository.findByIdentifier({
|
||||
hruid: exampleLearningObject.hruid,
|
||||
language: exampleLearningObject.language,
|
||||
version: exampleLearningObject.version
|
||||
version: exampleLearningObject.version,
|
||||
});
|
||||
expect(result).toBeInstanceOf(LearningObject);
|
||||
expectToBeCorrectEntity({
|
||||
name: "actual",
|
||||
entity: result!
|
||||
}, {
|
||||
name: "expected",
|
||||
entity: exampleLearningObject
|
||||
});
|
||||
expectToBeCorrectEntity(
|
||||
{
|
||||
name: 'actual',
|
||||
entity: result!,
|
||||
},
|
||||
{
|
||||
name: 'expected',
|
||||
entity: exampleLearningObject,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("should return null when non-existing version is queried", async () => {
|
||||
it('should return null when non-existing version is queried', async () => {
|
||||
const result = await learningObjectRepository.findByIdentifier({
|
||||
hruid: exampleLearningObject.hruid,
|
||||
language: exampleLearningObject.language,
|
||||
version: 100
|
||||
version: 100,
|
||||
});
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
|
||||
let newerExample: LearningObject;
|
||||
|
||||
it("should allow a learning object with the same id except a different version to be added", async () => {
|
||||
it('should allow a learning object with the same id except a different version to be added', async () => {
|
||||
newerExample = example.createLearningObject();
|
||||
newerExample.version = 10;
|
||||
newerExample.title += " (nieuw)";
|
||||
newerExample.title += ' (nieuw)';
|
||||
await learningObjectRepository.save(newerExample);
|
||||
});
|
||||
|
||||
it("should return the newest version of the learning object when queried by only hruid and language", async () => {
|
||||
it('should return the newest version of the learning object when queried by only hruid and language', async () => {
|
||||
const result = await learningObjectRepository.findLatestByHruidAndLanguage(newerExample.hruid, newerExample.language);
|
||||
expect(result).toBeInstanceOf(LearningObject);
|
||||
expect(result?.version).toBe(10);
|
||||
expect(result?.title).toContain("(nieuw)");
|
||||
expect(result?.title).toContain('(nieuw)');
|
||||
});
|
||||
|
||||
it("should return null when queried by non-existing hruid or language", async () => {
|
||||
const result = await learningObjectRepository.findLatestByHruidAndLanguage("something_that_does_not_exist", exampleLearningObject.language);
|
||||
it('should return null when queried by non-existing hruid or language', async () => {
|
||||
const result = await learningObjectRepository.findLatestByHruidAndLanguage('something_that_does_not_exist', exampleLearningObject.language);
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
import {beforeAll, describe, expect, it} from "vitest";
|
||||
import {setupTestApp} from "../../setup-tests";
|
||||
import {getLearningPathRepository} from "../../../src/data/repositories";
|
||||
import {LearningPathRepository} from "../../../src/data/content/learning-path-repository";
|
||||
import example from "../../test-assets/learning-paths/pn-werking-example";
|
||||
import {LearningPath} from "../../../src/entities/content/learning-path.entity";
|
||||
import {expectToBeCorrectEntity} from "../../test-utils/expectations";
|
||||
import {Language} from "../../../src/entities/content/language";
|
||||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import { setupTestApp } from '../../setup-tests';
|
||||
import { getLearningPathRepository } from '../../../src/data/repositories';
|
||||
import { LearningPathRepository } from '../../../src/data/content/learning-path-repository';
|
||||
import example from '../../test-assets/learning-paths/pn-werking-example';
|
||||
import { LearningPath } from '../../../src/entities/content/learning-path.entity';
|
||||
import { expectToBeCorrectEntity } from '../../test-utils/expectations';
|
||||
import { Language } from '../../../src/entities/content/language';
|
||||
|
||||
function expectToHaveFoundPrecisely(expected: LearningPath, result: LearningPath[]): void {
|
||||
expect(result).toHaveProperty("length");
|
||||
expect(result).toHaveProperty('length');
|
||||
expect(result.length).toBe(1);
|
||||
expectToBeCorrectEntity({ entity: result[0]! }, { entity: expected });
|
||||
}
|
||||
|
||||
function expectToHaveFoundNothing(result: LearningPath[]): void {
|
||||
expect(result).toHaveProperty("length");
|
||||
expect(result).toHaveProperty('length');
|
||||
expect(result.length).toBe(0);
|
||||
}
|
||||
|
||||
describe("LearningPathRepository", () => {
|
||||
describe('LearningPathRepository', () => {
|
||||
let learningPathRepo: LearningPathRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
|
@ -28,51 +28,39 @@ describe("LearningPathRepository", () => {
|
|||
|
||||
let examplePath: LearningPath;
|
||||
|
||||
it("should be able to add a learning path without throwing an error", async () => {
|
||||
it('should be able to add a learning path without throwing an error', async () => {
|
||||
examplePath = example.createLearningPath();
|
||||
await learningPathRepo.insert(examplePath);
|
||||
});
|
||||
|
||||
it("should return the added path when it is queried by hruid and language", async () => {
|
||||
it('should return the added path when it is queried by hruid and language', async () => {
|
||||
const result = await learningPathRepo.findByHruidAndLanguage(examplePath.hruid, examplePath.language);
|
||||
expect(result).toBeInstanceOf(LearningPath);
|
||||
expectToBeCorrectEntity({ entity: result! }, { entity: examplePath });
|
||||
});
|
||||
|
||||
it("should return null to a query on a non-existing hruid or language", async () => {
|
||||
const result = await learningPathRepo.findByHruidAndLanguage("not_existing_hruid", examplePath.language);
|
||||
it('should return null to a query on a non-existing hruid or language', async () => {
|
||||
const result = await learningPathRepo.findByHruidAndLanguage('not_existing_hruid', examplePath.language);
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
|
||||
it("should return the learning path when we search for a search term occurring in its title", async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(
|
||||
examplePath.title.slice(4, 9),
|
||||
examplePath.language
|
||||
);
|
||||
it('should return the learning path when we search for a search term occurring in its title', async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(examplePath.title.slice(4, 9), examplePath.language);
|
||||
expectToHaveFoundPrecisely(examplePath, result);
|
||||
});
|
||||
|
||||
it("should return the learning path when we search for a search term occurring in its description", async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(
|
||||
examplePath.description.slice(8, 15),
|
||||
examplePath.language
|
||||
);
|
||||
it('should return the learning path when we search for a search term occurring in its description', async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(examplePath.description.slice(8, 15), examplePath.language);
|
||||
expectToHaveFoundPrecisely(examplePath, result);
|
||||
});
|
||||
|
||||
it("should return null when we search for something not occurring in its title or description", async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(
|
||||
"something not occurring in the path",
|
||||
examplePath.language
|
||||
);
|
||||
it('should return null when we search for something not occurring in its title or description', async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage('something not occurring in the path', examplePath.language);
|
||||
expectToHaveFoundNothing(result);
|
||||
});
|
||||
|
||||
it("should return null when we search for something occurring in its title, but another language", async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(
|
||||
examplePath.description.slice(1, 3),
|
||||
Language.Kalaallisut
|
||||
);
|
||||
it('should return null when we search for something occurring in its title, but another language', async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(examplePath.description.slice(1, 3), Language.Kalaallisut);
|
||||
expectToHaveFoundNothing(result);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue