Skip to content

Commit ad7073b

Browse files
committed
fix: Swapped object and target/origin in Notifications
Swapped the `object` and `target`/`origin` properties in case of `Add`/`Delete` notifications respectively.
1 parent fef1ea2 commit ad7073b

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

lib/handlers/notify.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ function handler (req, res, next) {
7575
) {
7676
const mediaType = negotiatedFields['content-type']
7777
const activity = getActivity(method, path)
78-
const target = activity === 'Add'
78+
const object = activity === 'Add'
7979
? res.getHeader('location')
80+
: String(fullUrl)
81+
const target = activity === 'Add'
82+
? String(fullUrl)
8083
: undefined
8184
if (ALLOWED_RDF_MIME_TYPES.includes(mediaType?.[0])) {
8285
return `${headerTemplate(negotiatedFields)}\r\n${solidRDFTemplate({
8386
activity,
8487
eventID,
85-
object: String(fullUrl),
88+
object,
8689
target,
8790
date: eventDate,
8891
// We use eTag as a proxy for state for now
@@ -117,13 +120,14 @@ function handler (req, res, next) {
117120
) {
118121
const mediaType = negotiatedFields['content-type']
119122
const activity = getParentActivity(method, statusCode)
120-
const target = activity !== 'Update' ? String(fullUrl) : undefined
123+
const object = activity === 'Update' ? String(parentUrl) : String(fullUrl)
124+
const target = activity === 'Update' ? undefined : String(parentUrl)
121125
if (ALLOWED_RDF_MIME_TYPES.includes(mediaType?.[0])) {
122126
return `${headerTemplate(negotiatedFields)}\r\n${solidRDFTemplate({
123127
activity,
124128
eventID: parentID,
125129
date: eventDate,
126-
object: String(parentUrl),
130+
object,
127131
target,
128132
eTag: undefined,
129133
mediaType

test/integration/prep-test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ describe('Per Resource Events Protocol', function () {
9797
expect(notification.published).to.match(dateTimeRegex)
9898
expect(isNaN((new Date(notification.published)).valueOf())).to.equal(false)
9999
expect(notification.type).to.equal('Add')
100-
expect(notification.target).to.match(/sampleContainer\/example-prep\.ttl$/)
101-
expect(notification.object).to.match(/sampleContainer\/$/)
100+
expect(notification.target).to.match(/sampleContainer\/$/)
101+
expect(notification.object).to.match(/sampleContainer\/example-prep\.ttl$/)
102102
})
103103

104104
it('when contained resource is modified', async function () {
@@ -131,8 +131,8 @@ solid:inserts { <u> <v> <z>. }.`
131131
expect(notification.published).to.match(dateTimeRegex)
132132
expect(isNaN((new Date(notification.published)).valueOf())).to.equal(false)
133133
expect(notification.type).to.equal('Remove')
134-
expect(notification.object).to.match(/sampleContainer\/$/)
135-
expect(notification.origin).to.match(/sampleContainer\/.*example-prep.ttl$/)
134+
expect(notification.origin).to.match(/sampleContainer\/$/)
135+
expect(notification.object).to.match(/sampleContainer\/.*example-prep.ttl$/)
136136
})
137137

138138
it('when a contained container is created', async function () {
@@ -148,8 +148,8 @@ solid:inserts { <u> <v> <z>. }.`
148148
expect(notification.published).to.match(dateTimeRegex)
149149
expect(isNaN((new Date(notification.published)).valueOf())).to.equal(false)
150150
expect(notification.type).to.equal('Add')
151-
expect(notification.target).to.match(/sampleContainer\/example-prep\/$/)
152-
expect(notification.object).to.match(/sampleContainer\/$/)
151+
expect(notification.target).to.match(/sampleContainer\/$/)
152+
expect(notification.object).to.match(/sampleContainer\/example-prep\/$/)
153153
})
154154

155155
it('when a contained container is deleted', async function () {
@@ -162,8 +162,8 @@ solid:inserts { <u> <v> <z>. }.`
162162
expect(notification.published).to.match(dateTimeRegex)
163163
expect(isNaN((new Date(notification.published)).valueOf())).to.equal(false)
164164
expect(notification.type).to.equal('Remove')
165-
expect(notification.origin).to.match(/sampleContainer\/example-prep\/$/)
166-
expect(notification.object).to.match(/sampleContainer\/$/)
165+
expect(notification.origin).to.match(/sampleContainer\/$/)
166+
expect(notification.object).to.match(/sampleContainer\/example-prep\/$/)
167167
})
168168

169169
it('when a container is created by POST',
@@ -182,8 +182,8 @@ solid:inserts { <u> <v> <z>. }.`
182182
expect(notification.published).to.match(dateTimeRegex)
183183
expect(isNaN((new Date(notification.published)).valueOf())).to.equal(false)
184184
expect(notification.type).to.equal('Add')
185-
expect(notification.object).to.match(/sampleContainer\/$/)
186-
expect(notification.target).to.match(/sampleContainer\/.*example-post\/$/)
185+
expect(notification.target).to.match(/sampleContainer\/$/)
186+
expect(notification.object).to.match(/sampleContainer\/.*example-post\/$/)
187187
})
188188

189189
it('when resource is created by POST',
@@ -202,8 +202,8 @@ solid:inserts { <u> <v> <z>. }.`
202202
expect(notification.published).to.match(dateTimeRegex)
203203
expect(isNaN((new Date(notification.published)).valueOf())).to.equal(false)
204204
expect(notification.type).to.equal('Add')
205-
expect(notification.object).to.match(/sampleContainer\/$/)
206-
expect(notification.target).to.match(/sampleContainer\/.*example-prep.ttl$/)
205+
expect(notification.target).to.match(/sampleContainer\/$/)
206+
expect(notification.object).to.match(/sampleContainer\/.*example-prep.ttl$/)
207207
controller.abort()
208208
})
209209
})

0 commit comments

Comments
 (0)