UNPKG

meses-messaging

Version:

Meses messaging SDK in JavaScript

79 lines (69 loc) 2.54 kB
import MesesMessagingService from '../src/services/MesesMessagingService' class TestMesesMessagingService { static testGetEntity() { const uri = 'http://meses-api.airyrooms.dev' const applicationId = 'ceres' const entityName = 'USER-20027' const randomString = '!(@)*)!*()' const messagingService = new MesesMessagingService(uri, applicationId) messagingService.getEntity(entityName) .then(x => console.log('[SUCCESS] ', x)) .catch(x => console.log('[ERROR] ', x)) messagingService.getEntity(randomString) .then(x => console.log('[SUCCESS] ', x)) .catch(x => console.log('[ERROR] ', x)) } static testCreateEntity() { const uri = 'http://meses-api.airyrooms.dev' const applicationId = 'ceresa' const entityName = 'hola' const properties = { is_active: true, friends: [1, 2, 3, 'a'] } const messagingService = new MesesMessagingService(uri, applicationId) messagingService.createEntity(entityName, properties) .then(x => console.log('[SUCCESS] ', x)) .catch(x => console.log('[ERROR] ', x)) } static testMarkAsRead() { const uri = 'http://meses-api.airyrooms.dev' const applicationId = 'ceres' const conversationName = 'chat-101-102' const subscriberName = 'robert.herlim' const messagingService = new MesesMessagingService(uri, applicationId) messagingService.markConversationRead(conversationName, subscriberName) .then(x => console.log('[SUCCESS] ', x)) .catch(x => console.log('[ERROR] ', x)) } static testGetMessagesByInterval() { const uri = 'http://meses-api.airyrooms.dev' const applicationId = 'ceres' const conversationName = 'COMMENT-10001186' const startTime = 1500347259001 const endTime = 1500362431918 const messagingService = new MesesMessagingService(uri, applicationId) messagingService.getMessagesByInterval(conversationName, startTime, endTime) .then(x => console.log('[SUCCESS] ', x)) .catch(x => console.log('[ERROR] ', x)) } static run(command) { switch(command) { case 1: TestMesesMessagingService.testGetEntity() break case 2: TestMesesMessagingService.testCreateEntity() break case 3: TestMesesMessagingService.testMarkAsRead() break case 4: TestMesesMessagingService.testGetMessagesByInterval() break default: console.log('Please provide the argument') } } } TestMesesMessagingService.run(4)