bzr 0.3.0

A CLI for Bugzilla, inspired by gh
Documentation
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
#![expect(clippy::unwrap_used)]

use wiremock::matchers::{method, path, query_param};
use wiremock::{Mock, MockServer, ResponseTemplate};

use super::*;
use crate::client::test_helpers::{test_client, test_client_hybrid};

#[tokio::test]
async fn get_bug_history_returns_entries() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug/42/history"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{
                "id": 42,
                "alias": [],
                "history": [
                    {
                        "who": "alice@example.com",
                        "when": "2025-01-15T10:30:00Z",
                        "changes": [
                            {
                                "field_name": "status",
                                "removed": "NEW",
                                "added": "ASSIGNED"
                            },
                            {
                                "field_name": "assigned_to",
                                "removed": "",
                                "added": "alice@example.com"
                            }
                        ]
                    },
                    {
                        "who": "bob@example.com",
                        "when": "2025-01-16T14:00:00Z",
                        "changes": [
                            {
                                "field_name": "status",
                                "removed": "ASSIGNED",
                                "added": "RESOLVED"
                            }
                        ]
                    }
                ]
            }]
        })))
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let history = client.get_bug_history_since(42, None).await.unwrap();
    assert_eq!(history.len(), 2);
    assert_eq!(history[0].who, "alice@example.com");
    assert_eq!(history[0].changes.len(), 2);
    assert_eq!(history[0].changes[0].field_name, "status");
    assert_eq!(history[0].changes[0].removed, "NEW");
    assert_eq!(history[0].changes[0].added, "ASSIGNED");
    assert_eq!(history[1].changes.len(), 1);
}

#[tokio::test]
async fn get_bug_history_empty() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug/99/history"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{"id": 99, "alias": [], "history": []}]
        })))
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let history = client.get_bug_history_since(99, None).await.unwrap();
    assert!(history.is_empty());
}

#[tokio::test]
async fn get_bug_history_with_attachment_id() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug/10/history"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{
                "id": 10,
                "alias": [],
                "history": [{
                    "who": "carol@example.com",
                    "when": "2025-02-01T09:00:00Z",
                    "changes": [{
                        "field_name": "attachments.isobsolete",
                        "removed": "0",
                        "added": "1",
                        "attachment_id": 555
                    }]
                }]
            }]
        })))
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let history = client.get_bug_history_since(10, None).await.unwrap();
    assert_eq!(history.len(), 1);
    assert_eq!(history[0].changes[0].attachment_id, Some(555));
}

#[tokio::test]
async fn get_bug_history_since_filters_by_date() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug/42/history"))
        .and(query_param("new_since", "2025-06-01T00:00:00Z"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{
                "id": 42,
                "alias": [],
                "history": [{
                    "who": "alice@example.com",
                    "when": "2025-06-15T10:00:00Z",
                    "changes": [{"field_name": "status", "removed": "NEW", "added": "ASSIGNED"}]
                }]
            }]
        })))
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let history = client
        .get_bug_history_since(42, Some("2025-06-01T00:00:00Z"))
        .await
        .unwrap();
    assert_eq!(history.len(), 1);
}

#[tokio::test]
async fn get_bug_passes_params() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug/1"))
        .and(query_param("include_fields", "id,summary"))
        .respond_with(ResponseTemplate::new(200).set_body_json(
            serde_json::json!({"bugs": [{"id": 1, "summary": "test", "status": "NEW"}]}),
        ))
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let bug = client.get_bug("1", Some("id,summary"), None).await.unwrap();
    assert_eq!(bug.id, 1);
}

#[tokio::test]
async fn get_bug_falls_back_on_100500() {
    let mock = MockServer::start().await;

    // Direct endpoint returns 100500 (server extension crash)
    Mock::given(method("GET"))
        .and(path("/rest/bug/99"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "error": true,
            "code": BUGZILLA_INTERNAL_ERROR,
            "message": "Extension crash"
        })))
        .mount(&mock)
        .await;

    // Search endpoint returns the bug successfully
    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .and(query_param("id", "99"))
        .respond_with(ResponseTemplate::new(200).set_body_json(
            serde_json::json!({"bugs": [{"id": 99, "summary": "fallback bug", "status": "NEW"}]}),
        ))
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let bug = client.get_bug("99", None, None).await.unwrap();
    assert_eq!(bug.id, 99);
    assert_eq!(bug.summary, "fallback bug");
}

#[tokio::test]
async fn search_bugs_sends_option_fields() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .and(query_param("cc", "user@example.com"))
        .and(query_param("alias", "my-alias"))
        .and(query_param("summary", "crash"))
        .and(query_param("limit", "25"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": []
        })))
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let params = SearchParams {
        cc: Some("user@example.com".into()),
        alias: Some("my-alias".into()),
        summary: Some("crash".into()),
        limit: Some(25),
        ..Default::default()
    };
    let bugs = client.search_bugs(&params).await.unwrap();
    assert!(bugs.is_empty());
}

#[tokio::test]
async fn search_bugs_sends_product_filter() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .and(query_param("product", "Product"))
        .and(query_param("limit", "50"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{
                "id": 217_630,
                "summary": "Test bug",
                "status": "WORKING",
                "product": "Product",
                "component": "Triage",
                "assigned_to": "test@example.com",
                "priority": "P1",
                "severity": "high",
                "creation_time": "2026-03-09T09:33:08Z",
                "last_change_time": "2026-03-18T05:49:05Z"
            }]
        })))
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let params = SearchParams {
        product: vec!["Product".into()],
        limit: Some(50),
        ..Default::default()
    };
    let bugs = client.search_bugs(&params).await.unwrap();
    assert_eq!(bugs.len(), 1);
    assert_eq!(bugs[0].id, 217_630);
}

use crate::test_helpers::xmlrpc_bug_response;

#[tokio::test]
async fn hybrid_search_rest_has_results_no_xmlrpc_call() {
    let mock = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{"id": 1, "summary": "REST bug", "status": "NEW"}]
        })))
        .expect(1)
        .mount(&mock)
        .await;

    Mock::given(method("POST"))
        .and(path("/xmlrpc.cgi"))
        .respond_with(ResponseTemplate::new(200))
        .expect(0)
        .mount(&mock)
        .await;

    let client = test_client_hybrid(&mock.uri());
    let params = SearchParams {
        product: vec!["P".into()],
        ..Default::default()
    };
    let bugs = client.search_bugs(&params).await.unwrap();
    assert_eq!(bugs.len(), 1);
    assert_eq!(bugs[0].summary, "REST bug");
}

#[tokio::test]
async fn hybrid_search_rest_empty_with_filters_falls_back_to_xmlrpc() {
    let mock = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({"bugs": []})))
        .expect(1)
        .mount(&mock)
        .await;

    Mock::given(method("POST"))
        .and(path("/xmlrpc.cgi"))
        .respond_with(
            ResponseTemplate::new(200).set_body_string(xmlrpc_bug_response(99, "XML-RPC bug")),
        )
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client_hybrid(&mock.uri());
    let params = SearchParams {
        product: vec!["P".into()],
        ..Default::default()
    };
    let bugs = client.search_bugs(&params).await.unwrap();
    assert_eq!(bugs.len(), 1);
    assert_eq!(bugs[0].id, 99);
    assert_eq!(bugs[0].summary, "XML-RPC bug");
}

#[tokio::test]
async fn hybrid_search_rest_empty_without_filters_no_fallback() {
    let mock = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({"bugs": []})))
        .expect(1)
        .mount(&mock)
        .await;

    Mock::given(method("POST"))
        .and(path("/xmlrpc.cgi"))
        .respond_with(ResponseTemplate::new(200))
        .expect(0)
        .mount(&mock)
        .await;

    let client = test_client_hybrid(&mock.uri());
    let params = SearchParams::default();
    let bugs = client.search_bugs(&params).await.unwrap();
    assert!(bugs.is_empty());
}

#[tokio::test]
async fn hybrid_get_bug_rest_500_falls_back_to_xmlrpc() {
    let mock = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/rest/bug/42"))
        .respond_with(ResponseTemplate::new(500).set_body_string("error"))
        .mount(&mock)
        .await;

    Mock::given(method("POST"))
        .and(path("/xmlrpc.cgi"))
        .respond_with(
            ResponseTemplate::new(200).set_body_string(xmlrpc_bug_response(42, "XML-RPC result")),
        )
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client_hybrid(&mock.uri());
    let bug = client.get_bug("42", None, None).await.unwrap();
    assert_eq!(bug.id, 42);
    assert_eq!(bug.summary, "XML-RPC result");
}

#[tokio::test]
async fn hybrid_get_bug_rest_401_does_not_fall_back() {
    let mock = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/rest/bug/42"))
        .respond_with(ResponseTemplate::new(401).set_body_json(serde_json::json!({
            "error": true,
            "code": 102,
            "message": "Invalid API key"
        })))
        .mount(&mock)
        .await;

    Mock::given(method("POST"))
        .and(path("/xmlrpc.cgi"))
        .respond_with(ResponseTemplate::new(200))
        .expect(0)
        .mount(&mock)
        .await;

    let client = test_client_hybrid(&mock.uri());
    let err = client.get_bug("42", None, None).await.unwrap_err();
    assert!(
        err.to_string().contains("Invalid API key"),
        "should propagate auth error, got: {err}"
    );
}

#[test]
fn has_negated_filters_detects_negation() {
    let params = SearchParams {
        status: vec!["!CLOSED".into()],
        ..Default::default()
    };
    assert!(super::has_negated_filters(&params));
}

#[test]
fn has_negated_filters_false_for_positive_only() {
    let params = SearchParams {
        status: vec!["NEW".into()],
        ..Default::default()
    };
    assert!(!super::has_negated_filters(&params));
}

#[test]
fn has_raw_boolean_chart_params_detects_f1() {
    let params = SearchParams {
        raw_params: vec![
            ("f1".into(), "qa_contact".into()),
            ("o1".into(), "equals".into()),
            ("v1".into(), "user@example.com".into()),
        ],
        ..Default::default()
    };
    assert!(super::has_raw_boolean_chart_params(&params));
}

#[test]
fn has_raw_boolean_chart_params_false_for_non_chart() {
    let params = SearchParams {
        raw_params: vec![("product".into(), "Firefox".into())],
        ..Default::default()
    };
    assert!(!super::has_raw_boolean_chart_params(&params));
}

#[test]
fn has_raw_boolean_chart_params_false_for_empty() {
    let params = SearchParams::default();
    assert!(!super::has_raw_boolean_chart_params(&params));
}

#[tokio::test]
async fn search_bugs_multi_value_sends_repeated_params() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .and(query_param("status", "NEW"))
        .and(query_param("status", "ASSIGNED"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{"id": 1, "summary": "Bug 1", "status": "NEW"}]
        })))
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let params = SearchParams {
        status: vec!["NEW".into(), "ASSIGNED".into()],
        ..Default::default()
    };
    let bugs = client.search_bugs(&params).await.unwrap();
    assert_eq!(bugs.len(), 1);
}

#[tokio::test]
async fn search_bugs_negation_sends_boolean_chart() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .and(query_param("f1", "bug_status"))
        .and(query_param("o1", "notequals"))
        .and(query_param("v1", "CLOSED"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{"id": 2, "summary": "Open bug", "status": "NEW"}]
        })))
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let params = SearchParams {
        status: vec!["!CLOSED".into()],
        ..Default::default()
    };
    let bugs = client.search_bugs(&params).await.unwrap();
    assert_eq!(bugs.len(), 1);
}

#[tokio::test]
async fn search_bugs_mixed_positive_and_negated() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .and(query_param("status", "NEW"))
        .and(query_param("f1", "bug_severity"))
        .and(query_param("o1", "notequals"))
        .and(query_param("v1", "enhancement"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{"id": 3, "summary": "Real bug", "status": "NEW"}]
        })))
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let params = SearchParams {
        status: vec!["NEW".into()],
        severity: vec!["!enhancement".into()],
        ..Default::default()
    };
    let bugs = client.search_bugs(&params).await.unwrap();
    assert_eq!(bugs.len(), 1);
}

#[tokio::test]
async fn search_bugs_negations_in_two_fields_use_distinct_indices() {
    // Two negated values across different fields must produce
    // f1/o1/v1 and f2/o2/v2 — not collide on the same index.
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .and(query_param("f1", "bug_status"))
        .and(query_param("o1", "notequals"))
        .and(query_param("v1", "CLOSED"))
        .and(query_param("f2", "bug_severity"))
        .and(query_param("o2", "notequals"))
        .and(query_param("v2", "enhancement"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({"bugs": []})))
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let params = SearchParams {
        status: vec!["!CLOSED".into()],
        severity: vec!["!enhancement".into()],
        ..Default::default()
    };
    client.search_bugs(&params).await.unwrap();
}

#[test]
fn has_raw_boolean_chart_params_false_for_non_chart_letter_with_digit() {
    // "a1" matches the "letter+digit" shape but the prefix is not
    // f/o/v — must not be treated as a boolean chart parameter.
    let params = SearchParams {
        raw_params: vec![("a1".into(), "value".into())],
        ..Default::default()
    };
    assert!(!super::has_raw_boolean_chart_params(&params));
}

#[tokio::test]
async fn hybrid_search_bugs_with_raw_params_does_not_xmlrpc_fallback() {
    // Raw boolean chart params require REST and bypass the Hybrid
    // mode's empty-results XML-RPC retry: an empty REST result must
    // be returned as-is, not masked by a successful XML-RPC retry.
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({"bugs": []})))
        .mount(&mock)
        .await;
    // If the Hybrid arm were entered, it would see an empty result
    // with active filters and retry via XML-RPC, returning this
    // non-empty list and breaking the assertion below.
    Mock::given(method("POST"))
        .and(path("/xmlrpc.cgi"))
        .respond_with(
            ResponseTemplate::new(200).set_body_string(xmlrpc_bug_response(99, "xmlrpc-only")),
        )
        .mount(&mock)
        .await;

    let client = test_client_hybrid(&mock.uri());
    let params = SearchParams {
        raw_params: vec![
            ("f1".into(), "qa_contact".into()),
            ("o1".into(), "equals".into()),
            ("v1".into(), "user@example.com".into()),
        ],
        ..Default::default()
    };
    let bugs = client.search_bugs(&params).await.unwrap();
    assert!(
        bugs.is_empty(),
        "expected empty REST result, not XML-RPC fallback; got {bugs:?}"
    );
}

#[tokio::test]
async fn hybrid_get_bug_falls_back_on_residual_100500_error() {
    // The Hybrid arm catches a residual 100500 from get_bug_rest's
    // own retry chain (direct → search) and retries on XML-RPC.
    let mock = MockServer::start().await;

    Mock::given(method("GET"))
        .and(path("/rest/bug/42"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "error": true,
            "code": BUGZILLA_INTERNAL_ERROR,
            "message": "Extension crash"
        })))
        .mount(&mock)
        .await;

    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .and(query_param("id", "42"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "error": true,
            "code": BUGZILLA_INTERNAL_ERROR,
            "message": "Extension crash"
        })))
        .mount(&mock)
        .await;

    Mock::given(method("POST"))
        .and(path("/xmlrpc.cgi"))
        .respond_with(
            ResponseTemplate::new(200)
                .set_body_string(xmlrpc_bug_response(42, "recovered via xmlrpc")),
        )
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client_hybrid(&mock.uri());
    let bug = client.get_bug("42", None, None).await.unwrap();
    assert_eq!(bug.id, 42);
    assert_eq!(bug.summary, "recovered via xmlrpc");
}

#[tokio::test]
async fn search_bugs_rejects_negated_plus_raw_boolean_chart() {
    let mock = MockServer::start().await;
    let client = test_client(&mock.uri());
    let params = SearchParams {
        status: vec!["!CLOSED".into()],
        raw_params: vec![
            ("f1".into(), "qa_contact".into()),
            ("o1".into(), "equals".into()),
            ("v1".into(), "user@example.com".into()),
        ],
        ..Default::default()
    };
    let result = client.search_bugs(&params).await;
    assert!(result.is_err());
    let err = result.unwrap_err();
    assert!(
        err.to_string().contains("cannot combine negated filters"),
        "unexpected error: {err}"
    );
}

#[tokio::test]
async fn search_bugs_all_fields_reach_server() {
    let mock = MockServer::start().await;
    Mock::given(method("GET"))
        .and(path("/rest/bug"))
        .and(query_param("product", "Firefox"))
        .and(query_param("component", "General"))
        .and(query_param("status", "NEW"))
        .and(query_param("assigned_to", "dev@test.com"))
        .and(query_param("creator", "reporter@test.com"))
        .and(query_param("priority", "P1"))
        .and(query_param("severity", "major"))
        .and(query_param("cc", "watcher@test.com"))
        .and(query_param("alias", "my-bug"))
        .and(query_param("id", "42"))
        .and(query_param("limit", "10"))
        .and(query_param("summary", "crash"))
        .and(query_param("quicksearch", "qs-term"))
        .and(query_param("include_fields", "id,summary"))
        .and(query_param("exclude_fields", "cc"))
        .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
            "bugs": [{"id": 42, "summary": "crash", "status": "NEW"}]
        })))
        .expect(1)
        .mount(&mock)
        .await;

    let client = test_client(&mock.uri());
    let params = SearchParams {
        product: vec!["Firefox".into()],
        component: vec!["General".into()],
        status: vec!["NEW".into()],
        assigned_to: vec!["dev@test.com".into()],
        creator: vec!["reporter@test.com".into()],
        priority: vec!["P1".into()],
        severity: vec!["major".into()],
        cc: Some("watcher@test.com".into()),
        alias: Some("my-bug".into()),
        id: vec![42],
        limit: Some(10),
        summary: Some("crash".into()),
        quicksearch: Some("qs-term".into()),
        include_fields: Some("id,summary".into()),
        exclude_fields: Some("cc".into()),
        ..Default::default()
    };
    let bugs = client.search_bugs(&params).await.unwrap();
    assert_eq!(bugs.len(), 1);
}