From 150d8f02587c22076e5e22791fb7dd178a175587 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Tue, 27 Aug 2024 14:52:56 -0400 Subject: [PATCH] add unit test to contacts --- models/contacts/contacts.yml | 11 +++++++++-- models/contacts/tests/contacts.yml | 19 +++++++++++++++++++ .../contact_document_metadata_initial.csv | 5 +++++ test/fixtures/contact_initial_expected.csv | 6 ++++++ .../fixtures/contact_source_table_initial.csv | 5 +++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 models/contacts/tests/contacts.yml create mode 100644 test/fixtures/contact_document_metadata_initial.csv create mode 100644 test/fixtures/contact_initial_expected.csv create mode 100644 test/fixtures/contact_source_table_initial.csv diff --git a/models/contacts/contacts.yml b/models/contacts/contacts.yml index 5de80d54..a347c2cb 100644 --- a/models/contacts/contacts.yml +++ b/models/contacts/contacts.yml @@ -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 @@ -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 diff --git a/models/contacts/tests/contacts.yml b/models/contacts/tests/contacts.yml new file mode 100644 index 00000000..ae6e22fa --- /dev/null +++ b/models/contacts/tests/contacts.yml @@ -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 diff --git a/test/fixtures/contact_document_metadata_initial.csv b/test/fixtures/contact_document_metadata_initial.csv new file mode 100644 index 00000000..5711115f --- /dev/null +++ b/test/fixtures/contact_document_metadata_initial.csv @@ -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 diff --git a/test/fixtures/contact_initial_expected.csv b/test/fixtures/contact_initial_expected.csv new file mode 100644 index 00000000..479e81ac --- /dev/null +++ b/test/fixtures/contact_initial_expected.csv @@ -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 + diff --git a/test/fixtures/contact_source_table_initial.csv b/test/fixtures/contact_source_table_initial.csv new file mode 100644 index 00000000..b347c373 --- /dev/null +++ b/test/fixtures/contact_source_table_initial.csv @@ -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""}"