-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_integration.rb
More file actions
78 lines (64 loc) · 1.8 KB
/
test_integration.rb
File metadata and controls
78 lines (64 loc) · 1.8 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby
# Simple integration test for eval hooks functionality
puts "Testing eval hooks integration..."
# Load the eval hooks classes
require_relative 'lib/devcycle-ruby-server-sdk/eval_hooks_runner'
require_relative 'lib/devcycle-ruby-server-sdk/models/eval_hook'
require_relative 'lib/devcycle-ruby-server-sdk/models/eval_hook_context'
# Test the eval hooks classes work together
puts "\n1. Testing EvalHooksRunner with EvalHook..."
runner = DevCycle::EvalHooksRunner.new
hook = DevCycle::EvalHook.new(
before: ->(context) {
puts " Before hook called with key: #{context.key}"
context
},
after: ->(context) {
puts " After hook called with key: #{context.key}"
},
error: ->(context, error) {
puts " Error hook called with error: #{error.message}"
},
on_finally: ->(context) {
puts " Finally hook called with key: #{context.key}"
}
)
runner.add_hook(hook)
context = DevCycle::HookContext.new(
key: 'test-key',
user: 'test-user',
default_value: 'test-default'
)
puts "Running hooks..."
runner.run_before_hooks(context)
runner.run_after_hooks(context)
runner.run_finally_hooks(context)
puts "\n2. Testing error handling..."
test_error = StandardError.new('Test error')
runner.run_error_hooks(context, test_error)
puts "\n3. Testing multiple hooks..."
runner.clear_hooks
hook1 = DevCycle::EvalHook.new(
before: ->(context) {
puts " Hook1 before"
context
},
after: ->(context) {
puts " Hook1 after"
}
)
hook2 = DevCycle::EvalHook.new(
before: ->(context) {
puts " Hook2 before"
context
},
after: ->(context) {
puts " Hook2 after"
}
)
runner.add_hook(hook1)
runner.add_hook(hook2)
puts "Running multiple hooks..."
runner.run_before_hooks(context)
runner.run_after_hooks(context)
puts "\nIntegration test completed successfully!"