Skip to content

Commit

Permalink
Support local IDs for overlay of MARC records.
Browse files Browse the repository at this point in the history
refs #3555
  • Loading branch information
justinlittman committed Sep 19, 2022
1 parent e38de3d commit b9139ab
Show file tree
Hide file tree
Showing 27 changed files with 590 additions and 50 deletions.
55 changes: 55 additions & 0 deletions __tests__/__resource_fixtures__/local_admin_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"@id": "http://localhost:3000/resource/ae93cff4-d272-43b2-a4ee-fb8651907e51",
"@type": [
"http://sinopia.io/vocabulary/LocalAdminMetadata"
],
"http://id.loc.gov/ontologies/bibframe/identifier": [
{
"@id": "_:Nfe4b29df32004cc1b097a218f69df09f"
}
],
"http://sinopia.io/vocabulary/exportDate": [
{
"@value": "2022-08-01T15:49:44.558203"
}
],
"http://sinopia.io/vocabulary/hasResourceTemplate": [
{
"@value": "pcc:sinopia:localAdminMetadata"
}
],
"http://sinopia.io/vocabulary/localAdminMetadataFor": [
{
"@id": "http://localhost:3000/resource/a5c5f4c0-e7cd-4ca5-a20f-2a37fe1080d5"
}
]
},
{
"@id": "_:Nfe4b29df32004cc1b097a218f69df09f",
"@type": [
"http://id.loc.gov/ontologies/bibframe/Local"
],
"http://id.loc.gov/ontologies/bibframe/source": [
{
"@id": "_:Nf65f353d6fb64adeb6aa6040d21fb88c"
}
],
"http://www.w3.org/1999/02/22-rdf-syntax-ns#value": [
{
"@value": "13714202"
}
]
},
{
"@id": "_:Nf65f353d6fb64adeb6aa6040d21fb88c",
"@type": [
"http://id.loc.gov/ontologies/bibframe/Source"
],
"http://www.w3.org/2000/01/rdf-schema#label": [
{
"@value": "SIRSI"
}
]
}
]
1 change: 1 addition & 0 deletions __tests__/actionCreators/relationships.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe("loadRelationships()", () => {
bfAdminMetadataRefs: [
"http://localhost:3000/resource/72f2f457-31f5-432c-8acf-b4037f7754g",
],
sinopiaLocalAdminMetadataRefs: [],
bfItemRefs: [],
bfInstanceRefs: [],
bfWorkRefs: [
Expand Down
21 changes: 13 additions & 8 deletions __tests__/actionCreators/resources.loadResource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe("loadResource", () => {
sinopiaSearch.getSearchResultsByUris = jest
.fn()
.mockResolvedValue({ results: [] })
jest.spyOn(relationshipActionCreators, "loadRelationships")

it("dispatches actions", async () => {
const result = await store.dispatch(
Expand Down Expand Up @@ -75,20 +74,26 @@ describe("loadResource", () => {
group: "stanford",
modified: "2020-08-20T11:34:40.887Z",
})
expect(actions).toHaveAction("SET_RELATIONSHIPS", {
resourceKey: "abc123",
relationships: {
bfAdminMetadataRefs: [],
sinopiaLocalAdminMetadataRefs: [
"http://localhost:3000/resource/ae93cff4-d272-43b2-a4ee-fb8651907e51",
],
bfItemRefs: [],
bfInstanceRefs: [],
bfWorkRefs: [],
},
})
expect(actions).toHaveAction("CLEAR_LOCAL_IDS", "abc123")

expect(sinopiaApi.putUserHistory).toHaveBeenCalledWith(
"Foo McBar",
"resource",
"87d27b05d48874c9f80cd4b7e8fc0dcc",
uri
)

// loadRelationships is invoked async and do not wait for results
expect(relationshipActionCreators.loadRelationships).toHaveBeenCalledWith(
"abc123",
uri,
"testerrorkey"
)
})
})

Expand Down
41 changes: 36 additions & 5 deletions __tests__/actionCreators/transfer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,42 @@ import configureMockStore from "redux-mock-store"
import thunk from "redux-thunk"
import * as sinopiaApi from "sinopiaApi"
import { createState } from "stateUtils"
import { transfer } from "actionCreators/transfer"
import { transfer, loadLocalIds } from "actionCreators/transfer"
import Config from "Config"

const mockStore = configureMockStore([thunk])

const resourceUri =
"https://api.development.sinopia.io/resource/7b4c275d-b0c7-40a4-80b3-e95a0d9d987c"

// This forces Sinopia server to use fixtures
jest.spyOn(Config, "useResourceTemplateFixtures", "get").mockReturnValue(true)

describe("transfer", () => {
describe("successful", () => {
it("dispatches actions to add user", async () => {
sinopiaApi.postTransfer = jest.fn().mockResolvedValue()
const store = mockStore(createState())
await store.dispatch(
transfer(resourceUri, "stanford", "ils", "testerrorkey")
transfer(resourceUri, "stanford", "FOLIO", "abc123", "testerrorkey")
)

expect(store.getActions()).toHaveLength(0)
expect(sinopiaApi.postTransfer).toHaveBeenCalledWith(
resourceUri,
"stanford",
"ils"
"FOLIO",
"abc123"
)
})
})
describe("failure", () => {

describe("transfer failure", () => {
it("dispatches actions to remove user", async () => {
sinopiaApi.postTransfer = jest.fn().mockRejectedValue("Ooops!")
const store = mockStore(createState())
await store.dispatch(
transfer(resourceUri, "stanford", "ils", "testerrorkey")
transfer(resourceUri, "stanford", "", "abc123", "testerrorkey")
)

expect(store.getActions()).toHaveAction("ADD_ERROR", {
Expand All @@ -41,4 +47,29 @@ describe("transfer", () => {
})
})
})

describe("loadLocalIds()", () => {
it("dispatches actions to set local id", async () => {
const store = mockStore(createState())
await store.dispatch(
loadLocalIds(
"abc123",
[
"http://localhost:3000/resource/ae93cff4-d272-43b2-a4ee-fb8651907e51",
],
"testerrorkey"
)
)

const actions = store.getActions()

expect(actions).toHaveAction("CLEAR_LOCAL_IDS", "abc123")
expect(actions).toHaveAction("SET_LOCAL_ID", {
resourceKey: "abc123",
target: "SIRSI",
group: "stanford",
localId: "13714202",
})
})
})
})
33 changes: 32 additions & 1 deletion __tests__/feature/editing/transfer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jest.spyOn(Config, "transferConfig", "get").mockReturnValue({
},
})

describe("transfer saved bf:Instance when user belongs to a transfer group", () => {
describe("transfer saved bf:Instance when user belongs to a transfer group and no local ID", () => {
it("allows transfer", async () => {
const state = createState()
const store = createStore(state)
Expand All @@ -42,6 +42,37 @@ describe("transfer saved bf:Instance when user belongs to a transfer group", ()

const transferBtn = screen.getByText("Export to Catalog")
fireEvent.click(transferBtn)
fireEvent.click(await screen.findByText("Create a new record in catalog."))
await screen.findByText("Requesting")
}, 15000)
})

describe("transfer saved bf:Instance when user belongs to a transfer group and provided local ID", () => {
it("allows transfer", async () => {
const state = createState()
const store = createStore(state)
renderApp(store)

fireEvent.click(screen.getByText("Linked Data Editor", { selector: "a" }))

fireEvent.change(screen.getByLabelText("Search"), {
target: { value: bfUri },
})
fireEvent.click(screen.getByTestId("Submit search"))

await screen.findByText(bfUri)
fireEvent.click(screen.getByRole("button", { name: `Edit ${bfUri}` }))

await screen.findByText("The Practitioner's Guide to Graph Data", {
selector: resourceHeaderSelector,
})

const transferBtn = screen.getByText("Export to Catalog")
fireEvent.click(transferBtn)
fireEvent.change(await screen.findByLabelText("Enter local system id"), {
target: { value: "abc123" },
})
fireEvent.click(await screen.findByText("Go"))
await screen.findByText("Requesting")
}, 15000)
})
Expand Down
2 changes: 2 additions & 0 deletions __tests__/feature/editing/viewRelationships.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe("relationships", () => {
],
bfInstanceInferredRefs: [],
bfWorkInferredRefs: [],
sinopiaHasLocalAdminMetadataInferredRefs: [],
})

jest.spyOn(sinopiaSearch, "getSearchResultsByUris").mockResolvedValue({
Expand Down Expand Up @@ -75,6 +76,7 @@ describe("relationships", () => {
bfItemInferredRefs: [],
bfInstanceInferredRefs: [],
bfWorkInferredRefs: [],
sinopiaHasLocalAdminMetadataInferredRefs: [],
})
})

Expand Down
3 changes: 2 additions & 1 deletion __tests__/feature/searchAndPreviewResource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ describe("searching and preview a resource", () => {
).toHaveLength(1)

screen.getByText("MARC", { selector: "button" })
screen.getByText(/Export to/, { selector: "button" })
screen.getByText("Export to Symphony", { selector: "button" })
screen.getByText("Export to Folio", { selector: "button" })

// Switch to relationships
fireEvent.change(screen.getByLabelText(/Format/), {
Expand Down
6 changes: 6 additions & 0 deletions __tests__/reducers/resources.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,11 @@ describe("clearResource()", () => {
bfInstanceRefs: [],
bfWorkRefs: [],
}
oldState.entities.localIds.t9zVwg2zO = {
FOLIO: {
stanford: "123456",
},
}

const action = {
type: "CLEAR_RESOURCE",
Expand All @@ -952,6 +957,7 @@ describe("clearResource()", () => {
expect(Object.keys(newState.values)).toHaveLength(0)
expect(Object.keys(newState.versions)).toHaveLength(0)
expect(Object.keys(newState.relationships)).toHaveLength(0)
expect(Object.keys(newState.localIds)).toHaveLength(0)
})
})

Expand Down
109 changes: 109 additions & 0 deletions __tests__/reducers/transfer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { clearLocalIds, setLocalId } from "reducers/transfer"
import { createReducer } from "reducers/index"

const handlers = {
CLEAR_LOCAL_IDS: clearLocalIds,
SET_LOCAL_ID: setLocalId,
}
const reducer = createReducer(handlers)

describe("clearLocalIds", () => {
it("removes local ids for resource", () => {
const oldState = {
localIds: {
abc123: {
FOLIO: {
stanford: "123456",
},
},
def456: {
FOLIO: {
stanford: "234567",
},
},
},
}
const action = {
type: "CLEAR_LOCAL_IDS",
payload: "abc123",
}

const newState = reducer(oldState, action)
expect(newState).toStrictEqual({
localIds: {
def456: {
FOLIO: {
stanford: "234567",
},
},
},
})
})
})

describe("setLocalId", () => {
describe("when resource does not have existing local ids", () => {
it("adds local ids for resource", () => {
const oldState = {
localIds: {},
}
const action = {
type: "SET_LOCAL_ID",
payload: {
resourceKey: "abc123",
target: "FOLIO",
group: "stanford",
localId: "123456",
},
}

const newState = reducer(oldState, action)
expect(newState).toStrictEqual({
localIds: {
abc123: {
FOLIO: {
stanford: "123456",
},
},
},
})
})
})

describe("when resource has existing local ids", () => {
it("appends local ids for resource", () => {
const oldState = {
localIds: {
abc123: {
SYMPHONY: {
stanford: "234567",
},
},
},
}
const action = {
type: "SET_LOCAL_ID",
payload: {
resourceKey: "abc123",
target: "FOLIO",
group: "stanford",
localId: "123456",
},
}

const newState = reducer(oldState, action)
expect(newState).toStrictEqual({
localIds: {
abc123: {
SYMPHONY: {
stanford: "234567",
},
FOLIO: {
stanford: "123456",
},
},
},
})
})
})
})
Loading

0 comments on commit b9139ab

Please sign in to comment.