Skip to content

working unit test example #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions models/core/dim_orgs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ WITH orgs AS (
--prod
SELECT
org_id
, MIN(event_timestamp) AS created_at
FROM {{ ref('signed_in') }}
GROUP BY 1
, org_name
, employee_range
, created_at
FROM {{ ref('org_created') }}

-- --dev
-- SELECT
Expand All @@ -28,7 +29,7 @@ WITH orgs AS (
org_id
, event_timestamp AS sub_created_at
, plan as sub_plan
, price as sub_price
, coalesce(price, 0) as sub_price
FROM {{ ref('subscription_created') }}
)

Expand All @@ -38,7 +39,7 @@ SELECT
, created_at
, num_users
, sub_created_at
, sub_plan
, case when num_users = 1 then 'Individual' else sub_plan end as sub_plan
, sub_price
FROM orgs
LEFT JOIN user_count USING (org_id)
Expand Down
17 changes: 17 additions & 0 deletions models/core/dim_orgs_unit_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
unit_tests:
- name: test_is_individual_sub_plan
description: "Check if individual case when logic categorizes sub plans correctly for num_users equal to 1"
model: dim_orgs
given:
- input: ref('org_created')
rows:
- {org_id: 100000012, org_name: Crow Bar, domain: crowbar.edu, employee_range: 0-9, created_at: 2022-04-01 04:00:03}
- input: ref('user_created')
rows:
- {user_id: 100000021, org_id: 100000012, first_name: Tamara, last_name: Herman, email: [email protected], is_first_user: True, created_at: 2022-04-01T04:00:03Z}
- input: ref('subscription_created')
rows:
- {org_id: 100000011, event_timestamp: 2022-05-20T17:45:32Z, activity: subscribed, plan: Team, price: 99, deployment: SaaS}
expect:
rows:
- {org_id: 100000012, created_at: 2022-04-01 04:00:03, num_users: 1, sub_created_at: null, sub_plan: Individual, sub_price: null}
2 changes: 1 addition & 1 deletion models/syncs/sales_sync.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WITH org_events AS (
*
FROM {{ ref('dim_orgs') }}
LEFT JOIN {{ ref('feature_used') }} USING (org_id)
WHERE sub_plan IS NULL
WHERE sub_plan IS NULL or sub_plan = 'Individual'
)

, final AS (
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dbt-snowflake==1.6.2
dbt-snowflake==1.8.0b3
# dbt-core==1.8.0b2
Loading