Refactoring in-progress but mostly done

This commit is contained in:
mhelander 2018-01-23 01:04:28 +02:00
parent eb8d0dfcce
commit 14497ac7ad
2 changed files with 879 additions and 852 deletions

1499
sea.js

File diff suppressed because it is too large Load Diff

View File

@ -28,16 +28,24 @@ if(typeof Buffer === 'undefined'){
var Buffer = require('buffer').Buffer; var Buffer = require('buffer').Buffer;
} }
function checkIndexedDB(key, prop, resolve_){ const checkIndexedDB = (key, prop, resolve_) => {
var result; const doIt = (resolve, reject) => {
Gun.SEA._callonstore_(function(store) { try {
var getData = store.get(key); Gun.SEA._callonstore_((store) => new Promise((reslv) => {
getData.onsuccess = function(){ const getData = store.get(key)
result = getData.result && getData.result[prop]; getData.onsuccess = () => {
}; reslv(getData.result && getData.result[prop])
}, function(){ }
resolve_(result); })).then(resolve)
}); } catch (e) {
reject(e)
}
}
if (resolve_) {
doIt(resolve_, (e) => { throw e })
} else {
return new Promise(doIt)
}
} }
function setIndexedDB(key, prop, resolve_){ function setIndexedDB(key, prop, resolve_){
@ -346,31 +354,31 @@ Gun().user && describe('Gun', function(){
}); });
describe('auth', function(){ describe('auth', function(){
var checkStorage = function(done, notStored){ const checkStorage = (done, notStored) => () => {
return function(){ const checkValue = (data, val) => {
var checkValue = function(data, val){ if (notStored) {
if(notStored){
expect(typeof data !== 'undefined' && data !== null && data !== '') expect(typeof data !== 'undefined' && data !== null && data !== '')
.to.not.eql(true); .to.not.eql(true)
} else { } else {
expect(data).to.not.be(undefined); expect(data).to.not.be(undefined)
expect(data).to.not.be(''); expect(data).to.not.be('')
if(val){ expect(data).to.eql(val) } if (val) {
expect(data).to.eql(val)
} }
}; }
var alias = root.sessionStorage.getItem('user'); }
checkValue(alias); const alias = root.sessionStorage.getItem('user')
checkValue(root.sessionStorage.getItem('remember')); checkValue(alias)
if(alias){ checkValue(root.sessionStorage.getItem('remember'))
checkIndexedDB(alias, 'auth', function(auth){ if (alias) {
checkValue(auth); checkIndexedDB(alias, 'auth').then((auth) => {
done(); checkValue(auth)
}); done()
}).catch(done)
} else { } else {
done(); done()
}
} }
};
};
it('login', function(done){ it('login', function(done){
var check = function(ack){ var check = function(ack){
@ -478,13 +486,13 @@ Gun().user && describe('Gun', function(){
}); });
it('with PIN auth session stored', function(done){ it('with PIN auth session stored', function(done){
if(type === 'callback'){ if (type === 'callback'){
user.auth(alias+type, pass+' new', checkStorage(done), {pin: 'PIN'}); user.auth(alias+type, pass+' new', checkStorage(done), { pin: 'PIN' })
} else { } else {
user.auth(alias+type, pass+' new', {pin: 'PIN'}) user.auth(alias+type, pass+' new', { pin: 'PIN' })
.then(checkStorage(done)).catch(done); .then(checkStorage(done)).catch(done)
} }
}); })
it('without PIN and zero validity no auth session storing', function(done){ it('without PIN and zero validity no auth session storing', function(done){
user.recall(0).then(function(){ user.recall(0).then(function(){