From cfe34795b1d9db7ada11d18c4f76444060cdf60d Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 2 Jan 2018 17:18:39 +0000 Subject: better structure, and test, for License --- lib/Ultramarine/Controller.pm6 | 7 ++++++- lib/Ultramarine/Model/License.pm6 | 10 +++------- t/tests/model/license.t | 12 ++++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 t/tests/model/license.t diff --git a/lib/Ultramarine/Controller.pm6 b/lib/Ultramarine/Controller.pm6 index 208a50b..f5cbd64 100644 --- a/lib/Ultramarine/Controller.pm6 +++ b/lib/Ultramarine/Controller.pm6 @@ -53,9 +53,14 @@ class Ultramarine::Controller { before $!authorisation; post -> 'ping' { respond [] } post -> 'getLicense' { + my $expires = $.license.expires-at.DateTime.truncated-to('second'); respond [ :status, - license => [ |%($.license.status) ], + license => [ + :valid($.license.is-valid.Str.lc), + :email($.license.email), + :licenseExpires($expires.yyyy-mm-dd ~ ':' ~ $expires.hh-mm-ss), + ], ], } post -> 'getMusicFolders' { diff --git a/lib/Ultramarine/Model/License.pm6 b/lib/Ultramarine/Model/License.pm6 index 2ceeaa5..26380e0 100644 --- a/lib/Ultramarine/Model/License.pm6 +++ b/lib/Ultramarine/Model/License.pm6 @@ -1,11 +1,7 @@ use v6.d.PREVIEW; class Ultramarine::Model::License { - method status() { - return { - :valid, - :email, - :licenseExpires<2019-01-01:00:00:00>, - } - } + method is-valid() { True } + method email() { 'foo@bar.com' } + method expires-at { now.DateTime.later(:2years).Instant } } diff --git a/t/tests/model/license.t b/t/tests/model/license.t new file mode 100644 index 0000000..d7e7993 --- /dev/null +++ b/t/tests/model/license.t @@ -0,0 +1,12 @@ +use v6.d.PREVIEW; +use Test; +use Ultramarine::Model::License; + +my Ultramarine::Model::License $l .= new; + +ok($l.is-valid,'the license should always be valid'); +ok($l.email,'the license should have an email address'); +ok($l.expires-at > now, 'the license should never expire'); + +done-testing; + -- cgit v1.2.3