summaryrefslogtreecommitdiff
blob: ff4b9a639d15a8ea72a1b59e6d777005a09b728e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'mediawiki_api'

describe 'Echo' do
  before(:all) do
    if ENV['JENKINS_HOME']
      # jenkins
      @mediawiki_api = "#{ENV['MW_SERVER']}#{ENV['MW_SCRIPT_PATH']}/api.php"
      @admin_username = 'WikiAdmin'
      @admin_password = 'testpass'
    else
      # mediawiki-vagrant
      @mediawiki_api = 'http://127.0.0.1:8080/w/api.php'
      @admin_username = 'Admin'
      @admin_password = 'vagrant'
    end

    @client = MediawikiApi::Client.new @mediawiki_api
  end

  before(:each) do
    @client.log_in @admin_username, @admin_password

    require 'securerandom'
    @random_username = "U#{SecureRandom.hex(5)}"
    @random_password = SecureRandom.hex(5)
  end

  it 'should notify a new user with welcome message' do
    @client.create_account(@random_username, @random_password)

    @client.log_in @random_username, @random_password
    notifications = @client.query(meta: 'notifications').data['notifications']['list']

    welcome_notification = notifications.first
    expect(welcome_notification['type']).to eq 'welcome'
    expect(welcome_notification['agent']['name']).to eq @random_username
    expect(welcome_notification['timestamp']['date']).to eq 'Today'
  end

  it 'should notify user about mention on wikitext page' do
    @client.create_account(@random_username, @random_password)

    page = SecureRandom.hex(5).capitalize
    @client.edit(title: page, text: "[[User:#{@random_username}]] ~~~~")

    @client.log_in @random_username, @random_password
    notifications = @client.query(meta: 'notifications').data['notifications']['list']

    mention_notification = notifications.last
    expect(mention_notification['type']).to eq 'mention'
    expect(mention_notification['agent']['name']).to eq @admin_username
    expect(mention_notification['title']['full']).to eq page
  end

end