aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311/endpoint/schema.t
diff options
context:
space:
mode:
authorHakim Cassimally <hakim@mysociety.org>2014-03-13 16:56:02 +0000
committerHakim Cassimally <hakim@mysociety.org>2014-10-16 16:56:26 +0000
commitd1fee928f02dbc30d3a38b746155ce5b12be4a1b (patch)
tree5e8bdccbd69863e69098b9aa900c1e71745f8eb5 /t/open311/endpoint/schema.t
parent592f4c0ba0f822b55bb242cb12768ce771599d09 (diff)
Open311 Endpoint
Subsystems include * ::Spark encoding conventions for xml/json * ::Schema using Rx to validate form of inputs and outputs, including validation for, e.g., dates and CSV as part of Open311 Handles following paths: * Open311 attributes for Service Definition http://wiki.open311.org/GeoReport_v2#GET_Service_Definition * POST service request * GET Service Requests * GET Service Request Objects: * ::Service * ::Service::Request
Diffstat (limited to 't/open311/endpoint/schema.t')
-rw-r--r--t/open311/endpoint/schema.t82
1 files changed, 82 insertions, 0 deletions
diff --git a/t/open311/endpoint/schema.t b/t/open311/endpoint/schema.t
new file mode 100644
index 000000000..b669ca4a5
--- /dev/null
+++ b/t/open311/endpoint/schema.t
@@ -0,0 +1,82 @@
+use strict; use warnings;
+
+use Test::More;
+use Test::Exception;
+
+use Data::Rx;
+use Open311::Endpoint;
+
+my $endpoint = Open311::Endpoint->new;
+my $schema = $endpoint->rx;
+
+subtest 'comma tests' => sub {
+
+ dies_ok {
+ my $comma = $schema->make_schema({
+ type => '/open311/comma',
+ });
+ } 'Construction dies on no contents';
+
+ dies_ok {
+ my $comma = $schema->make_schema({
+ type => '/open311/comma',
+ contents => '/open311/status',
+ zirble => 'fleem',
+ });
+ } 'Construction dies on extra arguments';
+
+ my $comma = $schema->make_schema({
+ type => '/open311/comma',
+ contents => '/open311/status',
+ trim => 1,
+ });
+
+ ok ! $comma->check( undef ), 'Undef is not a valid string';
+ ok ! $comma->check( [] ), 'Reference is not a valid string';
+
+ ok ! $comma->check( 'zibble' ), 'invalid string';
+ ok ! $comma->check( 'open,zibble' ), 'an invalid element';
+
+ ok $comma->check( 'open' ), 'single value';
+ ok $comma->check( 'open,closed' ), 'multiple values ok';
+ ok $comma->check( 'open, closed ' ), 'spaces trimmed ok';
+};
+
+subtest 'datetime tests' => sub {
+
+ dies_ok {
+ my $comma = $schema->make_schema({
+ type => '/open311/datetime',
+ zirble => 'fleem',
+ });
+ } 'Construction dies on extra keys';
+
+ my $dt = $schema->make_schema({
+ type => '/open311/datetime',
+ });
+
+ ok ! $dt->check( undef ), 'Undef is not a valid string';
+ ok ! $dt->check( [] ), 'Reference is not a valid string';
+
+ ok ! $dt->check( '9th Feb 2012' ), 'invalid datetime format';
+
+ ok $dt->check( '1994-11-05T08:15:30-05:00' ), 'datetime format with offset';
+ ok $dt->check( '1994-11-05T08:15:30+05:00' ), 'datetime format with positive';
+ ok $dt->check( '1994-11-05T13:15:30Z' ), 'datetime format zulu';
+};
+
+subtest 'identifier tests' => sub {
+ my $id = $schema->make_schema( '/open311/example/identifier' );
+
+ ok ! $id->check( undef ), 'Undef is not a valid string';
+ ok ! $id->check( '' ), 'Empty string is not a valid identifier';
+ ok ! $id->check( 'foo bar' ), 'String with spaces is not a valid identifier';
+
+ ok $id->check( 'foo' ), 'Ascii word string is a valid identifier';
+ ok $id->check( 'foo_bar' ), 'Ascii word string is a valid identifier';
+ ok $id->check( 'foo_123' ), 'Ascii word/num string is a valid identifier';
+};
+
+done_testing;
+
+1;