<commit_before># encoding: UTF-8
require 'spec_helper'

describe WxExt::WeiXin do
  before(:all) do
    @weixin = WxExt::WeiXin.new '<EMAIL>', '1*flower@wrong*1'
  end

  it 'should login to the mp' do
    res_hash = @weixin.login
    expect(res_hash[:status]).to eql(0)
  end

  it 'should init method should init all params' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      token = @weixin.token
      expect(token).to match(/\d+/)
		else
			expect(flag).to eql(true)
    end
  end

  it 'should search msg with keyword' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      require 'uri'
      ha = @weixin.get_msg_items(20, 7, 1, '','', '', '')
    end
  end

  it "should preview msg method should preview a msg to me" do
    res_hash = @weixin.login
    flag = @weixin.init
    file = File.new(File.join(WxExt.spec, "test.png"), 'rb')
    file_hash = @weixin.upload_file(file, "test.png")
    file_id = file_hash["content"]
    msg_params_with_name = {
      AppMsgId: '',
      ajax: 1,
      author0: '作者' + rand.to_s,
      can_reward0: 0,
      content0: '正文' + rand.to_s,
      copyright_type0: 0,
      count: 1,
      digest0: 'test摘要' + rand.to_s,
      f: 'json',
      fileid0: file_id,
      imgcode: '',
      lang: 'zh_CN',
      preusername: 'nan474947',
      random: rand,
      reward_wording0: '',
      shortvideofileid0: '',
      show_cover_pic0: 1,  # 0 => 封面图片不显示在正文中
      sourceurl0: 'http://thecampus.cc/' + rand.to_s,
      title0: 'test标题' + rand.to_s,
      token: @weixin.token,
      vid: ''
    }
    msg_hash = @weixin.preview_msg(msg_params_with_name)
    expect(msg_hash["ret"].to_s).to eql("0")
  end

=begin
  it 'should reply to yang' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      quick_reply_res_hash = @weixin.quick_reply('测试回复2', 201123100, 204060720)
      puts '==' * 20
      puts quick_reply_res_hash
      expect(quick_reply_res_hash['base_resp']['ret'].to_s).to eql('0')
    end
  end

  it 'should star msg' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      star_res_hash = @weixin.collect_msg('201123100')
      puts '==' * 20
      puts star_res_hash
      expect(star_res_hash['ret'].to_s).to eql('0')
    end
  end

  it 'should un star msg' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      star_res_hash = @weixin.un_collect_msg('201123100')
      puts '==' * 20
      puts star_res_hash
      expect(star_res_hash['ret'].to_s).to eql('0')
    end
  end
=end

  it 'should get fans count' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      fans_res_hash = @weixin.get_fans_count
      expect(fans_res_hash[:status]).to eql(0)
    end
  end

  it 'should get total_count, count, day, frommsgid, can_search_msg, offset, action=search, keyword, last_msg_id, filterivrmsg=0/1 和 msg_items' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      res_hash = @weixin.get_msg_items(20, 7, 1, '', '', '', '')
      expect(res_hash[:status]).to eql(0)
    else
      puts 'init failed'
    end
  end

  it "should get new msg num" do
    res_hash = @weixin.login
    flag = @weixin.init
    msg_res_hash = @weixin.get_msg_items if flag
    res_hash = @weixin.get_new_msg_num(msg_res_hash[:latest_msg_id=])
    expect(res_hash['ret'].to_s).to eql('0')
  end

  it 'should get day msg count' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      day_msg_count = @weixin.get_day_msg_count
      expect(day_msg_count.to_s).to match(/\d*/)
    end
  end<commit_msg>Add account message api test<commit_after># encoding: UTF-8
require 'spec_helper'

describe WxExt::WeiXin do
  before(:all) do
    @weixin = WxExt::WeiXin.new '<EMAIL>', '1*flower@wrong*1'
  end

  it 'should login to the mp' do
    res_hash = @weixin.login
    expect(res_hash[:status]).to eql(0)
  end

  it 'should init method should init all params' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      token = @weixin.token
      expect(token).to match(/\d+/)
		else
			expect(flag).to eql(true)
    end
  end

  it 'should search msg with keyword' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      require 'uri'
      ha = @weixin.get_msg_items(20, 7, 1, '','', '', '')
    end
  end

  it "should preview msg method should preview a msg to me" do
    res_hash = @weixin.login
    flag = @weixin.init
    file = File.new(File.join(WxExt.spec, "test.png"), 'rb')
    file_hash = @weixin.upload_file(file, "test.png")
    file_id = file_hash["content"]
    msg_params_with_name = {
      AppMsgId: '',
      ajax: 1,
      author0: '作者' + rand.to_s,
      can_reward0: 0,
      content0: '正文' + rand.to_s,
      copyright_type0: 0,
      count: 1,
      digest0: 'test摘要' + rand.to_s,
      f: 'json',
      fileid0: file_id,
      imgcode: '',
      lang: 'zh_CN',
      preusername: 'nan474947',
      random: rand,
      reward_wording0: '',
      shortvideofileid0: '',
      show_cover_pic0: 1,  # 0 => 封面图片不显示在正文中
      sourceurl0: 'http://thecampus.cc/' + rand.to_s,
      title0: 'test标题' + rand.to_s,
      token: @weixin.token,
      vid: ''
    }
    msg_hash = @weixin.preview_msg(msg_params_with_name)
    expect(msg_hash["ret"].to_s).to eql("0")
  end

=begin
  it 'should reply to yang' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      quick_reply_res_hash = @weixin.quick_reply('测试回复2', 201123100, 204060720)
      puts '==' * 20
      puts quick_reply_res_hash
      expect(quick_reply_res_hash['base_resp']['ret'].to_s).to eql('0')
    end
  end

  it 'should star msg' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      star_res_hash = @weixin.collect_msg('201123100')
      puts '==' * 20
      puts star_res_hash
      expect(star_res_hash['ret'].to_s).to eql('0')
    end
  end

  it 'should un star msg' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      star_res_hash = @weixin.un_collect_msg('201123100')
      puts '==' * 20
      puts star_res_hash
      expect(star_res_hash['ret'].to_s).to eql('0')
    end
  end
=end

  it 'should get fans count' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      fans_res_hash = @weixin.get_fans_count
      expect(fans_res_hash[:status]).to eql(0)
    end
  end

  it 'should get total_count, count, day, frommsgid, can_search_msg, offset, action=search, keyword, last_msg_id, filterivrmsg=0/1 和 msg_items' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      res_hash = @weixin.get_msg_items(20, 7, 1, '', '', '', '')
      expect(res_hash[:status]).to eql(0)
    else
      puts 'init failed'
    end
  end

  it "should get new msg num" do
    res_hash = @weixin.login
    flag = @weixin.init
    msg_res_hash = @weixin.get_msg_items if flag
    res_hash = @weixin.get_new_msg_num(msg_res_hash[:latest_msg_id=])
    expect(res_hash['ret'].to_s).to eql('0')
  end

  it 'should get day msg count' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      day_msg_count = @weixin.get_day_msg_count
      expect(day_msg_count.to_s).to match(/\d*/)
    end
  end

  it 'should get account message' do
    res_hash = @weixin.login
    flag = @weixin.init
    if flag
      account_message_res_hash = @weixin.get_account_message
      expect(account_message_res_hash.count).to eql(3)
    end
  end
{'fraction_non_alphanumeric': 0.12715285252960173, 'fraction_numerical': 0.023546824542518836, 'mean_word_length': 2.694333996023857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '4302543', 'n_tokens_mistral': 3044, 'n_tokens_neox': 2938, 'n_words': 635}