@@ -8,6 +8,44 @@ import (
88 "github.com/zorgbijjou/golang-fhir-models/fhir-models/fhir"
99)
1010
11+ // Test that the generic validators do their job. At this point, this only checks whether
12+ // the resource is of an allowed type before deferring to a resource-specific function.
13+ func TestGenericValidators (t * testing.T ) {
14+ resources := []struct {
15+ name string
16+ resourceJSON []byte
17+ valid bool
18+ }{
19+ {
20+ name : "valid Organization" ,
21+ resourceJSON : []byte (`{"resourceType":"Organization", "identifier":[{"system":"http://fhir.nl/fhir/NamingSystem/ura","value":"12345"}]}` ),
22+ valid : true ,
23+ },
24+ {
25+ name : "invalid resource type" ,
26+ resourceJSON : []byte (`{"resourceType":"Patient"}` ),
27+ valid : false ,
28+ },
29+ }
30+
31+ for _ , tt := range resources {
32+ t .Run (tt .name , func (t * testing.T ) {
33+ err := ValidateUpdate (t .Context (), ValidationRules {AllowedResourceTypes : []string {"Organization" }}, tt .resourceJSON )
34+
35+ if tt .valid {
36+ require .NoError (t , err )
37+ } else {
38+ require .Error (t , err )
39+ }
40+ })
41+ }
42+
43+ }
44+
45+ // Test validator for Organization resources. An organization should either have an URA number
46+ // or should be a sub-organization to an Organization with an URA number.
47+ //
48+ // https://nuts-foundation.github.io/nl-generic-functions-ig/care-services.html#update-client
1149func TestOrganizationValidator (t * testing.T ) {
1250 organizations := []struct {
1351 name string
@@ -79,12 +117,12 @@ func TestOrganizationValidator(t *testing.T) {
79117
80118 for _ , tt := range organizations {
81119 t .Run (tt .name , func (t * testing.T ) {
82- err2 := validateOrganizationResource (t .Context (), & tt .organization )
120+ err := validateOrganizationResource (t .Context (), & tt .organization )
83121
84122 if tt .valid {
85- require .NoError (t , err2 )
123+ require .NoError (t , err )
86124 } else {
87- require .Error (t , err2 )
125+ require .Error (t , err )
88126 }
89127 })
90128 }
0 commit comments