Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing target resource id in transfer message. #286

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions __tests__/endpoints/transferPost.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,30 @@ describe("POST /transfer/:resourceId/:targetGroup/:targetSystem", () => {
*/
})
})

describe("POST /transfer/:resourceId/:targetGroup/:targetSystem/:targetResourceId", () => {
describe("user is in target group", () => {
it("returns a 204 after queueing an SQS message with the expected params", async () => {
aws.buildAndSendSqsMessage.mockResolvedValue()
const res = await request(app)
.post("/transfer/foo/stanford/ils/abc123")
.set("Authorization", `Bearer ${stanfordJwt}`)
.send("")

const msgBodyJson = {
resource: { uri: "https://api.development.sinopia.io/resource/foo" },
user: {
email: "[email protected]",
},
group: "stanford",
target: "ils",
targetResourceId: "abc123",
}
expect(res.statusCode).toEqual(204)
expect(aws.buildAndSendSqsMessage).toHaveBeenCalledWith(
"stanford-ils",
expect.stringMatching(JSON.stringify(msgBodyJson))
)
})
})
})
39 changes: 39 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,45 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Groups"
/transfer/{resourceId}/{targetGroup}/{targetSystem}/{targetResourceId}:
post:
summary: publish a Sinopia resource to the target group's target system (e.g. stanford's ILS) using the provided target resource id
responses:
"204":
description: "OK - a message was queued for the transfer request"
"401":
description: Unauthorized
content:
application/json:
schema:
$ref: "#/components/schemas/Errors"
parameters:
- name: resourceId
in: path
description: ID of the resource
required: true
schema:
type: string
- name: targetGroup
in: path
description: name of the group to which the resource should go
required: true
schema:
type: string
- name: targetSystem
in: path
description: system to which the resource should go
example: "ils"
required: true
schema:
type: string
- name: targetResourceId
in: path
description: identifier for the resource in the target system
example: "13714202"
required: true
schema:
type: string
/transfer/{resourceId}/{targetGroup}/{targetSystem}:
post:
summary: publish a Sinopia resource to the target group's target system (e.g. stanford's ILS)
Expand Down
54 changes: 31 additions & 23 deletions src/endpoints/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@ import { resourceUriFor } from "./resourcesHelpers.js"

const transferRouter = express.Router()

transferRouter.post("/:resourceId/:targetGroup/:targetSystem", [
canTransfer,
(req, res, next) => {
const { resourceId, targetGroup, targetSystem } = req.params
console.log(
`transferRouter Received post to /${resourceId}/${targetGroup}/${targetSystem}`
)
transferRouter.post(
[
"/:resourceId/:targetGroup/:targetSystem/:targetResourceId",
"/:resourceId/:targetGroup/:targetSystem",
],
[
canTransfer,
(req, res, next) => {
const { resourceId, targetGroup, targetSystem, targetResourceId } =
req.params
console.log(
`transferRouter Received post to /${resourceId}/${targetGroup}/${targetSystem}`
)

const sqsMessageBody = {
resource: { uri: resourceUriFor(req) },
user: {
email: req.user.email,
},
group: targetGroup,
target: targetSystem,
}
const sqsMessageBody = {
resource: { uri: resourceUriFor(req) },
user: {
email: req.user.email,
},
group: targetGroup,
target: targetSystem,
targetResourceId,
}

const queueName = `${targetGroup}-${targetSystem}`
buildAndSendSqsMessage(queueName, JSON.stringify(sqsMessageBody))
.then(() => {
res.sendStatus(204)
})
.catch(next)
},
])
const queueName = `${targetGroup}-${targetSystem}`
buildAndSendSqsMessage(queueName, JSON.stringify(sqsMessageBody))
.then(() => {
res.sendStatus(204)
})
.catch(next)
},
]
)

export default transferRouter