/
proto_event_spec.rb
54 lines (50 loc) · 1.49 KB
/
proto_event_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
48
49
50
51
52
53
54
# frozen_string_literal: true
require "spec_helper"
module RubyEventStore
module Protobuf
module Mappers
module Transformation
::RSpec.describe ProtoEvent do
include ProtobufHelper
before(:each) { require_protobuf_dependencies }
let(:time) { Time.now.utc }
let(:uuid) { SecureRandom.uuid }
let(:event) do
TestEvent.new(
event_id: uuid,
data: {
some: "value"
},
metadata: {
some: "meta",
timestamp: time,
valid_at: time
}
)
end
let(:record) do
Record.new(
event_id: uuid,
metadata: {
some: "meta"
},
data: ResTesting::OrderCreated.new(customer_id: 123, order_id: "K3THNX9"),
event_type: "res_testing.OrderCreated",
timestamp: time,
valid_at: time
)
end
specify "#load" do
loaded = ProtoEvent.new.load(record)
expect(loaded).to be_a(Proto)
expect(loaded.event_id).to eq(uuid)
expect(loaded.data).to be_a(ResTesting::OrderCreated)
expect(loaded.metadata.to_h).to eq(event.metadata.to_h)
expect(loaded.metadata[:timestamp]).to eq(time)
expect(loaded.metadata[:valid_at]).to eq(time)
end
end
end
end
end
end