File: 02_entity_coercion.t

package info (click to toggle)
libmastodon-client-perl 0.017-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 336 kB
  • sloc: perl: 1,525; makefile: 9
file content (82 lines) | stat: -rw-r--r-- 1,711 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
use Test2::V0;

use Mastodon::Types qw( to_Entity to_Instance );

# Test data uses only minimum arguments for entity constructors
# These were set as required only to aid in automatic detection,
# which makes blind coercion possible
#
my $samples = {
  Account => {
    acct => 'username',
    avatar => 'https://example.tld/image.png',
  },
  Application => {
    website => 'https://website.xyz',
  },
  Attachment => {
    preview_url => 'https://example.tld/image.png',
  },
  Card => {
    description => 'A card',
    url => 'https://website.xyz',
  },
  Context => {
    ancestors => [],
    descendants => [],
  },
  Error => {
    error => 'An error',
  },
  Instance => {
    uri => 'mastodon.social',
  },
  Mention => {
    acct => 'username@instance.xyz',
    username => 'tester',
  },
  Relationship => {
    muting => 0,
  },
  Report => {
    action_taken => 0,
  },
  Results => {
    hashtags => [ 'tag '],
  },
  Tag => {
    url => 'https://website.xyz',
  }
};

$samples->{Status} = {
  account => $samples->{Account},
  visibility => 'public',
  favourites_count => 123,
  application => $samples->{Application},
  media_attachments => [
    $samples->{Attachment},
    $samples->{Attachment},
  ],
  mentions => [
    $samples->{Mention},
    $samples->{Mention},
  ],
};

$samples->{Notification} = {
  status => $samples->{Status},
};

foreach my $name (keys %{$samples}) {
  ok my $e = to_Entity($samples->{$name}), 'Coercion succeeds';
  isa_ok $e, "Mastodon::Entity::$name";
}

ok my $e = to_Instance('mastodon.social'),
  'Coercion of instance from string succeeds';
isa_ok $e, 'Mastodon::Entity::Instance';

like $e->uri, qr/https/, 'Instance defaults to HTTPS';

done_testing();