Skip to content

Commit

Permalink
array-ified
Browse files Browse the repository at this point in the history
  • Loading branch information
maverick-zhn committed Jul 10, 2018
1 parent fb0fbe7 commit 77e7487
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"babel-preset-latest": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"babel-register": "^6.26.0",
"cerebral": "^4.2.2",
"chai": "^4.1.2"
}
}
18 changes: 18 additions & 0 deletions src/import.cerebral.provider.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
process.env.NODE_TLS_REJECT_UNAUTHORIZED=0;
import { Provider } from 'cerebral';
import oada from '../build/index';

import chai from 'chai';
let expect = chai.expect;

let token = 'def';
let url = 'https://vip3.ecn.purdue.edu/bookmarks';
let contentType = 'application/vnd.oada.yield.1+json';

describe('#connection()', function() {
it('should connect when a token is provided', () => {
return oada.connect({token, domain: 'https://vip3.ecn.purdue.edu'}).then((result) => {
expect(result).to.have.key('token')
})
})
});
48 changes: 33 additions & 15 deletions src/sequences.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const get = sequence('oada.get', [
for(let i = 0; i < arrayLength; i++){
apiPromises.push(oada.get({
url: state.get('oada.domain') + ((props.requests[i].path[0] === '/') ?
'':'/') + props.requests[i].path,
'':'/') + props.requests[i].path,
token: state.get('oada.token')
}));
htIndex[props.requests[i].path] = i;
Expand Down Expand Up @@ -168,20 +168,38 @@ export const put = sequence('oada.put', [
// Somewhat abandoned. PUT is preferred. Create the uuid and send it along.
export const post = sequence('oada.post', [
({props, state, oada}) => {
return oada.post({
url: state.get('oada.domain')+((props.path[0] === '/') ? '':'/')+props.path,
token: state.get('oada.token'),
contentType: props.contentType,
data: props.data,
}).then((response) => {
return {
// return the resource
_rev: response._rev,
id: response.headers['content-location'].split('/').filter(n => n && true).slice(-1)[0],
}
})
},
updateState
const apiPromises = [];
const htIndex = {};
requestsRequired = props.requests.length;

for (let i = 0; i < requestsRequired; i++) {
apiPromises.push(oada.post({
url: state.get('oada.domain')+((props.requests[i].path[0] === '/') ?
'':'/') + props.requests[i].path,
token: state.get('oada.token'),
contentType: props.contentType,
data: props.requests[i].data,
});
htIndex[props.requests[i].path] = i;
}//for

let results = [];
Promise.all(apiPromises)
.then(responses => {
const processedResponses = [];
responses.map(response => {
processedResponses.push(response);
results.push({
// return the resource
_rev: response._rev,
id: response.headers['content-location'].split('/')
.filter(n => n && true).slice(-1)[0],
});
})
return results;
})
}
//updateState
])

// When starting up, it should fetch stuff using using the setup tree, creating
Expand Down
29 changes: 29 additions & 0 deletions test/import.cerebral.provider.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var _cerebral = require('cerebral');

var _index = require('../build/index');

var _index2 = _interopRequireDefault(_index);

var _chai = require('chai');

var _chai2 = _interopRequireDefault(_chai);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

var expect = _chai2.default.expect;

var token = 'def';
var url = 'https://vip3.ecn.purdue.edu/bookmarks';
var contentType = 'application/vnd.oada.yield.1+json';

describe('#connection()', function () {
it('should connect when a token is provided', function () {
return _index2.default.connect({ token: token, domain: 'https://vip3.ecn.purdue.edu' }).then(function (result) {
expect(result).to.have.key('token');
});
});
});
18 changes: 18 additions & 0 deletions test/import.cerebral.provider.test.js.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
process.env.NODE_TLS_REJECT_UNAUTHORIZED=0;
import { Provider } from 'cerebral';
import oada from '@oada/cerebral-module';

import chai from 'chai';
let expect = chai.expect;

let token = 'def';
let url = 'https://vip3.ecn.purdue.edu/bookmarks';
let contentType = 'application/vnd.oada.yield.1+json';

describe('#connection()', function() {
it('should connect when a token is provided', () => {
return oada.connect({token, domain: 'https://vip3.ecn.purdue.edu'}).then((result) => {
expect(result).to.have.key('token')
})
})
});

0 comments on commit 77e7487

Please sign in to comment.