1
+ require 'readwise/review'
2
+ require 'readwise/highlight'
3
+
4
+ RSpec . describe Readwise ::Review do
5
+ let ( :review_data ) do
6
+ {
7
+ id : 12345 ,
8
+ url : 'https://readwise.io/review/12345' ,
9
+ completed : false ,
10
+ highlights : [ ]
11
+ }
12
+ end
13
+
14
+ subject { described_class . new ( **review_data ) }
15
+
16
+ describe '#completed?' do
17
+ it 'returns false when completed is false' do
18
+ expect ( subject . completed? ) . to be false
19
+ end
20
+
21
+ it 'returns true when completed is true' do
22
+ review = described_class . new ( **review_data . merge ( completed : true ) )
23
+ expect ( review . completed? ) . to be true
24
+ end
25
+ end
26
+
27
+ describe '#serialize' do
28
+ it 'returns a hash representation' do
29
+ result = subject . serialize
30
+ expect ( result ) . to be_a ( Hash )
31
+ expect ( result [ :id ] ) . to eq ( 12345 )
32
+ expect ( result [ :url ] ) . to eq ( 'https://readwise.io/review/12345' )
33
+ expect ( result [ :completed ] ) . to be false
34
+ end
35
+
36
+ it 'excludes nil values from serialization' do
37
+ review = described_class . new ( id : 123 , url : 'https://example.com' , completed : nil , highlights : [ ] )
38
+ result = review . serialize
39
+ expect ( result ) . not_to have_key ( :completed )
40
+ expect ( result [ :id ] ) . to eq ( 123 )
41
+ end
42
+ end
43
+
44
+ describe 'with highlights' do
45
+ let ( :highlight ) { Readwise ::Highlight . new ( text : 'Sample highlight' , highlight_id : '123' , book_id : '456' , tags : [ ] ) }
46
+ let ( :review_with_highlights ) do
47
+ described_class . new ( **review_data . merge ( highlights : [ highlight ] ) )
48
+ end
49
+
50
+ it 'stores highlights properly' do
51
+ expect ( review_with_highlights . highlights ) . to be_an ( Array )
52
+ expect ( review_with_highlights . highlights . size ) . to eq ( 1 )
53
+ expect ( review_with_highlights . highlights . first ) . to be_instance_of Readwise ::Highlight
54
+ end
55
+ end
56
+ end
0 commit comments