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

fix: include meta for replace pin #935

Merged
merged 4 commits into from
Feb 2, 2022
Merged
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
38 changes: 26 additions & 12 deletions packages/api/test/pin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -863,35 +863,49 @@ describe('Pinning APIs endpoints', () => {
})

it('should delete the pin request and replace it', async () => {
// Create a pin request.
const cid = 'bafybeid3ka3b3f443kv2je3mfm4byk6qps3wipr7wzu5uli6tdo57crcke'
const newCid = 'bafybeid4f2r3zpnkjqrglkng265ttqg6zbdr75dpbiwellvlpcxq7pggjy'

// Creates pin Requests
const pinRequest = await createPinRequest(cid, token)

// It replaces it
const resR = await fetch(new URL(`pins/${pinRequest.requestId}`, endpoint).toString(), {
// Replace this pin request, and include extra data.
const newCid = 'bafybeid4f2r3zpnkjqrglkng265ttqg6zbdr75dpbiwellvlpcxq7pggjy'
const name = 'Replaced.pdf'
const origins = [
'/ip4/77.100.8.43/tcp/28253/p2p/12D3KooWGYUY2TCpPZsiaJfqs7V74mbSTgx4xNtBkRzkSGQjdaLp',
'/ip4/77.100.8.43/udp/28253/quic/p2p/12D3KooWGYUY2TCpPZsiaJfqs7V74mbSTgx4xNtBkRzkSGQjdaLp'
]
const meta = { app_id: '99986338-1113-4706-8302-4420da6158aa' }

const replaceResponse = await fetch(new URL(`pins/${pinRequest.requestId}`, endpoint).toString(), {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`
},
body: JSON.stringify({
cid: newCid
cid: newCid,
name,
origins,
meta
})
})

assert(resR, 'Replace request did not respond')
assert(resR.ok, 'Replace request was not successful')
assert(replaceResponse, 'Replace request did not respond')
assert(replaceResponse.ok, 'Replace request was not successful')
const data = await replaceResponse.json()
assert.strictEqual(data.pin.cid, newCid)
assert.deepStrictEqual(data.pin.name, name)
assert.deepStrictEqual(data.pin.origins, origins)
assert.deepStrictEqual(data.pin.meta, meta)

const resG = await fetch(new URL(`pins/${pinRequest.requestId}`, endpoint).toString(), {
// Ensure the original pin request has been deleted.
const getResponse = await fetch(new URL(`pins/${pinRequest.requestId}`, endpoint).toString(), {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`
}
})

assert(resG, 'Get request did not respond')
assert.strictEqual(resG.status, 404, 'Pin request was not deleted')
assert(getResponse, 'Get request did not respond')
assert.strictEqual(getResponse.status, 404, 'Pin request was not deleted')
})

it('should not replace the same pin request', async () => {
Expand Down