File: account_api_client_spec.rb

package info (click to toggle)
ruby-postmark 1.25.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 480 kB
  • sloc: ruby: 5,413; makefile: 4
file content (124 lines) | stat: -rw-r--r-- 4,211 bytes parent folder | download
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
require 'spec_helper'

describe 'Account API client usage' do

  subject { Postmark::AccountApiClient.new(ENV['POSTMARK_ACCOUNT_API_KEY'],
                                           :http_open_timeout => 15,
                                           :http_read_timeout => 15) }
  let(:unique_token) { rand(36**32).to_s(36) }
  let(:unique_from_email) { ENV['POSTMARK_CI_SENDER'].gsub(/(\+.+)?@/, "+#{unique_token}@") }

  it 'manage senders' do
    # create & count
    new_sender = subject.create_sender(:name => 'Integration Test', :from_email => unique_from_email)
    expect(subject.get_senders_count).to be > 0

    # get
    expect(subject.get_sender(new_sender[:id])[:id]).to eq(new_sender[:id])

    # list
    senders = subject.get_senders(:count => 50)
    expect(senders.map { |s| s[:id] }).to include(new_sender[:id])

    # collection
    expect(subject.senders.map { |s| s[:id] }).to include(new_sender[:id])

    # update
    updated_sender = subject.update_sender(new_sender[:id], :name => 'New Name')
    expect(updated_sender[:name]).to eq('New Name')
    expect(updated_sender[:id]).to eq(new_sender[:id])


    # spf
    expect(subject.verified_sender_spf?(new_sender[:id])).to be true

    # resend
    expect { subject.resend_sender_confirmation(new_sender[:id]) }.not_to raise_error

    # dkim
    expect { subject.request_new_sender_dkim(new_sender[:id]) }.
        to raise_error(Postmark::InvalidMessageError,
                       'This DKIM is already being renewed.')

    # delete
    expect { subject.delete_sender(new_sender[:id]) }.not_to raise_error
  end

  it 'manage domains' do
    domain_name = "#{unique_token}-gem-integration.test"
    return_path = "return.#{domain_name}"
    updated_return_path = "updated-return.#{domain_name}"

    # create & count
    new_domain = subject.create_domain(:name => domain_name,
                                       :return_path_domain => return_path)
    expect(subject.get_domains_count).to be > 0

    # get
    expect(subject.get_domain(new_domain[:id])[:id]).to eq(new_domain[:id])

    # list
    domains = subject.get_domains(:count => 50)
    expect(domains.map { |d| d[:id] }).to include(new_domain[:id])

    # collection
    expect(subject.domains.map { |d| d[:id] }).to include(new_domain[:id])

    # update
    updated_domain = subject.update_domain(new_domain[:id], :return_path_domain => updated_return_path)
    expect(updated_domain[:return_path_domain]).to eq(updated_return_path)
    expect(updated_domain[:id]).to eq(new_domain[:id])

    # spf
    expect(subject.verified_domain_spf?(new_domain[:id])).to be true

    # dkim
    expect { subject.rotate_domain_dkim(new_domain[:id]) }.
        to raise_error(Postmark::InvalidMessageError,
                       'This DKIM is already being renewed.')

    # delete
    expect { subject.delete_domain(new_domain[:id]) }.not_to raise_error
  end

  it 'manage servers' do
    # create & count
    new_server = subject.create_server(:name => "server-#{unique_token}",
                                       :color => 'red')
    expect(subject.get_servers_count).to be > 0

    # get
    expect(subject.get_server(new_server[:id])[:id]).to eq(new_server[:id])

    # list
    servers = subject.get_servers(:count => 50)
    expect(servers.map { |s| s[:id] }).to include(new_server[:id])

    # collection
    expect(subject.servers.map { |s| s[:id] }).to include(new_server[:id])

    # update
    updated_server = subject.update_server(new_server[:id], :color => 'blue')
    expect(updated_server[:color]).to eq('blue')
    expect(updated_server[:id]).to eq(new_server[:id])

    # delete
    expect { subject.delete_server(new_server[:id]) }.not_to raise_error
  end

  it 'manages data removals' do
    # create
    data_removal_status = subject.request_data_removal(
      'requested_by' => 'sender@postmarkapp.com',
      'requested_for' => 'test@example.com',
      'notify_when_completed' => false
    )

    expect(data_removal_status[:status]).to eq('Pending')

    # get
    fetched_data_removal_status = subject.get_data_removal_status(data_removal_status[:id])

    expect(fetched_data_removal_status[:id]).to eq(data_removal_status[:id])
  end
end