Skip to content

Commit

Permalink
fix person fixtures and create place unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Lorena Rodriguez Viruel committed Aug 28, 2024
1 parent b38f98f commit 1405da0
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 2 deletions.
1 change: 1 addition & 0 deletions models/contacts/contacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions models/contacts/tests/contacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/fixtures/contact_initial_expected.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/fixtures/contact_source_table_initial.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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""}"
5 changes: 5 additions & 0 deletions test/fixtures/person_contact_initial.csv
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/fixtures/person_initial_expected.csv
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions test/fixtures/person_source_table_initial.csv
Original file line number Diff line number Diff line change
@@ -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""}"
6 changes: 6 additions & 0 deletions test/fixtures/place_contact_initial.csv
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/fixtures/place_initial_expected.csv
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions test/fixtures/place_source_table_initial.csv
Original file line number Diff line number Diff line change
@@ -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""}"

0 comments on commit 1405da0

Please sign in to comment.