irmago_test.go 1.34 KB
Newer Older
1
package irma
2
3

import (
4
	"encoding/json"
Sietse Ringers's avatar
Sietse Ringers committed
5
	"testing"
6

Sietse Ringers's avatar
Sietse Ringers committed
7
	"github.com/stretchr/testify/require"
8
9
)

10
func TestAttributeDisjunctionMarshaling(t *testing.T) {
11
	conf, err := NewConfiguration("testdata/irma_configuration", "")
12
	require.NoError(t, err)
13
	require.NoError(t, conf.ParseFolder())
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
	disjunction := AttributeDisjunction{}

	var _ json.Unmarshaler = &disjunction
	var _ json.Marshaler = &disjunction

	id := NewAttributeTypeIdentifier("MijnOverheid.ageLower.over18")

	attrsjson := `
	{
		"label": "Over 18",
		"attributes": {
			"MijnOverheid.ageLower.over18": "yes",
			"Thalia.age.over18": "Yes"
		}
	}`
	require.NoError(t, json.Unmarshal([]byte(attrsjson), &disjunction))
	require.True(t, disjunction.HasValues())
	require.Contains(t, disjunction.Attributes, id)
	require.Contains(t, disjunction.Values, id)
	require.Equal(t, disjunction.Values[id], "yes")

	disjunction = AttributeDisjunction{}
	attrsjson = `
	{
		"label": "Over 18",
		"attributes": [
			"MijnOverheid.ageLower.over18",
			"Thalia.age.over18"
		]
	}`
	require.NoError(t, json.Unmarshal([]byte(attrsjson), &disjunction))
	require.False(t, disjunction.HasValues())
	require.Contains(t, disjunction.Attributes, id)

48
	require.True(t, disjunction.MatchesConfig(conf))
49
50
51
52
53

	require.False(t, disjunction.Satisfied())
	disjunction.selected = &disjunction.Attributes[0]
	require.True(t, disjunction.Satisfied())
}