Skip to content

Commit

Permalink
add unit test to contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Lorena Rodriguez Viruel committed Aug 27, 2024
1 parent a4c0608 commit 150d8f0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
11 changes: 9 additions & 2 deletions models/contacts/contacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@ models:
- type: unique
data_tests:
- not_null
- unique
- relationships:
to: ref('document_metadata')
field: uuid
- name: saved_timestamp
data_type: timestamp
data_tests:
- not_null
- name: reported
data_type: timestamp with time zone
data_tests:
- not_null
- name: parent_uuid
data_type: string
- name: name
data_type: string
data_tests:
- not_null
- name: contact_type
data_type: string
data_tests:
- not_null
- name: phone
data_type: string
- name: phone2
Expand All @@ -37,8 +46,6 @@ models:
data_type: string
- name: contact_id
data_type: string
- name: contact_id
data_type: string
- name: muted
data_type: string
- name: person
Expand Down
19 changes: 19 additions & 0 deletions models/contacts/tests/contacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
unit_tests:
- name: test_contact_model_transformation_and_data_integrity
description: |
This unit test validates the transformation logic in the `contact` model and ensures data integrity.
It uses fixture data for both `document_metadata` and `source_table` to test the complete logic.
model: contact
overrides:
macros:
is_incremental: false
given:
- input: ref('document_metadata')
format: csv
fixture: contact_document_metadata_initial
- input: source('couchdb', "{{ env_var('POSTGRES_TABLE') }}")
format: csv
fixture: contact_source_table_initial
expect:
format: csv
fixture: contact_initial_expected
5 changes: 5 additions & 0 deletions test/fixtures/contact_document_metadata_initial.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
uuid,saved_timestamp,doc_type,_deleted
c1,2024-08-01 00:00:00,contact,false
c2,2024-08-01 00:00:00,clinic,false
c3,2024-08-02 00:00:00,person,false
c4,2024-08-02 00:00:00,district_hospital,false
6 changes: 6 additions & 0 deletions test/fixtures/contact_initial_expected.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
uuid,saved_timestamp,reported,parent_uuid,name,contact_type,phone,phone2,active,notes,contact_id,muted
c1,2024-08-01 00:00:00,2024-08-01 00:00:00+00,p1,John Doe,person,12345,54321,true,Note 1,C-123,false
c2,2024-08-01 00:00:00,2024-08-01 00:00:00+00,p2,Jane Doe,clinic,67890,09876,true,Note 2,C-456,true
c3,2024-08-02 00:00:00,2024-08-01 00:00:00+00,p3,Mike Smith,person,11223,33211,false,Note 3,C-789,false
c4,2024-08-02 00:00:00,2024-08-01 00:00:00+00,p4,Sara Connor,district_hospital,44556,65544,true,Note 4,C-101,true

5 changes: 5 additions & 0 deletions test/fixtures/contact_source_table_initial.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_id,saved_timestamp,_deleted,doc
c1,2024-08-01 00:00:00,false,"{""reported_date"": ""1714857600000"", ""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"": ""1714857600000"", ""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"": ""1714857600000"", ""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"": ""1714857600000"", ""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""}"

0 comments on commit 150d8f0

Please sign in to comment.