Example #1
0
test('should reply to inline query with basic driver', t => {
  let basicDriver = makeTelegramDriver(ACCESS_TOKEN)
  let results = [
    {
      type: 'article',
      title: 'Cycle.js',
      input_message_content: {
        message_text: 'A functional and reactive JavaScript framework for cleaner code'
      },
      id: '2o3aajndy0all3di'
    }
  ]
  let main = ({ bot }: Sources) => ({
    bot: xs.from([
      bot.events('inline_query')
        .debug(() => bot.dispose())
        .map(answerInlineQuery(results))
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okTake<boolean>(t, sources, (bool) => {
    t.ok(bool, 'response should be truthy')
    t.end()
  })
})
Example #2
0
test('should get game high scores with basic driver', t => {
  interface MessageUser {
    user: TcombUser
    message: TcombMessage
  }

  let basicDriver = makeTelegramDriver(ACCESS_TOKEN, isRecord ? {} : { startDate: 1477232741000 })
  let main = ({ bot }: Sources) => ({
    bot: xs.from([
      xs.of(sendGame(
        { chat_id: GROUP_ID,
          game_short_name: 'test' },
        {})),

      xs.combine(
        bot.events('message')
          .map<TcombUser>(x => x.message.from)
          .debug(() => bot.dispose()),
        bot.responses.take(1))
        .map(([user, message]) => ({ message, user }))
        .map(({ message, user }) =>
          getGameHighScores(
            { user_id: user.id, message_id: message.message_id },
            { message }))
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okDrop<TcombGameHighScore[]>(t, sources, (gameHighScores) => {
    t.ok(tc.list(GameHighScore).is(tc.list(GameHighScore)(gameHighScores)), 'game high scores satisfies typecheck')
    t.end()
  })
})
Example #3
0
test('should edit message caption with basic driver', t => {
  let basicDriver = makeTelegramDriver(ACCESS_TOKEN, isRecord ? {} : { startDate: 1472895309 * 1000 })
  let main = ({ bot }: Sources) => ({
    bot: xs.from([
      bot.events('message')
        .debug(() => bot.dispose())
        .map(sendPhoto({
          photo: fs.createReadStream(path.join(FIXTURES_PATH, 'test.jpg')),
          caption: 'Cycle.js'
        })),
      bot.responses
        .take(1)
        .filter(x => x.caption === 'Cycle.js')
        .map(message => editMessageCaption({ caption: 'Cycle Telegram' }, { message }))
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okDrop<TcombMessage | boolean>(t, sources, (message) => {
    if (typeof message !== 'boolean') {
      t.ok(Message.is(Message(message)), 'message satisfies typecheck')
      t.equal(message.caption, 'Cycle.js')
    }
    t.end()
  })
})
Example #4
0
test.skip('should answer callback query with basic driver', t => {
  let basicDriver = makeTelegramDriver(ACCESS_TOKEN)
  let main = ({ bot }: Sources) => ({
    bot: xs.from([
      bot.events('message').map(reply({
        text: 'Test message',
        reply_markup: {
          inline_keyboard: [
            [{ text: '1', callback_data: 'one' }],
            [{ text: '2', callback_data: 'two' }]
          ]
        }
      })),
      bot.events('callback_query')
        .map(x => answerCallbackQuery(
          { text: x.callback_query.data, show_alert: true },
          x))
        .debug(() => {
          bot.dispose()
          t.end()
        })
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okTake(t, sources, console.log.bind(console))
})
Example #5
0
test('should send venue with basic driver', t => {
  let basicDriver = makeTelegramDriver(ACCESS_TOKEN, { skipUpdates: true })
  let main = () => ({
    bot: xs.from([
      xs.of(sendVenue(
        {
          chat_id: GROUP_ID,
          latitude: 55.7554244,
          longitude: 37.6132518,
          title: 'Red Square',
          address: 'Moscow, Russia'
        },
        {}))
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okTake<TcombMessage>(t, sources, (message) => {
    t.ok(Message.is(Message(message)), 'message satisfies typecheck')
    t.ok(message.hasOwnProperty('venue'), 'message has property venue')
    t.equal(message.venue.title, 'Red Square', 'venue title should be Red Square')
    t.equal(message.venue.address, 'Moscow, Russia', 'venue title should be Moscow, Russia')
    t.end()
  })
})
Example #6
0
test('should leave chat with basic driver', t => {
  let basicDriver = makeTelegramDriver(ACCESS_TOKEN, { skipUpdates: true })
  let main = () => ({
    bot: xs.from([
      xs.of(leaveChat({ chat_id: GROUP_ID }, {}))
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okTake<boolean>(t, sources, (bool) => {
    t.equal(bool, true, 'bool should be true')
    t.end()
  })
})
Example #7
0
test('should get webhook info with basic driver', t => {
  let basicDriver = makeTelegramDriver(ACCESS_TOKEN, { skipUpdates: true })
  let main = () => ({
    bot: xs.from([
      xs.of(getWebhookInfo())
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okTake<TcombWebhookInfo>(t, sources, (info) => {
    t.ok(WebhookInfo.is(WebhookInfo(info)), 'webhook info satisfies typecheck')
    t.end()
  })
})
Example #8
0
test('should get chat members count with basic driver', t => {
  let basicDriver = makeTelegramDriver(ACCESS_TOKEN, { skipUpdates: true })
  let main = () => ({
    bot: xs.from([
      xs.of(getChatMembersCount({ chat_id: GROUP_ID }, {}))
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okTake<number>(t, sources, (chatMembersCount) => {
    t.equal(typeof chatMembersCount, 'number')
    t.end()
  })
})
Example #9
0
test('should reply to messages with basic driver', t => {
  let basicDriver = makeTelegramDriver(ACCESS_TOKEN, isRecord ? {} : { startDate: 1464342407440 })
  let main = ({ bot }: Sources) => ({
    bot: xs.from([
      bot.events('message').map(reply('Cycle.js'))
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okTake<TcombMessage>(t, sources, (message) => {
    t.ok(Message.is(Message(message)), 'message satisfies typecheck')
    t.equal(message.text, 'Cycle.js', 'message text should be equal to `Cycle.js`')
    t.end()
  })
})
Example #10
0
test('should get chat with basic driver', t => {
  let basicDriver = makeTelegramDriver(ACCESS_TOKEN, { skipUpdates: true })
  let main = () => ({
    bot: xs.from([
      xs.of(getChat({ chat_id: GROUP_ID }, {}))
    ])
  })
  let { sources, run } = Cycle(main, { bot: basicDriver })

  run()
  okTake<TcombChat>(t, sources, (chat) => {
    t.ok(Chat.is(Chat(chat)), 'chat satisfies typecheck')
    t.equal(chat.id, GROUP_ID)
    t.end()
  })
})