<commit_before>slack = null

describe 'No URL passed in', ->
  beforeEach ->
    spyOn(console, 'log')
    slack = require('../slack-notify.js')('')

  it 'should log to console that no URL is present', ->
    slack.send('Hello!')
    expect(console.log).toHaveBeenCalledWith('No Slack URL configured.')

describe 'API', ->
  url = 'https://myaccountname.slack.com/services/hooks/incoming-webhook?token=myToken'

  beforeEach ->
    slack = require('../slack-notify.js')(url)
    spyOn(slack, 'request')

  it 'slack.send', ->
    slack.send('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      username: 'Robot'
      text: 'Hello!'
      icon_emoji: ':bell:'
    , undefined

  it 'slack.success', ->
    slack.success('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#alerts'
      username: 'Hoorah'
      text: 'Hello!'
      icon_emoji: ':trophy:'
    , undefined

  it 'slack.bugs', ->
    slack.bug('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#bugs'
      username: 'Bug'
      text: 'Hello!'
      icon_emoji: ':bomb:'
    , undefined

  it 'slack.notes', ->
    slack.note('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#alerts'
      username: 'Note'
      text: 'Hello!'
      icon_emoji: ':bulb:'
    , undefined

  it 'slack.alerts', ->
    slack.alert('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#alerts'
      username: 'Alert'
      text: 'Hello!'
      icon_emoji: ':warning:'
    , undefined

  it 'slack.alerts with extra fields', ->
    slack.alert
      text: 'Hello!'
      fields:
        IP: '192.168.127.12'
        sha: '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12'

    expect(slack.request).toHaveBeenCalledWith
      channel: '#alerts'
      username: 'Alert'
      text: 'Hello!'
      icon_emoji: ':warning:'
      attachments: [
        {
          fallback: 'Alert details'
          fields: [
            { title: 'IP', value: '192.168.127.12', short: true }
            { title: 'sha', value: '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12', short: false }
          ]
        }
      ]
    , undefined

  it 'slack.extend', ->
    foo = slack.extend
      channel: '#foo'
      icon_emoji: ':saxophone:'
      username: 'Foo'

    foo('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#foo'
      username: 'Foo'
      text: 'Hello!'
      icon_emoji: ':saxophone:'
    , undefined

  it 'slack.send with icon_url', ->
    slack.send
      text: 'Hello!'
      icon_url: 'http://something.com/icon.png'

    expect(slack.request).toHaveBeenCalledWith
      username: 'Robot'
      text: 'Hello!'
      icon_url: 'http://something.com/icon.png'
    , undefined

  it 'slack.send with attachments and extra fields', ->
    slack.send
      text: 'Hello!'
      attachments: [
        {
          fallback: 'Fallback'
          fields: [
            { title: 'CPU %', value: '90%', short: true }
            { title: 'RAM %', value: '47%', short: true }
          ]
        }
      ]
      fields:
        IP: '192.168.127.12'
        sha: '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12'
    , undefined

    expect(slack.request).toHaveBeenCalledWith
      username: 'Robot'
      text: 'Hello!'
      icon_emoji: ':bell:'<commit_msg>Remove unnecessary undefined argument in test<commit_after>slack = null

describe 'No URL passed in', ->
  beforeEach ->
    spyOn(console, 'log')
    slack = require('../slack-notify.js')('')

  it 'should log to console that no URL is present', ->
    slack.send('Hello!')
    expect(console.log).toHaveBeenCalledWith('No Slack URL configured.')

describe 'API', ->
  url = 'https://myaccountname.slack.com/services/hooks/incoming-webhook?token=myToken'

  beforeEach ->
    slack = require('../slack-notify.js')(url)
    spyOn(slack, 'request')

  it 'slack.send', ->
    slack.send('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      username: 'Robot'
      text: 'Hello!'
      icon_emoji: ':bell:'
    , undefined

  it 'slack.success', ->
    slack.success('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#alerts'
      username: 'Hoorah'
      text: 'Hello!'
      icon_emoji: ':trophy:'
    , undefined

  it 'slack.bugs', ->
    slack.bug('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#bugs'
      username: 'Bug'
      text: 'Hello!'
      icon_emoji: ':bomb:'
    , undefined

  it 'slack.notes', ->
    slack.note('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#alerts'
      username: 'Note'
      text: 'Hello!'
      icon_emoji: ':bulb:'
    , undefined

  it 'slack.alerts', ->
    slack.alert('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#alerts'
      username: 'Alert'
      text: 'Hello!'
      icon_emoji: ':warning:'
    , undefined

  it 'slack.alerts with extra fields', ->
    slack.alert
      text: 'Hello!'
      fields:
        IP: '192.168.127.12'
        sha: '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12'

    expect(slack.request).toHaveBeenCalledWith
      channel: '#alerts'
      username: 'Alert'
      text: 'Hello!'
      icon_emoji: ':warning:'
      attachments: [
        {
          fallback: 'Alert details'
          fields: [
            { title: 'IP', value: '192.168.127.12', short: true }
            { title: 'sha', value: '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12', short: false }
          ]
        }
      ]
    , undefined

  it 'slack.extend', ->
    foo = slack.extend
      channel: '#foo'
      icon_emoji: ':saxophone:'
      username: 'Foo'

    foo('Hello!')
    expect(slack.request).toHaveBeenCalledWith
      channel: '#foo'
      username: 'Foo'
      text: 'Hello!'
      icon_emoji: ':saxophone:'
    , undefined

  it 'slack.send with icon_url', ->
    slack.send
      text: 'Hello!'
      icon_url: 'http://something.com/icon.png'

    expect(slack.request).toHaveBeenCalledWith
      username: 'Robot'
      text: 'Hello!'
      icon_url: 'http://something.com/icon.png'
    , undefined

  it 'slack.send with attachments and extra fields', ->
    slack.send
      text: 'Hello!'
      attachments: [
        {
          fallback: 'Fallback'
          fields: [
            { title: 'CPU %', value: '90%', short: true }
            { title: 'RAM %', value: '47%', short: true }
          ]
        }
      ]
      fields:
        IP: '192.168.127.12'
        sha: '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12'

    expect(slack.request).toHaveBeenCalledWith
      username: 'Robot'
      text: 'Hello!'
      icon_emoji: ':bell:'
{'fraction_non_alphanumeric': 0.14780635400907716, 'fraction_numerical': 0.031164901664145234, 'mean_word_length': 2.3626653102746693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1030909', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2283, 'n_words': 435}