Skip to content

Commit

Permalink
add generic test and unit test for users model
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Lorena Rodriguez Viruel committed Aug 27, 2024
1 parent 1fea79b commit a4c0608
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 8 deletions.
8 changes: 3 additions & 5 deletions models/root/tests/document_metadata.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
unit_tests:
- name: test_document_metadata
description: |
This unit test validates the transformation logic in the `document_metadata` model
for the first test scenario, ensuring that the input data from `source_table` is correctly transformed.
model: document_metadata
overrides:
macros:
is_incremental: false
given:
- input: source('couchdb', "{{ env_var('POSTGRES_TABLE') }}")
format: csv
fixture: contacts_initial_data
fixture: document_metadata_initial
expect:
format: csv
fixture: contacts_document_metadata_initial_expected
fixture: document_metadata_initial_expected

19 changes: 19 additions & 0 deletions models/users/tests/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
unit_tests:
- name: test_user_model_transformation_and_data_integrity
description: |
This unit test validates the transformation logic in the `user` model and ensures data integrity.
It uses fixture data for both `document_metadata` and `source_table` to test the complete logic.
model: user
overrides:
macros:
is_incremental: false
given:
- input: ref('document_metadata')
format: csv
fixture: user_document_metadata_initial
- input: source('couchdb', "{{ env_var('POSTGRES_TABLE') }}")
format: csv
fixture: user_source_table_initial
expect:
format: csv
fixture: user_initial_expected
7 changes: 7 additions & 0 deletions models/users/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ models:
field: uuid
- name: saved_timestamp
data_type: timestamp
data_tests:
- not_null
- name: contact_uuid
data_type: string
data_tests:
- not_null
- relationships:
to: ref('contact')
field: uuid
- name: language
data_type: string
- name: roles
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions test/fixtures/user_document_metadata_initial.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
uuid,_deleted,saved_timestamp,doc_type
1,false,2024-08-01 00:00:00,user-settings
2,false,2024-08-01 00:00:00,user-settings
3,false,2024-08-02 00:00:00,user-settings
4,false,2024-08-02 00:00:00,user-settings
5,true,2024-08-02 00:00:00,other-type

7 changes: 7 additions & 0 deletions test/fixtures/user_initial_expected.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
user_id,saved_timestamp,contact_uuid,language,roles
1,2024-08-01 00:00:00,1001,en,admin
2,2024-08-01 00:00:00,1002,fr,user
3,2024-08-02 00:00:00,1003,es,guest
4,2024-08-02 00:00:00,1004,de,user


7 changes: 7 additions & 0 deletions test/fixtures/user_source_table_initial.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
saved_timestamp,_id,_deleted,doc
2024-08-01 00:00:00,1,false,"{""type"": ""user-settings"", ""contact_id"": ""1001"", ""language"": ""en"", ""roles"": ""admin""}"
2024-08-01 00:00:00,2,false,"{""type"": ""user-settings"", ""facility_id"": ""1002"", ""language"": ""fr"", ""roles"": ""user""}"
2024-08-02 00:00:00,3,false,"{""type"": ""user-settings"", ""contact_id"": ""1003"", ""language"": ""es"", ""roles"": ""guest""}"
2024-08-02 00:00:00,4,false,"{""type"": ""user-settings"", ""contact_id"": ""1004"", ""language"": ""de"", ""roles"": ""user""}"
2024-08-02 00:00:00,5,true,"{""type"": ""other-type"", ""contact_id"": ""1005"", ""language"": ""it"", ""roles"": ""admin""}"

3 changes: 0 additions & 3 deletions test/sqltest/document_metadata_post_hook_deletes.sql

This file was deleted.

0 comments on commit a4c0608

Please sign in to comment.