getConfirmation(peer, transactionId) { // Get if the transaction has been confirmed in that peer const URL = `${peer.url}/blockchain/blocks/transactions/${transactionId}`; console.info(`Getting transactions from: ${URL}`); return superagent .get(URL) .then(() => { return true; }) .catch(() => { return false; }); }
getBlocks(peer) { const URL = `${peer.url}/blockchain/blocks`; let self = this; console.info(`Getting blocks from: ${URL}`); return superagent .get(URL) .then((res) => { // Check for what to do with the block list self.checkReceivedBlocks(Blocks.fromJson(res.body)); }) .catch((err) => { console.warn(`Unable to get blocks from ${URL}: ${err.message}`); }); }
it('strategy: should response from second file', function (done) { chai.request("http://localhost:9999") .get('/stubs/not-found') .then(res => { expect(res.status).toBe(200); expect(res.text).toBe("<root>Sample File contents</root>"); done(); }).catch( err => { markFailed(err,fail,done); }); });
request .delete(`${endpoint}`) .set(headers) .send() .then(res => { const { body: { data } } = res; return data; })
SA(sites[parts[0]].baseURL) .query({ q: parts.slice(1).join('+') }) .set({ 'User-Agent': `github.com/TheSharks/WildBeast@${require('../../../package.json').version}` }) .then(res => { if (!res.body.search || res.body.search.length < 1) { return this.safeSendMessage(msg.channel, `No results found for \`${query}\``) } const count = Math.floor((Math.random() * res.body.search.length)) return this.safeSendMessage(msg.channel, generateEmbed(`https:${res.body.search[count].representations.tall}`)) // why })
request.get('https://api.icndb.com/jokes/random') .query({ escape: 'javascript' }) .then(res => { if (res.statusCode !== 200) return this.safeSendMessage(msg.channel, 'Something went wrong!') return this.safeSendMessage(msg.channel, res.body.value.joke) })
getTransactions(peer) { const URL = `${peer.url}/blockchain/transactions`; let self = this; console.info(`Getting transactions from: ${URL}`); return superagent .get(URL) .then((res) => { self.syncTransactions(Transactions.fromJson(res.body)); }) .catch((err) => { console.warn(`Unable to get transations from ${URL}: ${err.message}`); }); }
it('/api/v2/suggestions POST for facts should fail if fact is not a string', done => { let suggestion = { fact: { fact: 100101, source: 'https://google.com' } }; chai.request(app).post('/api/v2/suggestions').send(suggestion).then(res => { expect(res.body).to.have.property('error'); done(); }).catch(err => done(err)); });
it('should response with fix delay', function (done) { var time = new Date(); chai.request("http://localhost:9999") .get('/stubs/delay') .then(res => { expect(res.status).toBe(200); expect((new Date()) - time).toBeGreaterThan(1999); done(); }).catch( err => { done.fail(err.message); }); });
it('should respond with 500 when unsupported strategy given', function (done) { chai.request("http://localhost:9999") .get('/stubs/unsupported-strategy') .then(res => { expect(res.status).toBe(500); done(); }).catch( err => { done.fail("not expected"); }); });
//TODO: replace functionality for {{ url.1 }} is implemented it('should response to POST with dynamic body', function (done) { chai.request("http://localhost:9999") .post('/stubs/phone-123456789/body') .then(res => { expect(res.status).toBe(200); expect(res.text).toBe("spacing is optional. 123456789 and 123456789 are valid"); done(); }).catch( err => { done.fail(err.message); }); });
getLatestBlock(peer) { const URL = `${peer.url}/blockchain/blocks/latest`; let self = this; console.info(`Getting latest block from: ${URL}`); return superagent .get(URL) .then((res) => { // Check for what to do with the latest block self.checkReceivedBlock(Block.fromJson(res.body)); }) .catch((err) => { console.warn(`Unable to get latest block from ${URL}: ${err.message}`); }); }
it('should response to GET short notation with response body', function (done) { chai.request("http://localhost:9999") .get('/stubs/healthcheck') .then(res => { expect(res.status).toBe(200); expect(res.text).toBe("OK"); done(); }).catch( err => { done.fail(err.message); }); });
it('/api/v2/suggestions POST for facts should fail if source is not a url', done => { let suggestion = { fact: { fact: 'Tabs >>> spaces', source: 'everywhere' } }; chai.request(app).post('/api/v2/suggestions').send(suggestion).then(res => { expect(res.body).to.have.property('error'); done(); }).catch(err => done(err)); });
it('/api/v2/suggestions POST for activities should fail if missing fields', done => { let suggestion = { activity: { activity: 'Missing other fields' } }; chai.request(app).post('/api/v2/suggestions').send(suggestion).then(res => { expect(res.body).to.have.property('error'); done(); }).catch(err => done(err)); });