File: 03_live.t

package info (click to toggle)
libmail-chimp3-perl 0.08-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: perl: 801; makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,595 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More;
use JSON;
use Digest::MD5 qw(md5_hex);

BEGIN {
  plan skip_all => '$ENV{MAILCHIMP_APIKEY} not set, skipping live tests' unless defined $ENV{MAILCHIMP_APIKEY}; 

  plan tests => 3;
  use_ok('Mail::Chimp3');
}

my $apikey = $ENV{MAILCHIMP_APIKEY};
my $mailchimp = Mail::Chimp3->new( api_key => $apikey );

my $lists = $mailchimp->lists;
my $list_id = $lists->{content}{lists}[0]->{id};

my %info1 = qw(email_address foo@foobar.com status subscribed);
my %info2 = qw(email_address baz@quux.com status subscribed);
my $batch = [
    {
        method => 'POST',
        path   => "lists/$list_id/members",
        body   => encode_json(\%info1),
    },
    {
        method => 'POST',
        path   => "lists/$list_id/members",
        body   => encode_json(\%info2),
    },
];

#my $listBatchSubscribe_expected = { add_count => 2, error_count => 0, errors => [], update_count => 0 };
my $listBatchSubscribe = $mailchimp->add_batch( operations => $batch );

is(
    $listBatchSubscribe->{code},
    200,
    'listBatchSubscribe succeeded'
);

#my $listBatchUnsubscribe_expected = { success_count => 2, error_count => 0, errors => [] };
my $hash1 = md5_hex('foo@foobar.com');
my $hash2 = md5_hex('baz@quux.com');
my $listBatchUnsubscribe = $mailchimp->add_batch( operations => [
    {
        method => 'DELETE',
        path   => "lists/$list_id/members/$hash1",
    },
    {
        method => 'DELETE',
        path   => "lists/$list_id/members/$hash2",
    },
] );

is(
    $listBatchUnsubscribe->{code},
    200,
    'listBatchUnsubscribe succeeded'
);