diff --git a/packages/api/test/pin.spec.js b/packages/api/test/pin.spec.js index 6790bcea90..58da1070a3 100644 --- a/packages/api/test/pin.spec.js +++ b/packages/api/test/pin.spec.js @@ -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 () => {