meses-messaging
Version:
Meses messaging SDK in JavaScript
126 lines (111 loc) • 4.07 kB
JavaScript
import MesesMessagingApp from '../src/MesesMessagingApp'
class TestMesesMessagingApp {
static testConnect() {
const app = new MesesMessagingApp('http://meses-api.airyrooms.dev', 'ceres')
app.connect('USER-20027')
.then(result => console.log('Result: ', result))
.then(() => app.connect('USER-20022'))
.then(result => console.log('Result: ', result))
.catch(err => console.log(err))
}
static testDisconnect() {
const app = new MesesMessagingApp('http://meses-api.airyrooms.dev', 'ceres')
app.connect('USER-20027')
.then(() => { console.log('Before disconnect:', app._user); return app.disconnect() })
.then(() => { console.log('After disconnect:', app._user) })
.catch(err => console.log(err))
}
static testUpdateUserInfo() {
const app = new MesesMessagingApp('http://meses-api.airyrooms.dev', 'ceres')
const properties = {
displayName: 'Robert Sebastian Herlimxxxx'
}
app.connect('USER-20027')
.then(function(result) { return app.updateUserInfo(properties) })
.then(function(result) { console.log('New user info: ', app._user) })
.catch(function(err) { console.log(err) })
}
static testCreateUser() {
const app = new MesesMessagingApp('http://meses-api.airyrooms.dev', 'ceres')
const properties = {
displayName: 'Robert Sebastian Herlim',
email: 'ngiooong@yahoo.com'
}
app.createUser('Ngiongxz', properties)
.then(() => app.connect('Ngiongxz'))
.then(() => console.log('[SUCCESS]', app._user))
.catch(err => console.log(err))
}
static testGetConversation() {
const app = new MesesMessagingApp('http://meses-api.airyrooms.dev', 'ceres')
let conversation
app.connect('USER-20002')
.then(() => app.getConversation('COMMENT-10000822'))
.then(result => { conversation = result })
.then(() => console.log('[SUCCESS]: ', conversation))
.then(() => app.getConversation('COMMENT-10000822'))
.then(result => console.log('This conversation is from cached array: ', result))
.catch(err => console.log(err))
}
static testCreateConversation() {
const app = new MesesMessagingApp('http://meses-api.airyrooms.dev', 'ceres')
let subscribers = ['USER-20001', 'USER-20002', 'USER-20003', 'USER-20004']
let conversation
app.connect('USER-20027')
.then(() => app.createConversation('HolaHipHipHorexxxxxxx', { usage: 'sdkTesting' }, subscribers))
.then(result => conversation = result)
.then(() => console.log(conversation))
.catch(err => console.log(err))
}
static testAttachHandler() {
const app = new MesesMessagingApp('http://meses-api.airyrooms.dev', 'ceres')
app.connect('USER-20027')
.then(() => {
let first = app.createConversationUpdateHandler('First', function(err, result) {
console.log('First')
})
app.attachUpdateHandler(first)
return app.getConversation('COMMENT-10001186')
})
.then(result => {
let second = result.createNewMessageUpdateHandler('Second', function(err, result) {
console.log('Second')
})
app.attachUpdateHandler(second)
})
.catch(err => console.error(err))
}
static testDetachHandler() {
}
static run(command) {
switch(command) {
case 1:
TestMesesMessagingApp.testConnect()
break
case 2:
TestMesesMessagingApp.testDisconnect()
break
case 3:
TestMesesMessagingApp.testUpdateUserInfo()
break
case 4:
TestMesesMessagingApp.testCreateUser()
break
case 5:
TestMesesMessagingApp.testGetConversation()
break
case 6:
TestMesesMessagingApp.testCreateConversation()
break
case 7:
TestMesesMessagingApp.testAttachHandler()
break
case 8:
TestMesesMessagingApp.testDetachHandler()
break
default:
console.log('Please provide the argument')
}
}
}
TestMesesMessagingApp.run(7)