linear-cli 0.3.7

A powerful CLI for Linear.app - manage issues, projects, cycles, and more from your terminal
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
//! Typed structs for Linear API responses.
//!
//! These types provide structured access to Linear API data instead of working
//! with raw `serde_json::Value`. They are designed for gradual adoption - the
//! codebase can continue using `Value` for complex nested data while leveraging
//! these types for common operations.

use serde::{Deserialize, Serialize};

/// A Linear issue with all commonly used fields.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Issue {
    pub id: String,
    pub identifier: String,
    pub title: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub priority: i32,
    #[serde(default)]
    pub estimate: Option<f64>,
    #[serde(default)]
    pub due_date: Option<String>,
    #[serde(default)]
    pub url: Option<String>,
    #[serde(default)]
    pub branch_name: Option<String>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
    #[serde(default)]
    pub started_at: Option<String>,
    #[serde(default)]
    pub completed_at: Option<String>,
    #[serde(default)]
    pub canceled_at: Option<String>,
    #[serde(default)]
    pub archived_at: Option<String>,
    #[serde(default)]
    pub state: Option<WorkflowState>,
    #[serde(default)]
    pub assignee: Option<User>,
    #[serde(default)]
    pub creator: Option<User>,
    #[serde(default)]
    pub team: Option<Team>,
    #[serde(default)]
    pub project: Option<Project>,
    #[serde(default)]
    pub cycle: Option<Cycle>,
    #[serde(default)]
    pub labels: Option<LabelConnection>,
    #[serde(default)]
    pub parent: Option<Box<IssueRef>>,
    #[serde(default)]
    pub sub_issues: Option<IssueConnection>,
}

/// A minimal issue reference for parent/child relationships.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IssueRef {
    pub id: String,
    pub identifier: String,
    #[serde(default)]
    pub title: Option<String>,
    #[serde(default)]
    pub state: Option<WorkflowState>,
}

/// Connection wrapper for issues (for sub-issues, etc.).
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IssueConnection {
    pub nodes: Vec<IssueRef>,
}

/// A workflow state (issue status).
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkflowState {
    pub id: String,
    pub name: String,
    #[serde(rename = "type")]
    #[serde(default)]
    pub state_type: Option<String>,
    #[serde(default)]
    pub color: Option<String>,
    #[serde(default)]
    pub position: Option<f64>,
}

/// A Linear user.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct User {
    pub id: String,
    pub name: String,
    #[serde(default)]
    pub email: Option<String>,
    #[serde(default)]
    pub display_name: Option<String>,
    #[serde(default)]
    pub avatar_url: Option<String>,
    #[serde(default)]
    pub active: Option<bool>,
    #[serde(default)]
    pub admin: Option<bool>,
}

/// A Linear team.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Team {
    pub id: String,
    pub key: String,
    pub name: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub color: Option<String>,
    #[serde(default)]
    pub icon: Option<String>,
    #[serde(default)]
    pub timezone: Option<String>,
    #[serde(default)]
    pub private: Option<bool>,
    #[serde(default)]
    pub issue_count: Option<i64>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
}

/// A project status reference.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProjectStatus {
    pub name: String,
}

/// A Linear project.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Project {
    pub id: String,
    pub name: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub slug_id: Option<String>,
    #[serde(default)]
    pub url: Option<String>,
    #[serde(default)]
    pub icon: Option<String>,
    #[serde(default)]
    pub color: Option<String>,
    #[serde(default)]
    pub state: Option<String>,
    #[serde(default)]
    pub status: Option<ProjectStatus>,
    #[serde(default)]
    pub progress: Option<f64>,
    #[serde(default)]
    pub start_date: Option<String>,
    #[serde(default)]
    pub target_date: Option<String>,
    #[serde(default)]
    pub started_at: Option<String>,
    #[serde(default)]
    pub completed_at: Option<String>,
    #[serde(default)]
    pub canceled_at: Option<String>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
    #[serde(default)]
    pub labels: Option<LabelConnection>,
}

/// A sprint cycle.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Cycle {
    pub id: String,
    #[serde(default)]
    pub number: Option<i32>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub starts_at: Option<String>,
    #[serde(default)]
    pub ends_at: Option<String>,
    #[serde(default)]
    pub completed_at: Option<String>,
    #[serde(default)]
    pub progress: Option<f64>,
}

/// An issue label.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Label {
    pub id: String,
    pub name: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub color: Option<String>,
    #[serde(default)]
    pub parent: Option<Box<LabelRef>>,
}

/// A minimal label reference.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LabelRef {
    pub id: String,
    pub name: String,
}

/// Connection wrapper for labels.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LabelConnection {
    pub nodes: Vec<Label>,
}

/// A comment on an issue.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Comment {
    pub id: String,
    #[serde(default)]
    pub body: Option<String>,
    #[serde(default)]
    pub user: Option<User>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
    #[serde(default)]
    pub edited_at: Option<String>,
}

/// A document in Linear.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Document {
    pub id: String,
    pub title: String,
    #[serde(default)]
    pub content: Option<String>,
    #[serde(default)]
    pub slug_id: Option<String>,
    #[serde(default)]
    pub url: Option<String>,
    #[serde(default)]
    pub icon: Option<String>,
    #[serde(default)]
    pub color: Option<String>,
    #[serde(default)]
    pub creator: Option<User>,
    #[serde(default)]
    pub project: Option<Project>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
}

/// A notification from Linear.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Notification {
    pub id: String,
    #[serde(rename = "type")]
    #[serde(default)]
    pub notification_type: Option<String>,
    #[serde(default)]
    pub read_at: Option<String>,
    #[serde(default)]
    pub snoozed_until_at: Option<String>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
    #[serde(default)]
    pub issue: Option<IssueRef>,
    #[serde(default)]
    pub comment: Option<Comment>,
    #[serde(default)]
    pub actor: Option<User>,
}

/// Pagination info from GraphQL connections.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PageInfo {
    #[serde(default)]
    pub has_next_page: bool,
    #[serde(default)]
    pub has_previous_page: bool,
    #[serde(default)]
    pub start_cursor: Option<String>,
    #[serde(default)]
    pub end_cursor: Option<String>,
}

/// A roadmap in Linear.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Roadmap {
    pub id: String,
    pub name: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub slug_id: Option<String>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
}

/// An initiative in Linear.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Initiative {
    pub id: String,
    pub name: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub slug_id: Option<String>,
    #[serde(default)]
    pub color: Option<String>,
    #[serde(default)]
    pub icon: Option<String>,
    #[serde(default)]
    pub status: Option<String>,
    #[serde(default)]
    pub sort_order: Option<f64>,
    #[serde(default)]
    pub target_date: Option<String>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
}

/// A favorite item in Linear.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Favorite {
    pub id: String,
    #[serde(rename = "type")]
    #[serde(default)]
    pub favorite_type: Option<String>,
    #[serde(default)]
    pub sort_order: Option<f64>,
    #[serde(default)]
    pub issue: Option<IssueRef>,
    #[serde(default)]
    pub project: Option<Project>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
}

/// An issue relation (blocking, related, etc.).
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IssueRelation {
    pub id: String,
    #[serde(rename = "type")]
    #[serde(default)]
    pub relation_type: Option<String>,
    #[serde(default)]
    pub issue: Option<IssueRef>,
    #[serde(default)]
    pub related_issue: Option<IssueRef>,
    #[serde(default)]
    pub created_at: Option<String>,
}

/// A time tracking entry.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TimeEntry {
    pub id: String,
    #[serde(default)]
    pub hours: Option<f64>,
    /// Duration in minutes (returned by timeSchedules GraphQL query).
    #[serde(default)]
    pub duration: Option<i64>,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub user: Option<User>,
    #[serde(default)]
    pub issue: Option<IssueRef>,
    #[serde(default)]
    pub spent_at: Option<String>,
    #[serde(default)]
    pub created_at: Option<String>,
    #[serde(default)]
    pub updated_at: Option<String>,
}

/// The current viewer (authenticated user).
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Viewer {
    pub id: String,
    pub name: String,
    #[serde(default)]
    pub email: Option<String>,
    #[serde(default)]
    pub display_name: Option<String>,
    #[serde(default)]
    pub avatar_url: Option<String>,
    #[serde(default)]
    pub active: Option<bool>,
    #[serde(default)]
    pub admin: Option<bool>,
    #[serde(default)]
    pub url: Option<String>,
    #[serde(default)]
    pub created_at: Option<String>,
}

/// Organization info.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Organization {
    pub id: String,
    pub name: String,
    #[serde(default)]
    pub url_key: Option<String>,
    #[serde(default)]
    pub logo_url: Option<String>,
    #[serde(default)]
    pub created_at: Option<String>,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_issue_deserialize() {
        let json = r#"{
            "id": "abc123",
            "identifier": "LIN-123",
            "title": "Test issue",
            "priority": 2,
            "state": {
                "id": "state1",
                "name": "In Progress",
                "type": "started"
            },
            "assignee": {
                "id": "user1",
                "name": "John Doe",
                "email": "john@example.com"
            },
            "team": {
                "id": "team1",
                "key": "ENG",
                "name": "Engineering"
            },
            "labels": {
                "nodes": [
                    {"id": "label1", "name": "bug"},
                    {"id": "label2", "name": "urgent"}
                ]
            }
        }"#;

        let issue: Issue = serde_json::from_str(json).unwrap();
        assert_eq!(issue.identifier, "LIN-123");
        assert_eq!(issue.title, "Test issue");
        assert_eq!(issue.priority, 2);
        assert_eq!(issue.state.as_ref().unwrap().name, "In Progress");
        assert_eq!(issue.assignee.as_ref().unwrap().name, "John Doe");
        assert_eq!(issue.team.as_ref().unwrap().key, "ENG");
        assert_eq!(issue.labels.as_ref().unwrap().nodes.len(), 2);
    }

    #[test]
    fn test_issue_minimal() {
        let json = r#"{
            "id": "abc123",
            "identifier": "LIN-123",
            "title": "Test issue"
        }"#;

        let issue: Issue = serde_json::from_str(json).unwrap();
        assert_eq!(issue.identifier, "LIN-123");
        assert!(issue.state.is_none());
        assert!(issue.assignee.is_none());
    }

    #[test]
    fn test_user_deserialize() {
        let json = r#"{
            "id": "user1",
            "name": "Jane Doe",
            "email": "jane@example.com",
            "active": true
        }"#;

        let user: User = serde_json::from_str(json).unwrap();
        assert_eq!(user.name, "Jane Doe");
        assert_eq!(user.email.as_deref(), Some("jane@example.com"));
        assert_eq!(user.active, Some(true));
    }

    #[test]
    fn test_team_deserialize() {
        let json = r#"{
            "id": "team1",
            "key": "ENG",
            "name": "Engineering",
            "private": false
        }"#;

        let team: Team = serde_json::from_str(json).unwrap();
        assert_eq!(team.key, "ENG");
        assert_eq!(team.name, "Engineering");
        assert_eq!(team.private, Some(false));
    }

    #[test]
    fn test_page_info_deserialize() {
        let json = r#"{
            "hasNextPage": true,
            "hasPreviousPage": false,
            "endCursor": "abc123"
        }"#;

        let page_info: PageInfo = serde_json::from_str(json).unwrap();
        assert!(page_info.has_next_page);
        assert!(!page_info.has_previous_page);
        assert_eq!(page_info.end_cursor.as_deref(), Some("abc123"));
    }

    // --- Cycle tests ---

    #[test]
    fn test_cycle_deserialize() {
        let json = r#"{
            "id": "c1",
            "number": 5,
            "name": "Sprint 5",
            "startsAt": "2024-01-01",
            "endsAt": "2024-01-14",
            "progress": 0.75
        }"#;
        let cycle: Cycle = serde_json::from_str(json).unwrap();
        assert_eq!(cycle.id, "c1");
        assert_eq!(cycle.number, Some(5));
        assert_eq!(cycle.name.as_deref(), Some("Sprint 5"));
        assert_eq!(cycle.starts_at.as_deref(), Some("2024-01-01"));
        assert_eq!(cycle.ends_at.as_deref(), Some("2024-01-14"));
        assert_eq!(cycle.progress, Some(0.75));
    }

    #[test]
    fn test_cycle_minimal() {
        let json = r#"{"id": "c1"}"#;
        let cycle: Cycle = serde_json::from_str(json).unwrap();
        assert_eq!(cycle.id, "c1");
        assert!(cycle.name.is_none());
        assert!(cycle.number.is_none());
        assert!(cycle.progress.is_none());
    }

    // --- Notification tests ---

    #[test]
    fn test_notification_deserialize() {
        let json = r#"{
            "id": "notif1",
            "type": "issueComment",
            "readAt": null,
            "createdAt": "2024-01-15T10:00:00Z",
            "issue": {
                "id": "issue1",
                "identifier": "LIN-100",
                "title": "Fix login bug"
            },
            "actor": {
                "id": "user1",
                "name": "Alice"
            }
        }"#;
        let notif: Notification = serde_json::from_str(json).unwrap();
        assert_eq!(notif.id, "notif1");
        assert_eq!(notif.notification_type.as_deref(), Some("issueComment"));
        assert!(notif.read_at.is_none());
        assert_eq!(notif.issue.as_ref().unwrap().identifier, "LIN-100");
        assert_eq!(notif.actor.as_ref().unwrap().name, "Alice");
    }

    #[test]
    fn test_notification_minimal() {
        let json = r#"{"id": "notif1"}"#;
        let notif: Notification = serde_json::from_str(json).unwrap();
        assert_eq!(notif.id, "notif1");
        assert!(notif.notification_type.is_none());
        assert!(notif.issue.is_none());
        assert!(notif.actor.is_none());
    }

    // --- IssueRelation tests ---

    #[test]
    fn test_issue_relation_deserialize() {
        let json = r#"{
            "id": "rel1",
            "type": "blocks",
            "issue": {
                "id": "issue1",
                "identifier": "LIN-1",
                "title": "Parent task"
            },
            "relatedIssue": {
                "id": "issue2",
                "identifier": "LIN-2",
                "title": "Blocked task"
            },
            "createdAt": "2024-02-01T12:00:00Z"
        }"#;
        let rel: IssueRelation = serde_json::from_str(json).unwrap();
        assert_eq!(rel.id, "rel1");
        assert_eq!(rel.relation_type.as_deref(), Some("blocks"));
        assert_eq!(rel.issue.as_ref().unwrap().identifier, "LIN-1");
        assert_eq!(rel.related_issue.as_ref().unwrap().identifier, "LIN-2");
        assert_eq!(rel.created_at.as_deref(), Some("2024-02-01T12:00:00Z"));
    }

    #[test]
    fn test_issue_relation_minimal() {
        let json = r#"{"id": "rel1"}"#;
        let rel: IssueRelation = serde_json::from_str(json).unwrap();
        assert_eq!(rel.id, "rel1");
        assert!(rel.relation_type.is_none());
        assert!(rel.issue.is_none());
        assert!(rel.related_issue.is_none());
    }

    // --- TimeEntry tests ---

    #[test]
    fn test_time_entry_deserialize() {
        let json = r#"{
            "id": "te1",
            "hours": 2.5,
            "spentAt": "2024-03-10",
            "user": {
                "id": "user1",
                "name": "Bob"
            },
            "issue": {
                "id": "issue1",
                "identifier": "LIN-50"
            },
            "createdAt": "2024-03-10T14:00:00Z"
        }"#;
        let entry: TimeEntry = serde_json::from_str(json).unwrap();
        assert_eq!(entry.id, "te1");
        assert_eq!(entry.hours, Some(2.5));
        assert_eq!(entry.spent_at.as_deref(), Some("2024-03-10"));
        assert_eq!(entry.user.as_ref().unwrap().name, "Bob");
        assert_eq!(entry.issue.as_ref().unwrap().identifier, "LIN-50");
    }

    #[test]
    fn test_time_entry_minimal() {
        let json = r#"{"id": "te1"}"#;
        let entry: TimeEntry = serde_json::from_str(json).unwrap();
        assert_eq!(entry.id, "te1");
        assert!(entry.hours.is_none());
        assert!(entry.user.is_none());
        assert!(entry.issue.is_none());
    }

    // --- Roadmap tests ---

    #[test]
    fn test_roadmap_deserialize() {
        let json = r#"{
            "id": "rm1",
            "name": "Q1 2024 Roadmap",
            "description": "First quarter planning",
            "slugId": "q1-2024",
            "createdAt": "2024-01-01T00:00:00Z"
        }"#;
        let roadmap: Roadmap = serde_json::from_str(json).unwrap();
        assert_eq!(roadmap.id, "rm1");
        assert_eq!(roadmap.name, "Q1 2024 Roadmap");
        assert_eq!(
            roadmap.description.as_deref(),
            Some("First quarter planning")
        );
        assert_eq!(roadmap.slug_id.as_deref(), Some("q1-2024"));
    }

    #[test]
    fn test_roadmap_minimal() {
        let json = r#"{"id": "rm1", "name": "Roadmap"}"#;
        let roadmap: Roadmap = serde_json::from_str(json).unwrap();
        assert_eq!(roadmap.id, "rm1");
        assert_eq!(roadmap.name, "Roadmap");
        assert!(roadmap.description.is_none());
        assert!(roadmap.slug_id.is_none());
    }

    // --- Initiative tests ---

    #[test]
    fn test_initiative_deserialize() {
        let json = r##"{
            "id": "init1",
            "name": "Platform Migration",
            "description": "Migrate to new platform",
            "slugId": "platform-migration",
            "color": "#FF5733",
            "icon": "rocket",
            "targetDate": "2024-06-30",
            "createdAt": "2024-01-15T10:00:00Z"
        }"##;
        let init: Initiative = serde_json::from_str(json).unwrap();
        assert_eq!(init.id, "init1");
        assert_eq!(init.name, "Platform Migration");
        assert_eq!(init.description.as_deref(), Some("Migrate to new platform"));
        assert_eq!(init.color.as_deref(), Some("#FF5733"));
        assert_eq!(init.target_date.as_deref(), Some("2024-06-30"));
    }

    #[test]
    fn test_initiative_minimal() {
        let json = r#"{"id": "init1", "name": "Init"}"#;
        let init: Initiative = serde_json::from_str(json).unwrap();
        assert_eq!(init.id, "init1");
        assert_eq!(init.name, "Init");
        assert!(init.description.is_none());
        assert!(init.target_date.is_none());
    }

    // --- Favorite tests ---

    #[test]
    fn test_favorite_deserialize() {
        let json = r#"{
            "id": "fav1",
            "type": "issue",
            "sortOrder": 1.5,
            "issue": {
                "id": "issue1",
                "identifier": "LIN-42",
                "title": "Favorite issue"
            },
            "createdAt": "2024-02-20T08:00:00Z"
        }"#;
        let fav: Favorite = serde_json::from_str(json).unwrap();
        assert_eq!(fav.id, "fav1");
        assert_eq!(fav.favorite_type.as_deref(), Some("issue"));
        assert_eq!(fav.sort_order, Some(1.5));
        assert_eq!(fav.issue.as_ref().unwrap().identifier, "LIN-42");
    }

    #[test]
    fn test_favorite_minimal() {
        let json = r#"{"id": "fav1"}"#;
        let fav: Favorite = serde_json::from_str(json).unwrap();
        assert_eq!(fav.id, "fav1");
        assert!(fav.favorite_type.is_none());
        assert!(fav.issue.is_none());
        assert!(fav.project.is_none());
    }

    // --- Document tests ---

    #[test]
    fn test_document_deserialize() {
        let json = r##"{
            "id": "doc1",
            "title": "Design Document",
            "content": "Overview of the design.",
            "slugId": "design-doc",
            "url": "https://linear.app/docs/design-doc",
            "icon": "file",
            "color": "#3B82F6",
            "creator": {
                "id": "user1",
                "name": "Alice"
            },
            "createdAt": "2024-03-01T09:00:00Z",
            "updatedAt": "2024-03-05T15:00:00Z"
        }"##;
        let doc: Document = serde_json::from_str(json).unwrap();
        assert_eq!(doc.id, "doc1");
        assert_eq!(doc.title, "Design Document");
        assert!(doc.content.as_deref().unwrap().contains("Overview"));
        assert_eq!(doc.slug_id.as_deref(), Some("design-doc"));
        assert_eq!(doc.creator.as_ref().unwrap().name, "Alice");
    }

    #[test]
    fn test_document_minimal() {
        let json = r#"{"id": "doc1", "title": "Doc"}"#;
        let doc: Document = serde_json::from_str(json).unwrap();
        assert_eq!(doc.id, "doc1");
        assert_eq!(doc.title, "Doc");
        assert!(doc.content.is_none());
        assert!(doc.creator.is_none());
    }

    // --- Label tests ---

    #[test]
    fn test_label_deserialize() {
        let json = r##"{
            "id": "label1",
            "name": "bug",
            "description": "Something is broken",
            "color": "#EF4444"
        }"##;
        let label: Label = serde_json::from_str(json).unwrap();
        assert_eq!(label.id, "label1");
        assert_eq!(label.name, "bug");
        assert_eq!(label.description.as_deref(), Some("Something is broken"));
        assert_eq!(label.color.as_deref(), Some("#EF4444"));
        assert!(label.parent.is_none());
    }

    #[test]
    fn test_label_with_parent() {
        let json = r#"{
            "id": "label2",
            "name": "frontend-bug",
            "parent": {
                "id": "label1",
                "name": "bug"
            }
        }"#;
        let label: Label = serde_json::from_str(json).unwrap();
        assert_eq!(label.id, "label2");
        assert_eq!(label.name, "frontend-bug");
        let parent = label.parent.as_ref().unwrap();
        assert_eq!(parent.id, "label1");
        assert_eq!(parent.name, "bug");
    }

    // --- Comment tests ---

    #[test]
    fn test_comment_deserialize() {
        let json = r#"{
            "id": "comment1",
            "body": "Looks good to me!",
            "user": {
                "id": "user1",
                "name": "Charlie"
            },
            "createdAt": "2024-04-01T11:30:00Z",
            "updatedAt": "2024-04-01T11:30:00Z",
            "editedAt": null
        }"#;
        let comment: Comment = serde_json::from_str(json).unwrap();
        assert_eq!(comment.id, "comment1");
        assert_eq!(comment.body.as_deref(), Some("Looks good to me!"));
        assert_eq!(comment.user.as_ref().unwrap().name, "Charlie");
        assert!(comment.edited_at.is_none());
    }

    #[test]
    fn test_comment_minimal() {
        let json = r#"{"id": "comment1"}"#;
        let comment: Comment = serde_json::from_str(json).unwrap();
        assert_eq!(comment.id, "comment1");
        assert!(comment.body.is_none());
        assert!(comment.user.is_none());
    }

    // --- WorkflowState tests ---

    #[test]
    fn test_workflow_state_deserialize() {
        let json = r##"{
            "id": "state1",
            "name": "In Progress",
            "type": "started",
            "color": "#F59E0B",
            "position": 2.0
        }"##;
        let state: WorkflowState = serde_json::from_str(json).unwrap();
        assert_eq!(state.id, "state1");
        assert_eq!(state.name, "In Progress");
        assert_eq!(state.state_type.as_deref(), Some("started"));
        assert_eq!(state.color.as_deref(), Some("#F59E0B"));
        assert_eq!(state.position, Some(2.0));
    }

    #[test]
    fn test_workflow_state_minimal() {
        let json = r#"{"id": "state1", "name": "Todo"}"#;
        let state: WorkflowState = serde_json::from_str(json).unwrap();
        assert_eq!(state.id, "state1");
        assert_eq!(state.name, "Todo");
        assert!(state.state_type.is_none());
        assert!(state.color.is_none());
    }

    // --- Viewer tests ---

    #[test]
    fn test_viewer_deserialize() {
        let json = r#"{
            "id": "viewer1",
            "name": "Current User",
            "email": "me@example.com",
            "displayName": "Me",
            "active": true,
            "admin": false,
            "url": "https://linear.app/user/me",
            "createdAt": "2023-01-01T00:00:00Z"
        }"#;
        let viewer: Viewer = serde_json::from_str(json).unwrap();
        assert_eq!(viewer.id, "viewer1");
        assert_eq!(viewer.name, "Current User");
        assert_eq!(viewer.email.as_deref(), Some("me@example.com"));
        assert_eq!(viewer.display_name.as_deref(), Some("Me"));
        assert_eq!(viewer.active, Some(true));
        assert_eq!(viewer.admin, Some(false));
    }

    #[test]
    fn test_viewer_minimal() {
        let json = r#"{"id": "viewer1", "name": "User"}"#;
        let viewer: Viewer = serde_json::from_str(json).unwrap();
        assert_eq!(viewer.id, "viewer1");
        assert_eq!(viewer.name, "User");
        assert!(viewer.email.is_none());
        assert!(viewer.admin.is_none());
    }

    // --- Organization tests ---

    #[test]
    fn test_organization_deserialize() {
        let json = r#"{
            "id": "org1",
            "name": "Acme Corp",
            "urlKey": "acme",
            "logoUrl": "https://example.com/logo.png",
            "createdAt": "2022-06-15T00:00:00Z"
        }"#;
        let org: Organization = serde_json::from_str(json).unwrap();
        assert_eq!(org.id, "org1");
        assert_eq!(org.name, "Acme Corp");
        assert_eq!(org.url_key.as_deref(), Some("acme"));
        assert_eq!(
            org.logo_url.as_deref(),
            Some("https://example.com/logo.png")
        );
    }

    #[test]
    fn test_organization_minimal() {
        let json = r#"{"id": "org1", "name": "Org"}"#;
        let org: Organization = serde_json::from_str(json).unwrap();
        assert_eq!(org.id, "org1");
        assert_eq!(org.name, "Org");
        assert!(org.url_key.is_none());
        assert!(org.logo_url.is_none());
    }
}