From 9307832b1518f33f19a71960cbbd20d8a2b97a4f Mon Sep 17 00:00:00 2001 From: Marco La Rosa Date: Fri, 17 Nov 2023 14:11:23 +1100 Subject: [PATCH] ditch more barrel file imports and fix tests --- api/src/common/aws-ses.spec.js | 5 +- api/src/common/elastic-index.js | 23 +++---- api/src/common/jwt.spec.js | 4 +- api/src/common/logger.spec.js | 2 +- api/src/common/test-utils.js | 99 +++++++++++++++++++++++++++++++ api/src/lib/admin.js | 31 ++++++---- api/src/lib/admin.spec.js | 37 +++++------- api/src/lib/collection.spec.js | 3 +- api/src/lib/crate-tools.spec.js | 5 +- api/src/lib/item.spec.js | 4 +- api/src/lib/logs.spec.js | 2 +- api/src/lib/repository.spec.js | 27 +++++---- api/src/lib/session.spec.js | 2 +- api/src/lib/user.spec.js | 14 +++-- api/src/routes/admin.spec.js | 9 ++- api/src/routes/base.spec.js | 7 ++- api/src/routes/collection.spec.js | 3 +- api/src/routes/data/data.spec.js | 2 +- api/src/routes/item.spec.js | 11 +--- api/src/routes/logs.spec.js | 2 +- api/src/routes/publish.spec.js | 4 +- api/src/routes/repository.spec.js | 25 +++----- api/src/routes/user.spec.js | 12 +++- 23 files changed, 222 insertions(+), 111 deletions(-) diff --git a/api/src/common/aws-ses.spec.js b/api/src/common/aws-ses.spec.js index d7f12105..2d254752 100644 --- a/api/src/common/aws-ses.spec.js +++ b/api/src/common/aws-ses.spec.js @@ -28,13 +28,14 @@ describe("AWS SES tests", () => { let templates = await ses.listTemplates(); templates.TemplatesMetadata = templates.TemplatesMetadata.filter( (t) => !t.Name.match(/production-/) - ); + ).filter((t) => !t.Name.match(/development-/)); expect(templates.TemplatesMetadata).toEqual([]); + await ses.loadTemplates(); templates = await ses.listTemplates(); templates.TemplatesMetadata = templates.TemplatesMetadata.filter( (t) => !t.Name.match(/production-/) - ); + ).filter((t) => !t.Name.match(/development-/)); expect(templates.TemplatesMetadata).toMatchObject([{ Name: "testing-application-login" }]); }); it("should be able to send a templated email", async () => { diff --git a/api/src/common/elastic-index.js b/api/src/common/elastic-index.js index f6e2b4ae..c359fb99 100644 --- a/api/src/common/elastic-index.js +++ b/api/src/common/elastic-index.js @@ -43,26 +43,27 @@ export async function indexItem({ location = "workspace", configuration, item, c // index the item metadata and content const indexIdentifier = `/${item.type}/${item.identifier}`; + let store = await getStoreHandle({ location, id: item.identifier, type: "item" }); + let teiText; try { - let store = await getStoreHandle({ location, id: item.identifier, type: "item" }); const teiFileContent = await store.get({ target: `${item.identifier}-tei-complete.xml`, }); - let teiText = await extractText({ + teiText = await extractText({ configuration, content: teiFileContent, }); - const document = assembleIndexRecord({ crate }); - document.text = teiText; - await client.index({ - index: "manuscripts", - id: indexIdentifier, - document, - }); - // console.log(document); } catch (error) { - console.log(error); + teiText = ""; } + const document = assembleIndexRecord({ crate }); + document.text = teiText; + await client.index({ + index: "manuscripts", + id: indexIdentifier, + document, + }); + // console.log(document); // setup the entities index try { // await client.indices.delete({ index: "entities" }); diff --git a/api/src/common/jwt.spec.js b/api/src/common/jwt.spec.js index c59aa1e4..451374cc 100644 --- a/api/src/common/jwt.spec.js +++ b/api/src/common/jwt.spec.js @@ -1,9 +1,9 @@ require("regenerator-runtime"); import { generateToken, verifyToken } from "./jwt"; -import { loadConfiguration } from "../common"; +import { loadConfiguration } from "../common/configuration.js"; const chance = require("chance").Chance(); import MockDate from "mockdate"; -import { TestSetup } from "../common"; +import { TestSetup } from "../common/test-utils.js"; describe("JWT tests", () => { let configuration, users, userEmail, adminEmail, bucket; diff --git a/api/src/common/logger.spec.js b/api/src/common/logger.spec.js index eb722f1e..4226537e 100644 --- a/api/src/common/logger.spec.js +++ b/api/src/common/logger.spec.js @@ -1,5 +1,5 @@ import "regenerator-runtime"; -import { logEvent } from "./logger"; +import { logEvent } from "./logger.js"; import models from "../models"; describe("Logger tests", () => { it("should be able to log an event to the logs table", async () => { diff --git a/api/src/common/test-utils.js b/api/src/common/test-utils.js index ff20f0a3..0abe5128 100644 --- a/api/src/common/test-utils.js +++ b/api/src/common/test-utils.js @@ -12,6 +12,101 @@ import { getS3Handle } from "./getS3Handle.js"; const bucketName = "testing"; export const host = `http://localhost:8080`; +export function teiDocument(identifier) { + return ` + + + + My Research Object CrateNyingarn

some text

+ { + "@graph": [ + { + "identifier": "ro-crate-metadata.json", + "@type": "CreativeWork", + "about": { "@id": ".\/" }, + "@id": "ro-crate-metadata.json", + "conformsTo": { "@id": "https:\/\/w3id.org\/ro\/crate\/1.1" } + }, + { + "rightsHolder": { "@id": "https:\/\/orcid.org\/0000-0003-1783-627X" }, + "identifier": "MarcoTest", + "licence": { "@id": "LICENCE.md" }, + "hasPart": [ + { "@id": "MarcoTest-357.jpg" }, + { "@id": "MarcoTest-357.tei.xml" }, + { "@id": "MarcoTest-357.textract_ocr-ADMIN.json" }, + { "@id": "MarcoTest-357.thumbnail_h300.jpg" }, + { "@id": "MarcoTest-357.webp" }, + { "@id": "MarcoTest-4003.jpg" }, + { "@id": "MarcoTest-4003.tei.xml" }, + { "@id": "MarcoTest-4003.textract_ocr-ADMIN.json" }, + { "@id": "MarcoTest-4003.thumbnail_h300.jpg" }, + { "@id": "MarcoTest-4003.webp" }, + { "@id": "MarcoTest-language-authority-permission.pdf" }, + { "@id": "MarcoTest-rights-holder-permission.pdf" }, + { "@id": ".item-status.json" }, + { "@id": "MarcoTest-tei-complete.xml" }, + { "@id": "LICENCE.md" }, + { "@id": "MarcoTest-tei-complete.v2023-07-10T03:50:13.975Z.xml" } + ], + "@type": [ "Dataset" ], + "author": { "@id": "https:\/\/orcid.org\/0000-0003-1783-627X" }, + "description": "some text", + "languageName": "more text", + "subjectLanguage": { "@id": "https:\/\/collection.aiatsis.gov.au\/austlang\/language\/D2" }, + "copyrightStatus": "Yes = in copyright", + "name": "My Research Object Crate", + "contentLanguage": [ + { "@id": "https:\/\/collection.aiatsis.gov.au\/austlang\/language\/W40" }, + { "@id": "https:\/\/collection.aiatsis.gov.au\/austlang\/language\/A48" }, + { "@id": "#e27" } + ], + "depositor": { "@id": "https:\/\/orcid.org\/0000-0001-5383-6993" }, + "@id": ".\/" + }, + ] + } +
+A +English and Aboriginal +A +Allow +Anoy +Along +Kash too bur-roin +answer +Foom boon +- +Also +tey +ant small kind +Beal- belp +Ber +ser-gun +do bull +nur murn +Amidel +Bar-go-rut +Ankle +Beur nar fer +Amiss +nil lam +apartment +Wil-mut +and +Bar +apple +Bool le-vrum +anget +Pork bork/bar-ren +War-ra three +Lam-bar-more +another +th ung +arch on Gap +Pear - bor ring +
`; +} export function headers(session) { return { @@ -107,6 +202,10 @@ export async function setupTestItem({ identifier, store, user }) { content: "text", target: `${identifier}-02.txt`, }, + { + content: teiDocument(identifier), + target: `${identifier}-tei-complete.xml`, + }, ], }); return { item }; diff --git a/api/src/lib/admin.js b/api/src/lib/admin.js index 4493ff9b..9eb57076 100644 --- a/api/src/lib/admin.js +++ b/api/src/lib/admin.js @@ -427,17 +427,28 @@ export async function setRepositoryItemMetadata({ configuration, item, store }) try { let licence = crate.getEntity("LICENCE.md"); - if (!licence) throw new Error(`no licence found - setting to closed`); - let openAccess = false; - let accessControlList = null; - let accessNarrative = null; - let reviewDate = null; - if (licence?.access?.[0]?.["@id"]?.match(/OpenAccess/)) { - openAccess = true; + let openAccess; + let accessControlList; + let accessNarrative; + let reviewDate; + if (!licence) { + console.log(`no licence found - setting to closed`); + openAccess = false; + accessControlList = null; + accessNarrative = null; + reviewDate = null; } else { - accessNarrative = licence.description.join("\n"); - reviewDate = licence?.reviewDate?.[0]; - accessControlList = await store.getJSON({ target: authorisedUsersFile }); + openAccess = false; + accessControlList = null; + accessNarrative = null; + reviewDate = null; + if (licence?.access?.[0]?.["@id"]?.match(/OpenAccess/)) { + openAccess = true; + } else { + accessNarrative = licence.description.join("\n"); + reviewDate = licence?.reviewDate?.[0]; + accessControlList = await store.getJSON({ target: authorisedUsersFile }); + } } item.openAccess = openAccess; diff --git a/api/src/lib/admin.spec.js b/api/src/lib/admin.spec.js index 926c7012..3e85e8ac 100644 --- a/api/src/lib/admin.spec.js +++ b/api/src/lib/admin.spec.js @@ -2,14 +2,9 @@ require("regenerator-runtime"); import { deleteItem } from "../lib/item.js"; import Chance from "chance"; const chance = Chance(); -import { - loadConfiguration, - getStoreHandle, - TestSetup, - setupTestItem, - setupTestCollection, - getS3Handle, -} from "../common/index.js"; +import { TestSetup, setupTestItem, setupTestCollection } from "../common/test-utils.js"; +import { getS3Handle, getStoreHandle } from "../common/getS3Handle.js"; +import { loadConfiguration } from "../common/configuration.js"; import models from "../models/index.js"; import { getAdminItems, @@ -427,25 +422,24 @@ describe("Admin management tests", () => { await item.reload(); // deposit into the repo - await depositObjectIntoRepository({ type: "item", identifier }); + await depositObjectIntoRepository({ type: "item", identifier, configuration }); let resources = await objectRepository.listResources(); resources = resources.map((r) => r.Key); - expect(resources.length).toEqual(9); + expect(resources.length).toEqual(10); - let objectExistsInWorkspace = await objectWorkspace.exists(); - expect(objectExistsInWorkspace).toBeFalse; + // let objectExistsInWorkspace = await objectWorkspace.exists(); + // expect(objectExistsInWorkspace).toBeFalse; const client = new Client({ node: configuration.api.services.elastic.host, }); let document = await client.get({ - index: "metadata", + index: "manuscripts", id: `/item/${identifier}`, }); expect(document._source).toMatchObject({ - "@id": "./", - "@type": ["Dataset"], + name: "My Research Object Crate", }); await objectWorkspace.removeObject(); @@ -480,16 +474,16 @@ describe("Admin management tests", () => { await item.reload(); // deposit into the repo - await depositObjectIntoRepository({ type: "item", identifier }); + await depositObjectIntoRepository({ type: "item", identifier, configuration }); // restore the object from the repo back into the workspace - await restoreObjectIntoWorkspace({ type: "item", identifier }); + // await restoreObjectIntoWorkspace({ type: "item", identifier }); let objectExistsInWorkspace = await objectWorkspace.exists(); expect(objectExistsInWorkspace).toBeTrue; let resources = await objectWorkspace.listResources(); resources = resources.map((r) => r.Key); - expect(resources.length).toEqual(9); + expect(resources.length).toEqual(10); // change the metadata file so it versions let crateFile = await objectWorkspace.getJSON({ target: "ro-crate-metadata.json" }); @@ -498,18 +492,19 @@ describe("Admin management tests", () => { resources = await objectWorkspace.listResources(); resources = resources.map((r) => r.Key); - expect(resources.length).toEqual(9); + expect(resources.length).toEqual(10); // deposit into the repo a second time and check metadata versioned await depositObjectIntoRepository({ type: "item", identifier, version: { metadata: true }, + configuration, }); resources = await objectRepository.listResources(); resources = resources.map((r) => r.Key); - expect(resources.length).toEqual(10); + expect(resources.length).toEqual(11); let crateFileVersions = await objectRepository.listFileVersions({ target: "ro-crate-metadata.json ", @@ -548,7 +543,7 @@ describe("Admin management tests", () => { await item.reload(); // deposit into the repo - await depositObjectIntoRepository({ type: "item", identifier }); + await depositObjectIntoRepository({ type: "item", identifier, configuration }); // delete the item from the repository await deleteItemFromRepository({ type: "item", identifier, configuration }); diff --git a/api/src/lib/collection.spec.js b/api/src/lib/collection.spec.js index c1648bed..492a51db 100644 --- a/api/src/lib/collection.spec.js +++ b/api/src/lib/collection.spec.js @@ -8,7 +8,8 @@ import { toggleCollectionVisibility, } from "./collection"; const chance = require("chance").Chance(); -import { getStoreHandle, TestSetup } from "../common"; +import { TestSetup } from "../common/test-utils.js"; +import { getStoreHandle } from "../common/getS3Handle"; describe("Collection management tests", () => { let configuration, users, userEmail, adminEmail, bucket; diff --git a/api/src/lib/crate-tools.spec.js b/api/src/lib/crate-tools.spec.js index ce392ebe..f8d234ee 100644 --- a/api/src/lib/crate-tools.spec.js +++ b/api/src/lib/crate-tools.spec.js @@ -1,7 +1,8 @@ require("regenerator-runtime"); import { registerAllFiles } from "./crate-tools.js"; const chance = require("chance").Chance(); -import { getStoreHandle, TestSetup, setupTestItem } from "../common"; +import { TestSetup, setupTestItem } from "../common/test-utils.js"; +import { getStoreHandle } from "../common/getS3Handle.js"; import { ROCrate } from "ro-crate"; import models from "../models"; @@ -35,7 +36,7 @@ describe("Crate tools tests", () => { let resources = await store.listResources(); await registerAllFiles({ crate, resources }); - expect(crate.rootDataset.hasPart.length).toBe(4); + expect(crate.rootDataset.hasPart.length).toBe(5); await models.item.destroy({ where: { identifier } }); await store.removeObject(); diff --git a/api/src/lib/item.spec.js b/api/src/lib/item.spec.js index 4447e9a8..05f7b2d0 100644 --- a/api/src/lib/item.spec.js +++ b/api/src/lib/item.spec.js @@ -20,7 +20,9 @@ import { saveItemTranscription, } from "./item"; const chance = require("chance").Chance(); -import { getStoreHandle, TestSetup, setupTestItem, resourceStatusFile } from "../common"; +import { resourceStatusFile } from "../common/index.js"; +import { TestSetup, setupTestItem } from "../common/test-utils.js"; +import { getStoreHandle } from "../common/getS3Handle"; import models from "../models"; describe("Item management tests", () => { diff --git a/api/src/lib/logs.spec.js b/api/src/lib/logs.spec.js index 1dfe4325..eb0552f8 100644 --- a/api/src/lib/logs.spec.js +++ b/api/src/lib/logs.spec.js @@ -1,7 +1,7 @@ require("regenerator-runtime"); import models from "../models"; const { getLogs } = require("./logs"); -import { generateLogs } from "../common"; +import { generateLogs } from "../common/test-utils.js"; describe("Log management tests", () => { beforeAll(async () => { diff --git a/api/src/lib/repository.spec.js b/api/src/lib/repository.spec.js index 50196100..4ec98cce 100644 --- a/api/src/lib/repository.spec.js +++ b/api/src/lib/repository.spec.js @@ -1,13 +1,10 @@ require("regenerator-runtime"); import Chance from "chance"; const chance = Chance(); -import { - loadConfiguration, - getStoreHandle, - getS3Handle, - TestSetup, - indexItem, -} from "../common/index.js"; +import { TestSetup, teiDocument } from "../common/test-utils.js"; +import { indexItem } from "../common/elastic-index.js"; +import { getStoreHandle, getS3Handle } from "../common/getS3Handle.js"; +import { loadConfiguration } from "../common/configuration.js"; import models from "../models/index.js"; import { importRepositoryContentFromStorageIntoTheDb, getRepositoryItems } from "./repository.js"; import { Client } from "@elastic/elasticsearch"; @@ -77,6 +74,10 @@ describe("Repository management tests", () => { location: "repository", }); await storeItem.createObject(); + await storeItem.put({ + target: `${identifier}-tei-complete.xml`, + content: teiDocument(identifier), + }); let crate = await storeItem.getJSON({ target: "ro-crate-metadata.json" }); @@ -104,7 +105,9 @@ describe("Repository management tests", () => { await indexItem({ item: { identifier, type: "item" }, + location: "repository", crate, + configuration, }); const client = new Client({ @@ -112,15 +115,11 @@ describe("Repository management tests", () => { }); let document = await client.get({ - index: "metadata", + index: "manuscripts", id: `/item/${identifier}`, }); expect(document._source).toMatchObject({ - "@id": "./", - "@type": ["Dataset"], - name: ["crate"], - author: [{}], - thingo: [{}], + name: "crate", }); let person = await client.get({ index: "entities", @@ -559,6 +558,8 @@ describe("Repository management tests", () => { await indexItem({ item: { identifier, type: "item" }, crate, + configuration, + location: "repository", }); }); }); diff --git a/api/src/lib/session.spec.js b/api/src/lib/session.spec.js index 8a0b37d0..773fac1b 100644 --- a/api/src/lib/session.spec.js +++ b/api/src/lib/session.spec.js @@ -2,7 +2,7 @@ require("regenerator-runtime"); const { getSession, createSession, destroySession } = require("./session"); const { createUser } = require("./user"); const chance = require("chance").Chance(); -import { TestSetup } from "../common"; +import { TestSetup } from "../common/test-utils.js"; describe("Session management tests", () => { let configuration, users, userEmail, adminEmail, bucket; diff --git a/api/src/lib/user.spec.js b/api/src/lib/user.spec.js index b4b21630..7ba9f769 100644 --- a/api/src/lib/user.spec.js +++ b/api/src/lib/user.spec.js @@ -8,7 +8,7 @@ import { createAllowedUserStubAccounts, } from "./user"; const chance = require("chance").Chance(); -import { TestSetup } from "../common"; +import { TestSetup } from "../common/test-utils.js"; describe("User management tests", () => { let configuration, users, userEmail, adminEmail, bucket; @@ -60,7 +60,9 @@ describe("User management tests", () => { it("should be able to set up a normal user account", async () => { // create stub account let email = chance.email(); - let users = await createAllowedUserStubAccounts({ emails: [email] }); + let users = await createAllowedUserStubAccounts({ + accounts: [{ email, givenName: chance.word(), familyName: chance.word() }], + }); // create user let user = await createUser({ @@ -128,14 +130,18 @@ describe("User management tests", () => { }); it("should be able to create user stub accounts", async () => { let emails = [chance.email()]; - let users = await createAllowedUserStubAccounts({ emails }); + let users = await createAllowedUserStubAccounts({ + accounts: [{ email: emails[0], givenName: chance.word(), familyName: chance.word() }], + }); expect(users.length).toEqual(1); expect(emails).toEqual([users[0].email]); for (let user of users) await user.destroy(); let email = chance.email(); emails = [email, email]; - users = await createAllowedUserStubAccounts({ emails }); + users = await createAllowedUserStubAccounts({ + accounts: [{ email: emails[1], givenName: chance.word(), familyName: chance.word() }], + }); expect(users.length).toEqual(1); }); }); diff --git a/api/src/routes/admin.spec.js b/api/src/routes/admin.spec.js index 741da85e..21ad3c08 100644 --- a/api/src/routes/admin.spec.js +++ b/api/src/routes/admin.spec.js @@ -1,18 +1,17 @@ require("regenerator-runtime"); import { createSession } from "../lib/session.js"; -import { deleteItem } from "../lib/item.js"; import Chance from "chance"; const chance = Chance(); import fetch from "cross-fetch"; import { - getStoreHandle, TestSetup, headers, host, setupTestItem, setupTestCollection, - loadConfiguration, -} from "../common/index.js"; +} from "../common/test-utils.js"; +import { getStoreHandle } from "../common/getS3Handle.js"; +import { loadConfiguration } from "../common/configuration.js"; import { publishObject } from "../lib/admin.js"; import models from "../models/index.js"; @@ -313,7 +312,7 @@ describe("Admin route tests", () => { expect(await repositoryObject.exists()).toBeTrue; let resources = await repositoryObject.listResources(); resources = resources.map((r) => r.Key); - expect(resources.length).toEqual(9); + expect(resources.length).toEqual(10); await models.item.destroy({ where: { identifier } }); await workspaceObject.removeObject(); diff --git a/api/src/routes/base.spec.js b/api/src/routes/base.spec.js index 5714f501..996582ed 100644 --- a/api/src/routes/base.spec.js +++ b/api/src/routes/base.spec.js @@ -1,9 +1,10 @@ import "regenerator-runtime"; import fetch from "node-fetch"; -import { createUser } from "../lib/user"; -import { loadConfiguration, generateToken } from "../common"; +import { generateToken } from "../common/jwt.js"; +import { loadConfiguration } from "../common/configuration.js"; const chance = require("chance").Chance(); -import { getStoreHandle, TestSetup, headers, host } from "../common"; +import { TestSetup, host } from "../common/test-utils.js"; +import { getStoreHandle } from "../common/getS3Handle"; describe("Test loading the configuration", () => { test("it should be able to load the default configuration for the environment", async () => { diff --git a/api/src/routes/collection.spec.js b/api/src/routes/collection.spec.js index 13458bf1..6918a94f 100644 --- a/api/src/routes/collection.spec.js +++ b/api/src/routes/collection.spec.js @@ -3,7 +3,8 @@ import { deleteCollection, createCollection } from "../lib/collection"; import { createSession } from "../lib/session"; const chance = require("chance").Chance(); import fetch from "node-fetch"; -import { getStoreHandle, TestSetup, headers, host } from "../common"; +import { TestSetup, headers, host } from "../common/test-utils.js"; +import { getStoreHandle } from "../common/getS3Handle"; import models from "../models"; describe("Collection management route tests", () => { diff --git a/api/src/routes/data/data.spec.js b/api/src/routes/data/data.spec.js index e782d293..233281da 100644 --- a/api/src/routes/data/data.spec.js +++ b/api/src/routes/data/data.spec.js @@ -1,5 +1,5 @@ import "regenerator-runtime"; -import { loadConfiguration } from "../../common"; +import { loadConfiguration } from "../../common/configuration.js"; import { groupFilesByResource } from "../../lib/item"; describe("Test data processing functions", () => { diff --git a/api/src/routes/item.spec.js b/api/src/routes/item.spec.js index 496c108c..d78d234d 100644 --- a/api/src/routes/item.spec.js +++ b/api/src/routes/item.spec.js @@ -3,14 +3,9 @@ import { deleteItem, createItem, updateResourceStatus } from "../lib/item"; import { createSession } from "../lib/session"; const chance = require("chance").Chance(); import fetch from "node-fetch"; -import { - getStoreHandle, - TestSetup, - setupTestItem, - headers, - host, - resourceStatusFile, -} from "../common"; +import { TestSetup, setupTestItem, headers, host } from "../common/test-utils.js"; +import { resourceStatusFile } from "../common/index.js"; +import { getStoreHandle } from "../common/getS3Handle"; import models from "../models"; describe("Item management route tests", () => { diff --git a/api/src/routes/logs.spec.js b/api/src/routes/logs.spec.js index 448a3872..76b1e1c4 100644 --- a/api/src/routes/logs.spec.js +++ b/api/src/routes/logs.spec.js @@ -3,7 +3,7 @@ import models from "../models"; import { createUser } from "../lib/user"; import { createSession } from "../lib/session"; import fetch from "node-fetch"; -import { TestSetup, headers, generateLogs, host } from "../common"; +import { TestSetup, headers, generateLogs, host } from "../common/test-utils.js"; const chance = require("chance").Chance(); describe("Log management tests", () => { diff --git a/api/src/routes/publish.spec.js b/api/src/routes/publish.spec.js index c1483fc6..916107b5 100644 --- a/api/src/routes/publish.spec.js +++ b/api/src/routes/publish.spec.js @@ -4,13 +4,13 @@ import Chance from "chance"; const chance = Chance(); import fetch from "cross-fetch"; import { - getStoreHandle, TestSetup, headers, host, setupTestItem, setupTestCollection, -} from "../common/index.js"; +} from "../common/test-utils.js"; +import { getStoreHandle } from "../common/getS3Handle.js"; import models from "../models/index.js"; import { ROCrate } from "ro-crate"; diff --git a/api/src/routes/repository.spec.js b/api/src/routes/repository.spec.js index 65314da8..d0109d38 100644 --- a/api/src/routes/repository.spec.js +++ b/api/src/routes/repository.spec.js @@ -3,16 +3,9 @@ import { createSession } from "../lib/session.js"; import Chance from "chance"; const chance = Chance(); import fetch from "cross-fetch"; -import { - loadConfiguration, - getStoreHandle, - TestSetup, - headers, - host, - setupTestItem, - setupTestCollection, - getS3Handle, -} from "../common/index.js"; +import { TestSetup, headers, host, setupTestItem } from "../common/test-utils.js"; +import { getStoreHandle, getS3Handle } from "../common/getS3Handle.js"; +import { loadConfiguration } from "../common/configuration.js"; import models from "../models/index.js"; import { importRepositoryContentFromStorageIntoTheDb } from "../lib/repository.js"; import { publishObject } from "../lib/admin.js"; @@ -78,13 +71,11 @@ describe("Repository route tests", () => { node: configuration.api.services.elastic.host, }); let document = await client.get({ - index: "metadata", + index: "manuscripts", id: `/item/${item.identifier}`, }); expect(document._source).toMatchObject({ - "@id": "./", - "@type": ["Dataset"], - name: ["My Research Object Crate"], + name: "My Research Object Crate", }); await models.repoitem.destroy({ where: { identifier } }); @@ -119,13 +110,11 @@ describe("Repository route tests", () => { node: configuration.api.services.elastic.host, }); let document = await client.get({ - index: "metadata", + index: "manuscripts", id: `/item/${identifier}`, }); expect(document._source).toMatchObject({ - "@id": "./", - "@type": ["Dataset"], - name: ["My Research Object Crate"], + name: "My Research Object Crate", }); await models.repoitem.destroy({ where: { identifier } }); diff --git a/api/src/routes/user.spec.js b/api/src/routes/user.spec.js index 8ce0e9a7..08b23d97 100644 --- a/api/src/routes/user.spec.js +++ b/api/src/routes/user.spec.js @@ -4,7 +4,7 @@ import models from "../models"; const chance = require("chance").Chance(); import fetch from "node-fetch"; import { createSession } from "../lib/session"; -import { TestSetup, headers, host } from "../common"; +import { TestSetup, headers, host } from "../common/test-utils.js"; describe("User management route tests as admin", () => { let users, userEmail, adminEmail; @@ -48,7 +48,15 @@ describe("User management route tests as admin", () => { let response = await fetch(`${host}/admin/users`, { method: "POST", headers: headers(session), - body: JSON.stringify({ emails: [email] }), + body: JSON.stringify({ + accounts: [ + { + email: chance.email(), + givenName: chance.word(), + familyName: chance.word, + }, + ], + }), }); expect(response.status).toEqual(200);