### ----------------------------------------------------
### -- Updown
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/02-check.rakutest
### ----------------------------------------------------
use Test;
use JSON::Fast;
use Updown;

plan 23;

my $json := q:to/JSON/;
{
  "token": "ngg8",
  "url": "https://updown.io",
  "alias": "",
  "last_status": 200,
  "uptime": 100.0,
  "down": false,
  "down_since": null,
  "error": null,
  "period": 30,
  "apdex_t": 0.5,
  "string_match": "",
  "enabled": true,
  "published": true,
  "disabled_locations": ["tok"],
  "last_check_at": "2016-02-07T13:59:51Z",
  "next_check_at": "2016-02-07T14:00:21Z",
  "mute_until": null,
  "favicon_url": "https://updown.io/favicon.png",
  "custom_headers": {},
  "http_verb": "GET/HEAD",
  "http_body": null,
  "ssl": {
    "tested_at": "2016-02-07T13:30:08Z",
    "expires_at": "2017-08-30T23:59:59Z",
    "valid": true,
    "error": null
  }
}
JSON

my $check := Updown::Check.new: from-json $json;
isa-ok $check, Updown::Check;

for (
  "token",          "ngg8",
  "url",            "https://updown.io",
  "alias",          "",
  "last_status",    200,
  "uptime",         100.0,
  "down",           False,
  "down_since",     Any,
  "error",          Any,
  "period",         30,
  "apdex_t",        0.5,
  "string_match",   "",
  "enabled",        True,
  "published",      True,
  "last_check_at",  "2016-02-07T13:59:51Z".DateTime,
  "next_check_at",  "2016-02-07T14:00:21Z".DateTime,
  "mute_until",     Any,
  "favicon_url",    "https://updown.io/favicon.png",
  "custom_headers", {},
  "http_verb",      "GET/HEAD",
  "http_body",      Any,
) -> $method, $value {
    is-deeply $check."$method"(), $value, "is $method ok";
}

# troublesome check
is $check.disabled_locations, "tok", 'is disabled_locations ok';

my $ssl := $check.ssl;
isa-ok $ssl, Updown::Check::SSL;

# ssl subchecks
for (
) -> $method, $value {
    is-deeply $ssl."$method"(), $value, "is $method ok on ssl";
}

# vim: expandtab shiftwidth=4


