Skip to content

Commit

Permalink
fix: default PSA pin status filter (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw authored May 24, 2022
1 parent 318ad50 commit 235a308
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/api/src/routes/pins-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ function parseSearchParams(params) {
out.status = /** @type {ListUploadsOptions["status"]}*/ (
statusParam.split(',').map(toDbPinStatus)
)
} else {
// "when no filter is provided, only successful pins are returned"
// https://ipfs.github.io/pinning-services-api-spec/#tag/pins/paths/~1pins/get
out.status = ['Pinned']
}

const afterParam = params.get('after')
Expand Down
26 changes: 24 additions & 2 deletions packages/api/test/pin-list.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import assert from 'assert'
import { createClientWithUser, DBTestClient } from './scripts/helpers.js'
import {
createClientWithUser,
DBTestClient,
rawClient,
} from './scripts/helpers.js'

describe('Pin list ', () => {
/** @type{DBTestClient} */
let client

before(async () => {
beforeEach(async () => {
client = await createClientWithUser()
})

Expand Down Expand Up @@ -70,4 +74,22 @@ describe('Pin list ', () => {
'Server response with pin requests created'
)
})

it('should list pinned items when querying without filters', async () => {
// Pin request (unavailable on IPFS)
const cid = 'bafkreiaoqabl7yiracpil3m7rgbgygky2wwqtvzom2lkdhy2pxchkjixae'
await client.addPin({ cid, name: 'test' })

// Make this CID 'Pinned' in our DB
await rawClient
.from('pin')
.update({ status: 'Pinned', updated_at: new Date().toISOString() })
.eq('content_cid', cid)

const headers = { Authorization: `Bearer ${client.token}` }
const res = await fetch('pins', { headers })
const { count, results } = await res.json()
assert.strictEqual(count, 1)
assert.strictEqual(results[0].pin.cid, cid)
})
})

0 comments on commit 235a308

Please sign in to comment.