diff schema/auth_tests.sql @ 2230:4374d942b23d

Remove debris and associate templates to country While the original idea was to associate templates to users, managed by a waterway admin per country, the new intention was to share templates between users per country. Just removing any constraints on readability and management of the templates did not fulfill this idea.
author Tom Gottfried <tom@intevation.de>
date Wed, 13 Feb 2019 10:52:14 +0100
parents b66cfcde8ff7
children 5470aa3ffb9a
line wrap: on
line diff
--- a/schema/auth_tests.sql	Wed Feb 13 08:00:26 2019 +0100
+++ b/schema/auth_tests.sql	Wed Feb 13 10:52:14 2019 +0100
@@ -36,16 +36,15 @@
     $$,
     'Only staged data should be visible');
 
---SELECT isnt_empty($$
---    SELECT * FROM users.templates
---    $$,
---    'User should see templates associated to him');
---SELECT is_empty($$
---    SELECT * FROM users.templates
---        JOIN users.user_templates USING (template_name)
---        WHERE username <> current_user
---    $$,
---    'User should only see templates associated to him');
+SELECT isnt_empty($$
+    SELECT * FROM users.templates
+    $$,
+    'User should see templates associated to his country');
+
+SELECT ok(
+    users.current_user_country() = ALL(
+        SELECT country FROM users.templates),
+    'User should only see templates associated to his country');
 
 --
 -- Run tests as waterway administrator
@@ -79,26 +78,22 @@
     'Waterway admin cannot insert data outside his region');
 
 -- template management
---SELECT isnt_empty($$
---    SELECT * FROM users.templates
---        JOIN users.user_templates USING (template_name)
---        WHERE username <> current_user
---    $$,
---    'Waterway admin should see templates of other users');
+SELECT results_eq($$
+    SELECT users.current_user_country()
+    $$,
+    $$
+    INSERT INTO users.templates (template_name, template_data)
+        VALUES ('New AT', '\x')
+        RETURNING country
+    $$,
+    'Waterway admin can add templates for his country');
 
---SELECT lives_ok($$
---    INSERT INTO users.templates (template_name, template_data)
---        VALUES ('New AT', '\x');
---        INSERT INTO users.user_templates
---        VALUES ('test_user_at', 'New AT')
---    $$,
---    'Waterway admin can add templates for users in his country');
-
---SELECT throws_ok($$
---    INSERT INTO users.user_templates VALUES ('waterway_user2', 'AT')
---    $$,
---    42501, NULL,
---    'Waterway admin cannot add template for other country');
+SELECT throws_ok($$
+    INSERT INTO users.templates (template_name, template_data, country)
+        VALUES ('New RO', '\x', 'RO')
+    $$,
+    42501, NULL,
+    'Waterway admin cannot add template for other country');
 
 SELECT isnt_empty($$
     UPDATE users.templates SET template_data = '\xDABE'