From ab014c10a34992a30444feaf1c6326d6b09ff359 Mon Sep 17 00:00:00 2001 From: Kegan Myers Date: Wed, 15 Apr 2020 00:45:18 -0500 Subject: [PATCH] add integration testing script --- integration.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 integration.js diff --git a/integration.js b/integration.js new file mode 100644 index 0000000..1dc8cfd --- /dev/null +++ b/integration.js @@ -0,0 +1,43 @@ +const assert = require('assert'); +const fetch = require('node-fetch'); + +const infoHash = '(m.%5bO%83i%85S(3j%c1%26%3a%e0*z%60%d5'; +(async () => { + if (!process.env.ENDPOINT) { + throw new Error('Endpoint must be defined.'); + } + console.log(`testing ${process.env.ENDPOINT} with infoHash '${infoHash}'`); + + const res = await fetch( + `${process.env.ENDPOINT}/fetch?info_hash=${infoHash}&json=1`, + ); + assert.deepEqual(res.status, 200, 'expected response to be ok'); + + const data = await res.json(); + assert.deepEqual( + typeof data, + 'object', + 'expected response to be an array (is not an object)', + ); + assert.ok( + data instanceof Array, + 'expected response to be an array (is not an object)', + ); + assert.ok(data.length > 0, 'expected popular torrent to have peers'); + data.forEach((peer) => { + assert.deepEqual( + typeof peer, + 'string', + 'expected every response entry to be a string', + ); + assert.match( + peer, + /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5}/, + 'expected every response entry to resemble ip:port', + ); + }); +})().catch((e) => { + console.log(e); + process.exit(1); +}); +