From 1405da0701c7d6deb4380524608d633f792b4bcc Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Tue, 27 Aug 2024 20:11:23 -0400 Subject: [PATCH] fix person fixtures and create place unit test --- models/contacts/contacts.yml | 1 + models/contacts/tests/contacts.yml | 36 +++++++++++++++++++ test/fixtures/contact_initial_expected.csv | 2 +- .../fixtures/contact_source_table_initial.csv | 2 +- test/fixtures/person_contact_initial.csv | 5 +++ test/fixtures/person_initial_expected.csv | 4 +++ test/fixtures/person_source_table_initial.csv | 5 +++ test/fixtures/place_contact_initial.csv | 6 ++++ test/fixtures/place_initial_expected.csv | 5 +++ test/fixtures/place_source_table_initial.csv | 6 ++++ 10 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/person_contact_initial.csv create mode 100644 test/fixtures/person_initial_expected.csv create mode 100644 test/fixtures/person_source_table_initial.csv create mode 100644 test/fixtures/place_contact_initial.csv create mode 100644 test/fixtures/place_initial_expected.csv create mode 100644 test/fixtures/place_source_table_initial.csv diff --git a/models/contacts/contacts.yml b/models/contacts/contacts.yml index a347c2cb..a7294c6e 100644 --- a/models/contacts/contacts.yml +++ b/models/contacts/contacts.yml @@ -60,6 +60,7 @@ models: expression: "{{ env_var('POSTGRES_SCHEMA') }}.contact (uuid) ON DELETE CASCADE" data_tests: - not_null + - unique - relationships: to: ref('contact') field: uuid diff --git a/models/contacts/tests/contacts.yml b/models/contacts/tests/contacts.yml index ae6e22fa..6823e2a8 100644 --- a/models/contacts/tests/contacts.yml +++ b/models/contacts/tests/contacts.yml @@ -17,3 +17,39 @@ unit_tests: expect: format: csv fixture: contact_initial_expected + - name: test_person_model_transformation_and_data_integrity + description: | + This unit test validates the transformation logic in the `person` model and ensures data integrity. + It uses fixture data for `contact` and `couchdb` to test the complete logic. + model: person + overrides: + macros: + is_incremental: false + given: + - input: ref('contact') + format: csv + fixture: person_contact_initial + - input: source('couchdb', "{{ env_var('POSTGRES_TABLE') }}") + format: csv + fixture: person_source_table_initial + expect: + format: csv + fixture: person_initial_expected + - name: test_place_model_transformation_and_data_integrity + description: | + This unit test validates the transformation logic in the `place` model and ensures data integrity. + It uses fixture data for both `contact` and `couchdb` to test the complete logic. + model: place + overrides: + macros: + is_incremental: false + given: + - input: ref('contact') + format: csv + fixture: place_contact_initial + - input: source('couchdb', "{{ env_var('POSTGRES_TABLE') }}") + format: csv + fixture: place_source_table_initial + expect: + format: csv + fixture: place_initial_expected diff --git a/test/fixtures/contact_initial_expected.csv b/test/fixtures/contact_initial_expected.csv index 54c11c72..416d3ed5 100644 --- a/test/fixtures/contact_initial_expected.csv +++ b/test/fixtures/contact_initial_expected.csv @@ -2,4 +2,4 @@ uuid,saved_timestamp,reported,parent_uuid,name,contact_type,phone,phone2,active, c1,2024-08-01 00:00:00,2024-07-31 08:00:00+00,p1,John Doe,person,12345,54321,true,Note 1,C-123,false c2,2024-08-01 00:00:00,2024-07-31 08:00:00+00,p2,Jane Doe,clinic,67890,09876,true,Note 2,C-456,true c3,2024-08-02 00:00:00,2024-07-31 08:00:00+00,p3,Mike Smith,person,11223,33211,false,Note 3,C-789,false -c4,2024-08-02 00:00:00,2024-07-31 08:00:00+00,p4,Sara Connor,district_hospital,44556,65544,true,Note 4,C-101,true +c4,2024-08-02 00:00:00,2024-07-31 08:00:00+00,p4,Sara Smith,district_hospital,44556,65544,true,Note 4,C-101,true diff --git a/test/fixtures/contact_source_table_initial.csv b/test/fixtures/contact_source_table_initial.csv index 673300d4..5c7f0d15 100644 --- a/test/fixtures/contact_source_table_initial.csv +++ b/test/fixtures/contact_source_table_initial.csv @@ -2,4 +2,4 @@ _id,saved_timestamp,_deleted,doc c1,2024-08-01 00:00:00,false,"{""reported_date"": ""1722412800000"", ""parent"": {""_id"": ""p1""}, ""name"": ""John Doe"", ""contact_type"": ""person"", ""phone"": ""12345"", ""alternative_phone"": ""54321"", ""is_active"": ""true"", ""notes"": ""Note 1"", ""contact_id"": ""C-123"", ""muted"": ""false""}" c2,2024-08-01 00:00:00,false,"{""reported_date"": ""1722412800000"", ""parent"": {""_id"": ""p2""}, ""name"": ""Jane Doe"", ""contact_type"": ""clinic"", ""phone"": ""67890"", ""alternative_phone"": ""09876"", ""is_active"": ""true"", ""notes"": ""Note 2"", ""contact_id"": ""C-456"", ""muted"": ""true""}" c3,2024-08-02 00:00:00,false,"{""reported_date"": ""1722412800000"", ""parent"": {""_id"": ""p3""}, ""name"": ""Mike Smith"", ""contact_type"": ""person"", ""phone"": ""11223"", ""alternative_phone"": ""33211"", ""is_active"": ""false"", ""notes"": ""Note 3"", ""contact_id"": ""C-789"", ""muted"": ""false""}" -c4,2024-08-02 00:00:00,false,"{""reported_date"": ""1722412800000"", ""parent"": {""_id"": ""p4""}, ""name"": ""Sara Connor"", ""contact_type"": ""district_hospital"", ""phone"": ""44556"", ""alternative_phone"": ""65544"", ""is_active"": ""true"", ""notes"": ""Note 4"", ""contact_id"": ""C-101"", ""muted"": ""true""}" +c4,2024-08-02 00:00:00,false,"{""reported_date"": ""1722412800000"", ""parent"": {""_id"": ""p4""}, ""name"": ""Sara Smith"", ""contact_type"": ""district_hospital"", ""phone"": ""44556"", ""alternative_phone"": ""65544"", ""is_active"": ""true"", ""notes"": ""Note 4"", ""contact_id"": ""C-101"", ""muted"": ""true""}" diff --git a/test/fixtures/person_contact_initial.csv b/test/fixtures/person_contact_initial.csv new file mode 100644 index 00000000..b0f19e60 --- /dev/null +++ b/test/fixtures/person_contact_initial.csv @@ -0,0 +1,5 @@ +uuid,saved_timestamp,contact_type +p1,2024-08-01 00:00:00,person +p2,2024-08-01 00:00:00,person +p3,2024-08-02 00:00:00,clinic +p4,2024-08-02 00:00:00,clinic diff --git a/test/fixtures/person_initial_expected.csv b/test/fixtures/person_initial_expected.csv new file mode 100644 index 00000000..886f8432 --- /dev/null +++ b/test/fixtures/person_initial_expected.csv @@ -0,0 +1,4 @@ +uuid,saved_timestamp,date_of_birth,sex +p1,2024-08-01 00:00:00,1980-01-01,M +p2,2024-08-01 00:00:00,1990-05-15,F + diff --git a/test/fixtures/person_source_table_initial.csv b/test/fixtures/person_source_table_initial.csv new file mode 100644 index 00000000..b36b1f6c --- /dev/null +++ b/test/fixtures/person_source_table_initial.csv @@ -0,0 +1,5 @@ +_id,saved_timestamp,_deleted,doc +p1,2024-08-01 00:00:00,false,"{""date_of_birth"": ""1980-01-01"", ""sex"": ""M""}" +p2,2024-08-01 00:00:00,false,"{""date_of_birth"": ""1990-05-15"", ""sex"": ""F""}" +p3,2024-08-02 00:00:00,false,"{""type"": ""clinic""}" +p4,2024-08-02 00:00:00,false,"{""type"": ""clinic""}" diff --git a/test/fixtures/place_contact_initial.csv b/test/fixtures/place_contact_initial.csv new file mode 100644 index 00000000..a38e1ef6 --- /dev/null +++ b/test/fixtures/place_contact_initial.csv @@ -0,0 +1,6 @@ +uuid,saved_timestamp,contact_type +p1,2024-08-01 00:00:00,clinic +p2,2024-08-01 00:00:00,health_center +p3,2024-08-02 00:00:00,district_hospital +p4,2024-08-02 00:00:00,person +p5,2024-08-02 00:00:00,contact diff --git a/test/fixtures/place_initial_expected.csv b/test/fixtures/place_initial_expected.csv new file mode 100644 index 00000000..391f3dff --- /dev/null +++ b/test/fixtures/place_initial_expected.csv @@ -0,0 +1,5 @@ +uuid,saved_timestamp,place_id +p1,2024-08-01 00:00:00,P-001 +p2,2024-08-01 00:00:00,P-002 +p3,2024-08-02 00:00:00,P-003 +p5,2024-08-02 00:00:00,P-004 diff --git a/test/fixtures/place_source_table_initial.csv b/test/fixtures/place_source_table_initial.csv new file mode 100644 index 00000000..36781c54 --- /dev/null +++ b/test/fixtures/place_source_table_initial.csv @@ -0,0 +1,6 @@ +_id,saved_timestamp,_deleted,doc +p1,2024-08-01 00:00:00,false,"{""place_id"": ""P-001"", ""type"": ""clinic""}" +p2,2024-08-01 00:00:00,false,"{""place_id"": ""P-002"", ""type"": ""health_center""}" +p3,2024-08-02 00:00:00,false,"{""place_id"": ""P-003"", ""type"": ""district_hospital""}" +p4,2024-08-02 00:00:00,false,"{""type"": ""person""}" +p5,2024-08-02 00:00:00,false,"{""place_id"": ""P-004"", ""type"": ""contact""}"