diff --git a/main.sql b/main.sql index a3b7fac..f9321a0 100644 --- a/main.sql +++ b/main.sql @@ -16,7 +16,10 @@ VALUES ( $application_bank_account_number, $application_is_rejected, $application_date_of_birth, - $application_customer_type + CASE + WHEN LOWER(TRIM($application_customer_type::text)) = 'uprwebnew' THEN 'Direct New' + ELSE $application_customer_type + END ) ON CONFLICT (application_key) DO UPDATE @@ -26,4 +29,4 @@ DO UPDATE application_bank_account_number = EXCLUDED.application_bank_account_number, application_is_rejected = EXCLUDED.application_is_rejected, application_date_of_birth = EXCLUDED.application_date_of_birth, - application_customer_type = EXCLUDED.application_customer_type; \ No newline at end of file + application_customer_type = EXCLUDED.application_customer_type; diff --git a/test_block.py b/test_block.py new file mode 100644 index 0000000..807d634 --- /dev/null +++ b/test_block.py @@ -0,0 +1,22 @@ +import json +import unittest +from pathlib import Path + + +BLOCK_DIR = Path(__file__).resolve().parent + + +class TestDbPushV1SqlContract(unittest.TestCase): + def test_application_customer_type_direct_new_mapping(self): + schema = json.loads((BLOCK_DIR / "request_schema.json").read_text()) + sql = (BLOCK_DIR / "main.sql").read_text().lower() + + self.assertEqual(schema["properties"]["application_customer_type"]["type"], ["string", "null"]) + self.assertNotIn("application_source_name", schema["properties"]) + self.assertIn("$application_customer_type::text", sql) + self.assertIn("= 'uprwebnew' then 'direct new'", sql) + self.assertIn("else $application_customer_type", sql) + + +if __name__ == "__main__": + unittest.main()