Skip to content

Commit

Permalink
Merge pull request #18 from zazuko/close-empty
Browse files Browse the repository at this point in the history
fix: close writable if no quads have been written
  • Loading branch information
bergos authored Oct 6, 2021
2 parents 05bb845 + c49bea0 commit 60850b8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/graph-store/lib/SinkToWritable.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class SinkToWritable extends Writable {
callback()
},
final: async callback => {
init()

readable.push(null)

try {
Expand Down
23 changes: 22 additions & 1 deletion packages/graph-store/test/post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('post', () => {
})
})

it('should send a GET request', async () => {
it('should send a POST request', async () => {
await withServer(async server => {
let called = false
const quad = rdf.quad(ns.subject1, ns.predicate1, ns.object1, ns.graph1)
Expand All @@ -49,6 +49,27 @@ describe('post', () => {
})
})

it('should do nothing if the stream was closed and no quads have been written', async () => {
await withServer(async server => {
let called = false

server.app.post('/', async (req, res) => {
called = true

res.status(204).end()
})

const baseUrl = await server.listen()
const stream = post({ endpoint: baseUrl })

stream.end()

await promisify(finished)(stream)

strictEqual(called, false)
})
})

it('should send a content-type header with the value application/n-triples', async () => {
await withServer(async server => {
let mediaType = null
Expand Down
23 changes: 22 additions & 1 deletion packages/graph-store/test/put.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('put', () => {
})
})

it('should send a GET request', async () => {
it('should send a PUT request', async () => {
await withServer(async server => {
let called = false
const quad = rdf.quad(ns.subject1, ns.predicate1, ns.object1, ns.graph1)
Expand All @@ -49,6 +49,27 @@ describe('put', () => {
})
})

it('should do nothing if the stream was closed and no quads have been written', async () => {
await withServer(async server => {
let called = false

server.app.put('/', async (req, res) => {
called = true

res.status(204).end()
})

const baseUrl = await server.listen()
const stream = put({ endpoint: baseUrl })

stream.end()

await promisify(finished)(stream)

strictEqual(called, false)
})
})

it('should send a content-type header with the value application/n-triples', async () => {
await withServer(async server => {
let mediaType = null
Expand Down

0 comments on commit 60850b8

Please sign in to comment.