mirror of
https://github.com/amark/gun.git
synced 2025-06-07 14:46:44 +00:00
once -> then
This commit is contained in:
parent
87b2dbe03d
commit
8161f14553
@ -267,22 +267,21 @@ describe("Shocknet Test!", function(){
|
|||||||
},{pub: testData[1].pub, config: config})
|
},{pub: testData[1].pub, config: config})
|
||||||
})
|
})
|
||||||
it("Reading bob display name using .then !",function(){
|
it("Reading bob display name using .then !",function(){
|
||||||
return alice.run(function(test){
|
return alice.run(async function(test){
|
||||||
const done = test.async()
|
const done = test.async()
|
||||||
const {pub} = test.props
|
const {pub} = test.props
|
||||||
const {keys} = test.props.config
|
const {keys} = test.props.config
|
||||||
global.gun
|
const dn = await global.gun
|
||||||
.user(pub)
|
.user(pub)
|
||||||
.get(keys.PROFILE)
|
.get(keys.PROFILE)
|
||||||
.get(keys.DISPLAY_NAME)
|
.get(keys.DISPLAY_NAME)
|
||||||
.then(dn => {
|
.then()
|
||||||
if(!dn.startsWith('bob')){
|
if(!dn.startsWith('bob')){
|
||||||
test.fail(`display Name > ${dn}`)
|
test.fail(`display Name > ${dn}`)
|
||||||
} else {
|
} else {
|
||||||
console.log(dn)
|
console.log(dn)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
},{pub: testData[1].pub, config: config})
|
},{pub: testData[1].pub, config: config})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -377,28 +376,27 @@ describe("Shocknet Test!", function(){
|
|||||||
tests.push(client.run(function(test){
|
tests.push(client.run(function(test){
|
||||||
const env = test.props;
|
const env = test.props;
|
||||||
const keys = env.config.keys
|
const keys = env.config.keys
|
||||||
global.pubToEpub = pub =>{
|
global.pubToEpub = async (pub,fail) =>{
|
||||||
return new Promise((res,rej)=> {
|
const epub = await global.gun
|
||||||
global.gun
|
|
||||||
.user(pub)
|
.user(pub)
|
||||||
.get('epub')
|
.get('epub')
|
||||||
.once(epub => typeof epub === 'string' ? res(epub): rej(`Expected epub ti be string found ${typeof epub}`))
|
.then()
|
||||||
})
|
if(typeof epub === 'string'){
|
||||||
|
return epub
|
||||||
|
} else {
|
||||||
|
fail(`Expected epub ti be string found ${typeof epub}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
global.successfulHandshakeAlreadyExists = async pub =>{
|
global.successfulHandshakeAlreadyExists = async pub =>{
|
||||||
const {user} = global
|
const {user} = global
|
||||||
const maybeIncomingID = await new Promise(res=>{
|
const maybeIncomingID = await user
|
||||||
user
|
|
||||||
.get(keys.USER_TO_INCOMING)
|
.get(keys.USER_TO_INCOMING)
|
||||||
.get(pub)
|
.get(pub)
|
||||||
.once(id => res(id))
|
.then()
|
||||||
})
|
const maybeOutgoingID = await user
|
||||||
const maybeOutgoingID = await new Promise(res =>{
|
|
||||||
user
|
|
||||||
.get(keys.RECIPIENT_TO_OUTGOING)
|
.get(keys.RECIPIENT_TO_OUTGOING)
|
||||||
.get(pub)
|
.get(pub)
|
||||||
.once(id => res(id))
|
.then()
|
||||||
})
|
|
||||||
return typeof maybeIncomingID === 'string' && typeof maybeOutgoingID === 'string'
|
return typeof maybeIncomingID === 'string' && typeof maybeOutgoingID === 'string'
|
||||||
}
|
}
|
||||||
}, {i: i += 1, config: config}));
|
}, {i: i += 1, config: config}));
|
||||||
@ -468,16 +466,16 @@ describe("Shocknet Test!", function(){
|
|||||||
},data)
|
},data)
|
||||||
})
|
})
|
||||||
it(`Sending handshake request to ${name} 1: cleanup 4:recipientToOutgoingID !`,function(){
|
it(`Sending handshake request to ${name} 1: cleanup 4:recipientToOutgoingID !`,function(){
|
||||||
return testClient.run(function(test){
|
return testClient.run(async function(test){
|
||||||
const done = test.async()
|
const done = test.async()
|
||||||
const env = test.props
|
const env = test.props
|
||||||
const {index} = env
|
const {index} = env
|
||||||
const {pub} = env.testData[index]
|
const {pub} = env.testData[index]
|
||||||
const keys = env.config.keys
|
const keys = env.config.keys
|
||||||
global.user
|
const maybeEncryptedOutgoingID = await global.user
|
||||||
.get(keys.RECIPIENT_TO_OUTGOING)
|
.get(keys.RECIPIENT_TO_OUTGOING)
|
||||||
.get(pub)
|
.get(pub)
|
||||||
.once(maybeEncryptedOutgoingID => {
|
.then()
|
||||||
if(maybeEncryptedOutgoingID === 'string'){
|
if(maybeEncryptedOutgoingID === 'string'){
|
||||||
|
|
||||||
global.hsData.maybeEncryptedOutgoingID = maybeEncryptedOutgoingID
|
global.hsData.maybeEncryptedOutgoingID = maybeEncryptedOutgoingID
|
||||||
@ -487,7 +485,6 @@ describe("Shocknet Test!", function(){
|
|||||||
global.hsData.outgoingID = maybeEncryptedOutgoingID
|
global.hsData.outgoingID = maybeEncryptedOutgoingID
|
||||||
}
|
}
|
||||||
done()
|
done()
|
||||||
})
|
|
||||||
|
|
||||||
},data)
|
},data)
|
||||||
})
|
})
|
||||||
@ -556,7 +553,7 @@ describe("Shocknet Test!", function(){
|
|||||||
pubToEpub,
|
pubToEpub,
|
||||||
SEA,
|
SEA,
|
||||||
} = global
|
} = global
|
||||||
return pubToEpub(pub)
|
pubToEpub(pub,test.fail)
|
||||||
.then(bobEpub =>{
|
.then(bobEpub =>{
|
||||||
SEA.secret(bobEpub,user._.sea)
|
SEA.secret(bobEpub,user._.sea)
|
||||||
.then(ourSecret =>{
|
.then(ourSecret =>{
|
||||||
@ -588,59 +585,53 @@ describe("Shocknet Test!", function(){
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("Sending handshake request to bob 4: getting handshake address!",function(){
|
it("Sending handshake request to bob 4: getting handshake address!",function(){
|
||||||
return alice.run(function(test){
|
return alice.run(async function(test){
|
||||||
const done = test.async()
|
const done = test.async()
|
||||||
const {pub} = test.props
|
const {pub} = test.props
|
||||||
const {keys} = test.props.config
|
const {keys} = test.props.config
|
||||||
return new Promise(res => {
|
const currentHandshakeAddress = await gun
|
||||||
gun
|
|
||||||
.user(pub)
|
.user(pub)
|
||||||
.get(keys.CURRENT_HANDSHAKE_ADDRESS)
|
.get(keys.CURRENT_HANDSHAKE_ADDRESS)
|
||||||
.once(addr => res(addr))
|
.then()
|
||||||
}).then(currentHandshakeAddress =>{
|
|
||||||
if(typeof currentHandshakeAddress !== 'string'){
|
if(typeof currentHandshakeAddress !== 'string'){
|
||||||
test.fail("expected current handshake address to be string")
|
test.fail("expected current handshake address to be string")
|
||||||
} else {
|
} else {
|
||||||
global.hsData.currentHandshakeAddress = currentHandshakeAddress
|
global.hsData.currentHandshakeAddress = currentHandshakeAddress
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
},{pub: testData[1].pub, config: config})
|
},{pub: testData[1].pub, config: config})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Sending handshake request to bob 5: check if already sent request!",function(){
|
it("Sending handshake request to bob 5: check if already sent request!",function(){
|
||||||
return alice.run(function(test){
|
return alice.run(async function(test){
|
||||||
const done = test.async()
|
const done = test.async()
|
||||||
const {pub} = test.props
|
const {pub} = test.props
|
||||||
const {keys} = test.props.config
|
const {keys} = test.props.config
|
||||||
const {currentHandshakeAddress} = global.hsData
|
const {currentHandshakeAddress} = global.hsData
|
||||||
user
|
const maybeLastRequestIDSentToUser = await user
|
||||||
.get(keys.USER_TO_LAST_REQUEST_SENT)
|
.get(keys.USER_TO_LAST_REQUEST_SENT)
|
||||||
.get(pub)
|
.get(pub)
|
||||||
.once(maybeLastRequestIDSentToUser => {
|
.then()
|
||||||
if(typeof maybeLastRequestIDSentToUser === 'string'){
|
if(typeof maybeLastRequestIDSentToUser === 'string'){
|
||||||
if (maybeLastRequestIDSentToUser.length < 5) {
|
if (maybeLastRequestIDSentToUser.length < 5) {
|
||||||
test.fail("maybeLastRequestIDSentToUser.length < 5")
|
test.fail("maybeLastRequestIDSentToUser.length < 5")
|
||||||
}
|
}
|
||||||
const lastRequestIDSentToUser = maybeLastRequestIDSentToUser
|
const lastRequestIDSentToUser = maybeLastRequestIDSentToUser
|
||||||
gun
|
const hrInHandshakeNode = await gun
|
||||||
.get(keys.HANDSHAKE_NODES)
|
.get(keys.HANDSHAKE_NODES)
|
||||||
.get(currentHandshakeAddress)
|
.get(currentHandshakeAddress)
|
||||||
.get(lastRequestIDSentToUser)
|
.get(lastRequestIDSentToUser)
|
||||||
.once(hrInHandshakeNode =>{
|
.then()
|
||||||
if(typeof hrInHandshakeNode !== 'undefined'){
|
if(typeof hrInHandshakeNode !== 'undefined'){
|
||||||
test.fail("request already sent")
|
test.fail("request already sent")
|
||||||
} else {
|
} else {
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
},{pub: testData[1].pub, config: config})
|
},{pub: testData[1].pub, config: config})
|
||||||
})
|
})
|
||||||
const createOutgoingFeed =(name,testClient,data)=>{
|
const createOutgoingFeed =(name,testClient,data)=>{
|
||||||
@ -677,16 +668,16 @@ describe("Shocknet Test!", function(){
|
|||||||
},data)
|
},data)
|
||||||
})
|
})
|
||||||
it(`${name}: create outgoing feed 2.8:maybeOutgoingID !`,function(){
|
it(`${name}: create outgoing feed 2.8:maybeOutgoingID !`,function(){
|
||||||
return testClient.run(function(test){
|
return testClient.run(async function(test){
|
||||||
const done = test.async()
|
const done = test.async()
|
||||||
const env = test.props
|
const env = test.props
|
||||||
const {index} = env
|
const {index} = env
|
||||||
const {pub} = env.testData[index]
|
const {pub} = env.testData[index]
|
||||||
const keys = env.config.keys
|
const keys = env.config.keys
|
||||||
global.user
|
const maybeEncryptedOutgoingID = await global.user
|
||||||
.get(keys.RECIPIENT_TO_OUTGOING)
|
.get(keys.RECIPIENT_TO_OUTGOING)
|
||||||
.get(pub)
|
.get(pub)
|
||||||
.once(maybeEncryptedOutgoingID => {
|
.then()
|
||||||
if(maybeEncryptedOutgoingID === 'string'){
|
if(maybeEncryptedOutgoingID === 'string'){
|
||||||
|
|
||||||
global.hsData.maybeEncryptedOutgoingID = maybeEncryptedOutgoingID
|
global.hsData.maybeEncryptedOutgoingID = maybeEncryptedOutgoingID
|
||||||
@ -696,7 +687,6 @@ describe("Shocknet Test!", function(){
|
|||||||
global.hsData.maybeOutgoingID = maybeEncryptedOutgoingID
|
global.hsData.maybeOutgoingID = maybeEncryptedOutgoingID
|
||||||
}
|
}
|
||||||
done()
|
done()
|
||||||
})
|
|
||||||
|
|
||||||
},data)
|
},data)
|
||||||
})
|
})
|
||||||
@ -1018,22 +1008,21 @@ describe("Shocknet Test!", function(){
|
|||||||
},{testData, config: config,index:1})
|
},{testData, config: config,index:1})
|
||||||
})
|
})
|
||||||
it(`Accepting handshake request from alice 7: currentHandshakeAddress !`,function(){
|
it(`Accepting handshake request from alice 7: currentHandshakeAddress !`,function(){
|
||||||
return bob.run(function(test){
|
return bob.run(async function(test){
|
||||||
const done = test.async()
|
const done = test.async()
|
||||||
const env = test.props
|
const env = test.props
|
||||||
const keys = env.config.keys
|
const keys = env.config.keys
|
||||||
const {user} = global
|
const {user} = global
|
||||||
global.hsData = {}
|
global.hsData = {}
|
||||||
user
|
const currentHandshakeAddress = await user
|
||||||
.get(keys.CURRENT_HANDSHAKE_ADDRESS)
|
.get(keys.CURRENT_HANDSHAKE_ADDRESS)
|
||||||
.once(currentHandshakeAddress => {
|
.then()
|
||||||
if(typeof currentHandshakeAddress !== 'string'){
|
if(typeof currentHandshakeAddress !== 'string'){
|
||||||
test.fail("expected currentHandshakeAddress to be string")
|
test.fail("expected currentHandshakeAddress to be string")
|
||||||
} else {
|
} else {
|
||||||
global.hsData.currentHandshakeAddress = currentHandshakeAddress
|
global.hsData.currentHandshakeAddress = currentHandshakeAddress
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
},{testData, config: config,index:0})
|
},{testData, config: config,index:0})
|
||||||
})
|
})
|
||||||
it(`Accepting handshake request from alice 7: receivedReqs **using .load!`,function(){
|
it(`Accepting handshake request from alice 7: receivedReqs **using .load!`,function(){
|
||||||
@ -1046,7 +1035,7 @@ describe("Shocknet Test!", function(){
|
|||||||
gun
|
gun
|
||||||
.get(keys.HANDSHAKE_NODES)
|
.get(keys.HANDSHAKE_NODES)
|
||||||
.get(currentHandshakeAddress)
|
.get(currentHandshakeAddress)
|
||||||
.load(receivedReqs =>{
|
.open(receivedReqs =>{
|
||||||
global.hsData.receivedReqs = receivedReqs
|
global.hsData.receivedReqs = receivedReqs
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
@ -1084,7 +1073,7 @@ describe("Shocknet Test!", function(){
|
|||||||
const keys = env.config.keys
|
const keys = env.config.keys
|
||||||
const {pubToEpub} = global
|
const {pubToEpub} = global
|
||||||
const {data} = global.hsData
|
const {data} = global.hsData
|
||||||
pubToEpub(data.from)
|
pubToEpub(data.from,test.fail)
|
||||||
.then(aliceEpub => {
|
.then(aliceEpub => {
|
||||||
global.hsData.otherEpub = aliceEpub
|
global.hsData.otherEpub = aliceEpub
|
||||||
done()
|
done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user