@@ -21,6 +21,7 @@ module Decorators
21
21
22
22
let ( :consumer ) { Domain ::Pacticipant . new ( name : 'Consumer' ) }
23
23
let ( :provider ) { Domain ::Pacticipant . new ( name : 'Provider' ) }
24
+ let ( :event ) { Webhooks ::WebhookEvent . new ( name : 'something_happened' ) }
24
25
let ( :created_at ) { DateTime . now }
25
26
let ( :updated_at ) { created_at + 1 }
26
27
@@ -30,6 +31,7 @@ module Decorators
30
31
uuid : 'some-uuid' ,
31
32
consumer : consumer ,
32
33
provider : provider ,
34
+ events : [ event ] ,
33
35
created_at : created_at ,
34
36
updated_at : updated_at
35
37
)
@@ -44,26 +46,14 @@ module Decorators
44
46
expect ( parsed_json [ :request ] ) . to eq request
45
47
end
46
48
47
- it 'includes an embedded consumer' do
48
- expect ( parsed_json [ :_embedded ] [ :consumer ] ) . to eq ( {
49
- name : 'Consumer' ,
50
- _links : {
51
- self : {
52
- href : 'http://example.org/pacticipants/Consumer'
53
- }
54
- }
55
- } )
49
+ it 'includes a link to the consumer' do
50
+ expect ( parsed_json [ :_links ] [ :'pb:consumer' ] [ :name ] ) . to eq 'Consumer'
51
+ expect ( parsed_json [ :_links ] [ :'pb:consumer' ] [ :href ] ) . to eq 'http://example.org/pacticipants/Consumer'
56
52
end
57
53
58
- it 'includes an embedded provider' do
59
- expect ( parsed_json [ :_embedded ] [ :provider ] ) . to eq ( {
60
- name : 'Provider' ,
61
- _links : {
62
- self : {
63
- href : 'http://example.org/pacticipants/Provider'
64
- }
65
- }
66
- } )
54
+ it 'includes a link to the provider' do
55
+ expect ( parsed_json [ :_links ] [ :'pb:provider' ] [ :name ] ) . to eq 'Provider'
56
+ expect ( parsed_json [ :_links ] [ :'pb:provider' ] [ :href ] ) . to eq 'http://example.org/pacticipants/Provider'
67
57
end
68
58
69
59
it 'includes a link to itself' do
@@ -83,6 +73,10 @@ module Decorators
83
73
expect ( parsed_json [ :_links ] [ :'pb:execute' ] [ :href ] ) . to eq 'http://example.org/webhooks/some-uuid/execute'
84
74
end
85
75
76
+ it 'includes the events' do
77
+ expect ( parsed_json [ :events ] . first ) . to eq name : 'something_happened'
78
+ end
79
+
86
80
it 'includes timestamps' do
87
81
expect ( parsed_json [ :createdAt ] ) . to eq created_at . xmlschema
88
82
expect ( parsed_json [ :updatedAt ] ) . to eq updated_at . xmlschema
@@ -97,7 +91,8 @@ module Decorators
97
91
end
98
92
99
93
describe 'from_json' do
100
- let ( :hash ) { { request : request } }
94
+ let ( :hash ) { { request : request , events : [ event ] } }
95
+ let ( :event ) { { name : 'something_happened' } }
101
96
let ( :json ) { hash . to_json }
102
97
let ( :webhook ) { Domain ::Webhook . new }
103
98
let ( :parsed_object ) { subject . from_json ( json ) }
@@ -117,6 +112,10 @@ module Decorators
117
112
it 'parses the request body' do
118
113
expect ( parsed_object . request . body ) . to eq 'some' => 'body'
119
114
end
115
+
116
+ it 'parses the events' do
117
+ expect ( parsed_object . events . first . name ) . to eq 'something_happened'
118
+ end
120
119
end
121
120
end
122
121
end
0 commit comments