-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafelyx_spec.rb
91 lines (71 loc) · 2.87 KB
/
safelyx_spec.rb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# frozen_string_literal: true
require 'rspec'
require_relative 'safelyx'
RSpec.describe Safelyx::Client do
let(:key_code) { ENV.fetch('TEST_KEY_CODE', nil) }
let(:client) { described_class.new(key_code) }
describe '#check_link' do
it 'can check a link' do
result = client.check_link('example.com')
expect(result[:url]).to eq('https://example.com')
expect([-2, *(8..10)]).to include(result[:result])
expect(result[:result_text]).not_to be_empty
expect(result[:date]).not_to be_empty
analysis = result[:analysis]
expect(analysis[:domain_reputation]).not_to be_empty
expect(analysis[:source_code]).not_to be_empty
expect(analysis[:anti_virus]).not_to be_empty
expect(result[:checks_remaining]).to be >= 0
end
end
describe '#check_email' do
it 'can check an email' do
result = client.check_email('[email protected]')
expect(result[:email]).to eq('[email protected]')
expect([-2, *(8..10)]).to include(result[:result])
expect(result[:result_text]).not_to be_empty
expect(result[:date]).not_to be_empty
analysis = result[:analysis]
expect(analysis[:address]).not_to be_empty
expect(analysis[:domain_reputation]).not_to be_empty
expect(analysis[:mx_records]).not_to be_empty
expect(result[:checks_remaining]).to be >= 0
end
end
describe '#check_message' do
it 'can check a message' do
result = client.check_message('Hello, world!')
expect(result[:message]).to eq('Hello, world!')
expect([-2, *(8..10)]).to include(result[:result])
expect(result[:result_text]).not_to be_empty
expect(result[:date]).not_to be_empty
analysis = result[:analysis]
expect(analysis[:content]).not_to be_empty
expect(analysis[:sentiment]).not_to be_empty
expect(analysis[:links]).to be_an(Array)
expect(analysis[:emails]).to be_an(Array)
expect(result[:checks_remaining]).to be >= 0
end
end
describe '#check_image' do
it 'can check an image' do
image_url = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
result = client.check_image(image_url)
expect(result[:image_url]).to eq(image_url)
expect([-2, *(8..10)]).to include(result[:result])
expect(result[:result_text]).not_to be_empty
expect(result[:date]).not_to be_empty
analysis = result[:analysis]
expect(analysis[:description]).not_to be_empty
link = analysis[:link]
expect(link[:url]).not_to be_empty
expect(link[:result]).to be >= -1
expect(link[:date]).not_to be_empty
link_analysis = link[:analysis]
expect(link_analysis[:domain_reputation]).not_to be_empty
expect(link_analysis[:source_code]).not_to be_empty
expect(link_analysis[:anti_virus]).not_to be_empty
expect(result[:checks_remaining]).to be >= 0
end
end
end