# typed: false

require 'spec_helper'

describe ReservationPlayer do
  context 'banned asns' do
    it 'doesnt flag good ASNs' do
      good_ip = '1.128.0.1'
      expect(described_class.banned_asn_ip?(good_ip)).to be false
    end

    it 'recognizes bad ASNs' do
      described_class.stub(:custom_banned_asns).and_return([ 1221 ])
      expect(described_class.banned_asn_ip?('1.128.0.1')).to be true
    end

    it 'knows custom range of VPN IPs not from a specific ASN' do
      described_class.stub(:vpn_ranges).and_return([ IPAddr.new('1.129.0.0/24') ])
      expect(described_class.banned_asn_ip?('1.129.0.1')).to be true
    end

    it 'knows SDR ips wont be in the ASN database, so should just return false for those' do
      expect(described_class.banned_asn_ip?('169.254.1.1')).to be false
    end
  end

  context 'banned steam ids' do
    it 'recognizes a banned steam id' do
      expect(described_class.banned_uid?(76561198310925535)).to eql 'match invader'
    end
    it 'doesnt flag a good steam id as banned' do
      expect(described_class.banned_uid?(76561197960497430)).to be_falsy
    end
  end

  context 'whitelisted steam id' do
    it 'recognizes a whitelisted steam id' do
      expect(described_class.whitelisted_uid?(76561198350261670)).to eql 'formerly lived in Russia'
    end

    it 'doesnt flag an unknown steam id as whitelisted' do
      expect(described_class.whitelisted_uid?('foobarwidget')).to be_falsy
    end
  end

  context 'banned ip' do
    it 'recognizes a banned ip in a range' do
      expect(described_class.banned_ip?('109.81.174.1')).to be_truthy
    end
    it 'doesnt flag a good ip as banned' do
      expect(described_class.banned_ip?('127.0.0.1')).to be_falsy
    end
  end
end
