Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/v0.2.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-xu committed Apr 12, 2019
2 parents 1b3b978 + 93053b0 commit 8ba8a85
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uport-transports",
"version": "0.2.5",
"version": "0.2.6",
"description": "Set up communication channels between your app and a uPort client to handle requests and responses",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/transport/messageServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { randomString } from './../crypto.js'
import generalPoll from './poll.js'
import { decodeJWT } from 'did-jwt'
import nets from 'nets'
const CHASQUI_URL = 'https://api.uport.space/chasqui/'
const CHASQUI_URL = 'https://api.uport.me/chasqui/'
const POLLING_INTERVAL = 2000

// TODO can the name of URIHandler be changed
Expand Down
70 changes: 36 additions & 34 deletions test/transport/chasqui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
// import * as chasqui from './../../src/transport/messageServer.js'
const sinon = require('sinon')
const proxyquire = require('proxyquire')
var chai = require('chai');
var chai = require('chai')
const expect = chai.expect
chai.use(require('sinon-chai'))
let chasqui = require('./../../src/transport/messageServer.js')
const CHASQUI_URL = 'https://api.uport.space/chasqui/topic/'
const CHASQUI_URL = 'https://api.uport.me/chasqui/topic/'
const ranStr = 'aVKcEd5jznmWslj3'

// TODO stub nets everywhere
// Cleanup imports and redundancy

describe('transport.chasqui', function () {

describe('URIHandlerSend()', function () {
describe('transport.chasqui', function() {
describe('URIHandlerSend()', function() {
it('Requires a uriHandler', () => {
expect(chasqui.URIHandlerSend).to.throw(/required/)
expect(() => chasqui.URIHandlerSend(()=>{})).to.not.throw()
expect(() => chasqui.URIHandlerSend(() => {})).to.not.throw()
})
})

describe('URIHandlerSend() Configured', function () {
describe('URIHandlerSend() Configured', function() {
const uriHandler = sinon.spy()
const pollGeneral = sinon.stub().resolves('ResponseString')
const randomString = sinon.stub().returns(ranStr)
const requestMessage = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1Mjk5NTQxMjcsImV4cCI6MTUyOTk1NDcyNywicmVxdWVzdGVkIjpbIm5hbWUiLCJwaG9uZSIsImNvdW50cnkiXSwicGVybWlzc2lvbnMiOlsibm90aWZpY2F0aW9ucyJdLCJjYWxsYmFjayI6Imh0dHBzOi8vYXBpLnVwb3J0LnNwYWNlL2NoYXNxdWkvdG9waWMvYVZLY0VkNWp6bm1Xc2xqMyIsInR5cGUiOiJzaGFyZVJlcSIsImlzcyI6ImRpZDpldGhyOjB4NDFjOTkxZjczZjBjN2E3Y2M5NWI5ZGY5MDk0NmUxYTdiMDE3NGVlNiJ9.hjkP5-yoAACebORa29-iO_VXCm3_81KwaHzrD3xHI94PbJzaT50x3uSr9MwQSl9sO1Lmdzkg1VMkuHyHFt9ClAE'
const requestMessage =
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1Mjk5NTQxMjcsImV4cCI6MTUyOTk1NDcyNywicmVxdWVzdGVkIjpbIm5hbWUiLCJwaG9uZSIsImNvdW50cnkiXSwicGVybWlzc2lvbnMiOlsibm90aWZpY2F0aW9ucyJdLCJjYWxsYmFjayI6Imh0dHBzOi8vYXBpLnVwb3J0Lm1lL2NoYXNxdWkvdG9waWMvYVZLY0VkNWp6bm1Xc2xqMyIsInR5cGUiOiJzaGFyZVJlcSIsImlzcyI6ImRpZDpldGhyOjB4NDFjOTkxZjczZjBjN2E3Y2M5NWI5ZGY5MDk0NmUxYTdiMDE3NGVlNiJ9.Xe7KOQrMGM8PRwXBWY4_7i8VR79o_dJ7DC2eabzf65HPra2zZ8JyhWLBQgIcN33DmmbZgeyy8b5t8dBVZXpaIQ'
const uri = `https://id.uport.me/req/${requestMessage}`
let URIHandlerSend

before(() => {
chasqui = proxyquire( './../../src/transport/messageServer.js', {
'./poll.js': {default: pollGeneral},
'../crypto.js': { randomString }
chasqui = proxyquire('./../../src/transport/messageServer.js', {
'./poll.js': { default: pollGeneral },
'../crypto.js': { randomString },
})
URIHandlerSend = chasqui.URIHandlerSend(uriHandler)
});
})

it('Uses uPort chasqui as default messaging server', () => {
return URIHandlerSend(requestMessage).then(res => {
Expand All @@ -56,17 +56,17 @@ describe('transport.chasqui', function () {
})
})

describe('poll()', function () {
const res = { message: { access_token: 'token'}}
const resError = { message: {error: 'error'}}
describe('poll()', function() {
const res = { message: { access_token: 'token' } }
const resError = { message: { error: 'error' } }

it('Creates poll arg function to parse message', () => {
const pollGeneral = sinon.stub().callsFake((url, messageParse, errorParse, pollingInterval, cancelled) => {
expect(messageParse(res)).to.equal('token')
return Promise.resolve('ResponseString')
})
chasqui = proxyquire( './../../src/transport/messageServer.js', {
'./poll.js': {default: pollGeneral}
chasqui = proxyquire('./../../src/transport/messageServer.js', {
'./poll.js': { default: pollGeneral },
})
return chasqui.poll(CHASQUI_URL + ranStr)
})
Expand All @@ -76,25 +76,25 @@ describe('transport.chasqui', function () {
expect(errorParse(resError)).to.equal('error')
return Promise.resolve('ResponseString')
})
chasqui = proxyquire( './../../src/transport/messageServer.js', {
'./poll.js': {default: pollGeneral}
chasqui = proxyquire('./../../src/transport/messageServer.js', {
'./poll.js': { default: pollGeneral },
})
return chasqui.poll(CHASQUI_URL + ranStr)
})

it('Clears response on chasqui once response received ', () => {
const pollGeneral = sinon.stub().resolves('ResponseString')
chasqui = proxyquire( './../../src/transport/messageServer.js', {
'./poll.js': {default: pollGeneral}
chasqui = proxyquire('./../../src/transport/messageServer.js', {
'./poll.js': { default: pollGeneral },
})
return chasqui.poll(CHASQUI_URL + ranStr)
// TODO Spy on nets call with delete uponr response
})

it('It resolves with response from polling if response', () => {
const pollGeneral = sinon.stub().resolves('ResponseString')
chasqui = proxyquire( './../../src/transport/messageServer.js', {
'./poll.js': {default: pollGeneral}
chasqui = proxyquire('./../../src/transport/messageServer.js', {
'./poll.js': { default: pollGeneral },
})
return chasqui.poll(CHASQUI_URL + ranStr).then(res => {
expect(res).to.equal('ResponseString')
Expand All @@ -103,25 +103,27 @@ describe('transport.chasqui', function () {

it('It rejects with error from polling if error', () => {
const pollGeneral = sinon.stub().rejects('Error')
chasqui = proxyquire( './../../src/transport/messageServer.js', {
'./poll.js': {default: pollGeneral}
})
return chasqui.poll(CHASQUI_URL + ranStr).then(res => {
throw new Error('transport.chasqui.poll Promise resolved, expected it to reject')
}, err => {
expect(err).to.be.an('error');
chasqui = proxyquire('./../../src/transport/messageServer.js', {
'./poll.js': { default: pollGeneral },
})
return chasqui.poll(CHASQUI_URL + ranStr).then(
res => {
throw new Error('transport.chasqui.poll Promise resolved, expected it to reject')
},
err => {
expect(err).to.be.an('error')
},
)
})

})

describe('clearResponse()', function () {
describe('clearResponse()', function() {
it('Creates DELETE HTTP request to given url', () => {
const nets = sinon.stub().callsFake((obj, cb) => {
expect(obj.method).to.equal('DELETE')
})
chasqui = proxyquire( './../../src/transport/messageServer.js', {
'nets': nets
chasqui = proxyquire('./../../src/transport/messageServer.js', {
nets: nets,
})
return chasqui.clearResponse(CHASQUI_URL + ranStr)
})
Expand Down
2 changes: 1 addition & 1 deletion test/transport/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const proxyquire = require('proxyquire')
var chai = require('chai');
const expect = chai.expect
chai.use(require('sinon-chai'))
const CHASQUI_URL = 'https://api.uport.space/chasqui/topic/'
const CHASQUI_URL = 'https://api.uport.me/chasqui/topic/'
const ranStr = '4242'

describe('transport.poll', function () {
Expand Down

0 comments on commit 8ba8a85

Please sign in to comment.