Skip to content

Commit

Permalink
chore(pipeline) : Fix unit tests
Browse files Browse the repository at this point in the history
Note : the code was incorrect, thank us for unit testing it.

Side note : ARRAY is unsupported for the `dict` data type in unit tests,
currently, so we have to use SQL, meaning we also have to define each
and every field out there.

Other side note : as a side effect, this checks that the 'profils' field
is made empty when going from 'stg' to 'int' layer with DORA services.
  • Loading branch information
vperron committed Oct 17, 2024
1 parent f4cd11e commit 4f0b7ec
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 34 deletions.
36 changes: 3 additions & 33 deletions pipeline/dbt/models/intermediate/_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,45 +198,15 @@ unit_tests:
model: int_dora__services
description: "Check if the NULL value in the stg file stays null and is not converted to {NULL}"
given:
# Those are only needed to fool DBT's parser, which first enforces that
# all the models referenced in the union are mocked in the test.
- input: ref('stg_dora__services')
format: sql
rows: select 'foo' as id, TRUE as contact_public,
TRUE as cumulable, '2024-07-16' as date_creation,
'2024-09-13' as date_maj,
null as date_suspension,
null as formulaire_en_ligne, null as frais_autres,
'LETTRE DE MOTIVATION' as justificatifs,
'https://dora.inclusion.beta.gouv.fr/services/ass-tremplin-inserti-permis-de-conduire-c-imsn' as lien_source,
'en-presentiel' as modes_accueil,
'autre' as modes_orientation_accompagnateur,
null as modes_orientation_accompagnateur_autres,
ARRAY['modes_orientation_beneficiaire:foo'] as modes_orientation_beneficiaire,
null as modes_orientation_beneficiaire_autres,
'Marquage vélo' as nom,
'Carte de réduction TER' as presentation_resume,
null as presentation_detail,
null as prise_rdv,
ARRAY['profils:foo'] as profils,
null as recurrence,
'dora' as _di_source_id,
'08887e14-cd85-4ec8-85cb-bb7b88d32985' as structure_id,
ARRAY['thematiques:foo'] as thematiques,
ARRAY['types:foo'] as types,
'55' as zone_diffusion_code,
'Meuse' as zone_diffusion_nom,
'departement' as zone_diffusion_type,
ARRAY['pre_requis:foo'] as pre_requis,
null as contact_nom_prenom,
null as courriel,
null as telephone,
ARRAY['frais:foo'] as frais
fixture: stg_dora__services__input
- input: ref('int_brevo__contacts')
format: sql
rows:
select ARRAY['services:bar'] as contact_uids, TRUE as est_interdit, '2021-01-01' as date_di_rgpd_opposition

expect:
rows:
- {id: foo,'structure_id':08887e14-cd85-4ec8-85cb-bb7b88d32985,'frais':ARRAY['foo']}
format: sql
fixture: int_dora__services__expected
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ final AS (
END AS "telephone",
CASE
WHEN services.frais IS NULL THEN NULL
ELSE ARRAY(SELECT services.frais WHERE services.frais IS NOT NULL)
ELSE ARRAY[services.frais]
END AS "frais"


Expand Down
36 changes: 36 additions & 0 deletions pipeline/dbt/tests/fixtures/int_dora__services__expected.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
select
'foo' AS id,
'foo' AS adresse_id,
TRUE AS contact_public,
TRUE AS cumulable,
CAST('2024-07-16' AS DATE) AS date_creation,
CAST('2024-09-13' AS DATE) AS date_maj,
CAST(NULL AS DATE) AS date_suspension,
NULL AS formulaire_en_ligne,
NULL AS frais_autres,
'LETTRE DE MOTIVATION' AS justificatifs,
'https://dora.inclusion.beta.gouv.fr/services/ass-tremplin-inserti-permis-de-conduire-c-imsn' AS lien_source,
'en-presentiel' AS modes_accueil,
'autre' AS modes_orientation_accompagnateur,
NULL AS modes_orientation_accompagnateur_autres,
ARRAY['modes_orientation_beneficiaire:foo'] AS modes_orientation_beneficiaire,
NULL AS modes_orientation_beneficiaire_autres,
'Marquage vélo' AS nom,
'Carte de réduction TER' AS presentation_resume,
NULL AS presentation_detail,
NULL AS prise_rdv,
ARRAY[]::text[] AS profils,
NULL AS recurrence,
'dora' AS source,
'08887e14-cd85-4ec8-85cb-bb7b88d32985' AS structure_id,
ARRAY['thematiques:foo'] AS thematiques,
ARRAY['types:foo'] AS types,
'55' AS zone_diffusion_code,
'Meuse' AS zone_diffusion_nom,
'departement' AS zone_diffusion_type,
ARRAY['pre_requis:foo'] AS pre_requis,
NULL AS page_web,
NULL AS contact_nom_prenom,
NULL AS courriel,
NULL AS telephone,
ARRAY['frais:foo'] AS frais
32 changes: 32 additions & 0 deletions pipeline/dbt/tests/fixtures/stg_dora__services__input.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
select
'foo' as id,
TRUE as contact_public,
TRUE as cumulable, '2024-07-16' as date_creation,
'2024-09-13' as date_maj,
null as date_suspension,
null as formulaire_en_ligne, null as frais_autres,
'LETTRE DE MOTIVATION' as justificatifs,
'https://dora.inclusion.beta.gouv.fr/services/ass-tremplin-inserti-permis-de-conduire-c-imsn' as lien_source,
'en-presentiel' as modes_accueil,
'autre' as modes_orientation_accompagnateur,
null as modes_orientation_accompagnateur_autres,
ARRAY['modes_orientation_beneficiaire:foo'] as modes_orientation_beneficiaire,
null as modes_orientation_beneficiaire_autres,
'Marquage vélo' as nom,
'Carte de réduction TER' as presentation_resume,
null as presentation_detail,
null as prise_rdv,
ARRAY['profils:foo'] as profils,
null as recurrence,
'dora' as _di_source_id,
'08887e14-cd85-4ec8-85cb-bb7b88d32985' as structure_id,
ARRAY['thematiques:foo'] as thematiques,
ARRAY['types:foo'] as types,
'55' as zone_diffusion_code,
'Meuse' as zone_diffusion_nom,
'departement' as zone_diffusion_type,
ARRAY['pre_requis:foo'] as pre_requis,
null as contact_nom_prenom,
null as courriel,
null as telephone,
'frais:foo' as frais

0 comments on commit 4f0b7ec

Please sign in to comment.