crawlrs 0.2.0

crawlrs - Enterprise-grade web scraping and crawling platform built with Rust
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
// Copyright (c) 2025-2026 Kirky.X🌠
// SPDX-License-Identifier: Apache-2.0

//! Task Mapper - converts between Task domain model and database entity

use crate::common::time_utils::{
    from_db_datetime, from_db_datetime_opt, to_db_datetime, to_db_datetime_opt,
};
use crate::domain::models::{Task, TaskStatus, TaskType};
use crate::infrastructure::database::entities::task;
use dbnexus::sea_orm::ActiveValue::{Set, Unchanged};

/// Mapper for converting between Task domain model and database entity
pub struct TaskMapper;

impl TaskMapper {
    /// Convert database entity to domain model
    pub fn to_domain(entity: task::Model) -> Task {
        Task {
            id: entity.id.into(),
            task_type: Self::parse_task_type(&entity.task_type),
            status: Self::parse_task_status(&entity.status),
            priority: entity.priority,
            team_id: entity.team_id.into(),
            api_key_id: entity.api_key_id.into(),
            url: entity.url,
            payload: entity.payload,
            retry_count: entity.retry_count,
            attempt_count: entity.attempt_count,
            max_retries: entity.max_retries,
            scheduled_at: from_db_datetime_opt(entity.scheduled_at),
            expires_at: from_db_datetime_opt(entity.expires_at),
            created_at: from_db_datetime(entity.created_at),
            started_at: from_db_datetime_opt(entity.started_at),
            completed_at: from_db_datetime_opt(entity.completed_at),
            crawl_id: entity.crawl_id.map(Into::into),
            updated_at: from_db_datetime(entity.updated_at),
            lock_token: entity.lock_token.map(Into::into),
            lock_expires_at: from_db_datetime_opt(entity.lock_expires_at),
        }
    }

    /// Convert domain model to database entity
    pub fn to_entity(domain: &Task) -> task::Model {
        task::Model {
            id: domain.id.into(),
            task_type: domain.task_type.to_string(),
            status: domain.status.to_string(),
            priority: domain.priority,
            team_id: domain.team_id.into(),
            api_key_id: domain.api_key_id.into(),
            url: domain.url.clone(),
            payload: domain.payload.clone(),
            retry_count: domain.retry_count,
            attempt_count: domain.attempt_count,
            max_retries: domain.max_retries,
            scheduled_at: to_db_datetime_opt(domain.scheduled_at),
            expires_at: to_db_datetime_opt(domain.expires_at),
            created_at: to_db_datetime(domain.created_at),
            started_at: to_db_datetime_opt(domain.started_at),
            completed_at: to_db_datetime_opt(domain.completed_at),
            crawl_id: domain.crawl_id.map(Into::into),
            updated_at: to_db_datetime(domain.updated_at),
            lock_token: domain.lock_token.map(Into::into),
            lock_expires_at: to_db_datetime_opt(domain.lock_expires_at),
        }
    }

    /// Convert multiple entities to domain models
    pub fn to_domain_list(entities: Vec<task::Model>) -> Vec<Task> {
        entities.into_iter().map(Self::to_domain).collect()
    }

    /// Convert domain model to ActiveModel for update operations
    ///
    /// 所有字段为 Set 状态,确保 `update()` 实际更新数据。
    /// id 用 Unchanged(用于 WHERE 条件),created_at 用 Unchanged(不应更新)。
    pub fn to_active_model(domain: &Task) -> task::ActiveModel {
        let entity = Self::to_entity(domain);
        task::ActiveModel {
            id: Unchanged(entity.id),
            task_type: Set(entity.task_type),
            team_id: Set(entity.team_id),
            api_key_id: Set(entity.api_key_id),
            crawl_id: Set(entity.crawl_id),
            url: Set(entity.url),
            status: Set(entity.status),
            priority: Set(entity.priority),
            payload: Set(entity.payload),
            retry_count: Set(entity.retry_count),
            max_retries: Set(entity.max_retries),
            scheduled_at: Set(entity.scheduled_at),
            expires_at: Set(entity.expires_at),
            completed_at: Set(entity.completed_at),
            lock_token: Set(entity.lock_token),
            lock_expires_at: Set(entity.lock_expires_at),
            started_at: Set(entity.started_at),
            attempt_count: Set(entity.attempt_count),
            created_at: Unchanged(entity.created_at),
            updated_at: Set(entity.updated_at),
        }
    }

    /// Parse task type from string
    fn parse_task_type(s: &str) -> TaskType {
        s.parse().unwrap_or_default()
    }

    /// Parse task status from string
    fn parse_task_status(s: &str) -> TaskStatus {
        s.parse().unwrap_or_default()
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use chrono::Utc;
    use dbnexus::sea_orm::ActiveValue;

    /// 构造一个填充了典型值的 task::Model,供各测试按需覆盖字段
    fn make_entity() -> task::Model {
        let now = Utc::now().fixed_offset();
        task::Model {
            id: crate::domain::id::Id::generate().to_uuid_v8(),
            task_type: "scrape".to_string(),
            team_id: crate::domain::id::Id::generate().to_uuid_v8(),
            api_key_id: crate::domain::id::Id::generate().to_uuid_v8(),
            crawl_id: None,
            url: "https://example.com".to_string(),
            status: "queued".to_string(),
            priority: 1,
            payload: serde_json::json!({"key": "value"}),
            retry_count: 0,
            max_retries: 3,
            scheduled_at: None,
            expires_at: None,
            completed_at: None,
            lock_token: None,
            lock_expires_at: None,
            started_at: None,
            attempt_count: 0,
            created_at: now,
            updated_at: now,
        }
    }

    #[test]
    fn test_task_mapper_roundtrip() {
        let now = Utc::now();
        let domain = Task {
            id: crate::domain::id::Id::generate(),
            task_type: TaskType::Scrape,
            status: TaskStatus::Queued,
            priority: 1,
            team_id: crate::domain::id::Id::generate(),
            api_key_id: crate::domain::id::Id::generate(),
            url: "https://example.com".to_string(),
            payload: serde_json::json!({"key": "value"}),
            retry_count: 0,
            attempt_count: 0,
            max_retries: 3,
            scheduled_at: None,
            expires_at: None,
            created_at: now,
            started_at: None,
            completed_at: None,
            crawl_id: None,
            updated_at: now,
            lock_token: None,
            lock_expires_at: None,
        };

        let entity = TaskMapper::to_entity(&domain);
        let back_to_domain = TaskMapper::to_domain(entity);

        assert_eq!(domain.id, back_to_domain.id);
        assert_eq!(domain.task_type, back_to_domain.task_type);
        assert_eq!(domain.status, back_to_domain.status);
        assert_eq!(domain.url, back_to_domain.url);
    }

    // to_domain: TaskType 映射

    #[test]
    fn test_to_domain_scrape_type() {
        let mut entity = make_entity();
        entity.task_type = "scrape".to_string();
        let domain = TaskMapper::to_domain(entity);
        assert_eq!(domain.task_type, TaskType::Scrape);
    }

    #[test]
    fn test_to_domain_crawl_type() {
        let mut entity = make_entity();
        entity.task_type = "crawl".to_string();
        let domain = TaskMapper::to_domain(entity);
        assert_eq!(domain.task_type, TaskType::Crawl);
    }

    #[test]
    fn test_to_domain_extract_type() {
        let mut entity = make_entity();
        entity.task_type = "extract".to_string();
        let domain = TaskMapper::to_domain(entity);
        assert_eq!(domain.task_type, TaskType::Extract);
    }

    #[test]
    fn test_to_domain_invalid_task_type_falls_back_to_default() {
        // 解析失败应 fallback 到 TaskType::default = Scrape
        for bad in ["unknown", "", "SCRAPE", "search", "scrape "].iter() {
            let mut entity = make_entity();
            entity.task_type = bad.to_string();
            let domain = TaskMapper::to_domain(entity);
            assert_eq!(
                domain.task_type,
                TaskType::Scrape,
                "invalid task_type {:?} should fall back to Scrape",
                bad
            );
        }
    }

    // to_domain: TaskStatus 映射

    #[test]
    fn test_to_domain_queued_status() {
        let mut entity = make_entity();
        entity.status = "queued".to_string();
        assert_eq!(TaskMapper::to_domain(entity).status, TaskStatus::Queued);
    }

    #[test]
    fn test_to_domain_active_status() {
        let mut entity = make_entity();
        entity.status = "active".to_string();
        assert_eq!(TaskMapper::to_domain(entity).status, TaskStatus::Active);
    }

    #[test]
    fn test_to_domain_completed_status() {
        let mut entity = make_entity();
        entity.status = "completed".to_string();
        assert_eq!(TaskMapper::to_domain(entity).status, TaskStatus::Completed);
    }

    #[test]
    fn test_to_domain_failed_status() {
        let mut entity = make_entity();
        entity.status = "failed".to_string();
        assert_eq!(TaskMapper::to_domain(entity).status, TaskStatus::Failed);
    }

    #[test]
    fn test_to_domain_cancelled_status() {
        let mut entity = make_entity();
        entity.status = "cancelled".to_string();
        assert_eq!(TaskMapper::to_domain(entity).status, TaskStatus::Cancelled);
    }

    #[test]
    fn test_to_domain_invalid_status_falls_back_to_default() {
        // 解析失败应 fallback 到 TaskStatus::default = Queued
        for bad in ["unknown", "", "QUEUED", "running", "expired"].iter() {
            let mut entity = make_entity();
            entity.status = bad.to_string();
            let domain = TaskMapper::to_domain(entity);
            assert_eq!(
                domain.status,
                TaskStatus::Queued,
                "invalid status {:?} should fall back to Queued",
                bad
            );
        }
    }

    // to_entity: 字段映射

    #[test]
    fn test_to_entity_maps_all_fields() {
        let now = Utc::now();
        let domain = Task {
            id: crate::domain::id::Id::generate(),
            task_type: TaskType::Crawl,
            status: TaskStatus::Active,
            priority: 7,
            team_id: crate::domain::id::Id::generate(),
            api_key_id: crate::domain::id::Id::generate(),
            url: "https://test.example.com/path".to_string(),
            payload: serde_json::json!({"k": "v", "n": 42}),
            retry_count: 2,
            attempt_count: 3,
            max_retries: 5,
            scheduled_at: None,
            expires_at: None,
            created_at: now,
            started_at: None,
            completed_at: None,
            crawl_id: None,
            updated_at: now,
            lock_token: None,
            lock_expires_at: None,
        };

        let entity = TaskMapper::to_entity(&domain);
        assert_eq!(domain.id, entity.id);
        assert_eq!(entity.task_type, "crawl");
        assert_eq!(entity.status, "active");
        assert_eq!(entity.priority, 7);
        assert_eq!(domain.team_id, entity.team_id);
        assert_eq!(domain.api_key_id, entity.api_key_id);
        assert_eq!(entity.url, domain.url);
        assert_eq!(entity.payload, domain.payload);
        assert_eq!(entity.retry_count, 2);
        assert_eq!(entity.attempt_count, 3);
        assert_eq!(entity.max_retries, 5);
        assert_eq!(entity.created_at.timestamp(), now.timestamp());
        assert_eq!(entity.updated_at.timestamp(), now.timestamp());
        assert!(entity.scheduled_at.is_none());
        assert!(entity.expires_at.is_none());
        assert!(entity.started_at.is_none());
        assert!(entity.completed_at.is_none());
        assert!(entity.crawl_id.is_none());
        assert!(entity.lock_token.is_none());
        assert!(entity.lock_expires_at.is_none());
    }

    // to_domain_list

    #[test]
    fn test_to_domain_list_empty() {
        let result = TaskMapper::to_domain_list(Vec::new());
        assert!(result.is_empty());
    }

    #[test]
    fn test_to_domain_list_single_element() {
        let entity = make_entity();
        let result = TaskMapper::to_domain_list(vec![entity.clone()]);
        assert_eq!(result.len(), 1);
        assert_eq!(result[0].id, entity.id);
        assert_eq!(result[0].url, entity.url);
    }

    #[test]
    fn test_to_domain_list_multiple_preserves_order() {
        let e1 = make_entity();
        let mut e2 = make_entity();
        e2.url = "https://second.example.com".to_string();
        let mut e3 = make_entity();
        e3.url = "https://third.example.com".to_string();

        let input = vec![e1.clone(), e2.clone(), e3.clone()];
        let result = TaskMapper::to_domain_list(input);
        assert_eq!(result.len(), 3);
        assert_eq!(result[0].id, e1.id);
        assert_eq!(result[1].id, e2.id);
        assert_eq!(result[2].id, e3.id);
        assert_eq!(result[0].url, e1.url);
        assert_eq!(result[1].url, e2.url);
        assert_eq!(result[2].url, e3.url);
    }

    // to_active_model: ActiveValue 状态

    #[test]
    fn test_to_active_model_id_is_unchanged() {
        let now = Utc::now();
        let id = crate::domain::id::Id::generate();
        let domain = Task {
            id,
            task_type: TaskType::Scrape,
            status: TaskStatus::Queued,
            priority: 1,
            team_id: crate::domain::id::Id::generate(),
            api_key_id: crate::domain::id::Id::generate(),
            url: "https://example.com".to_string(),
            payload: serde_json::json!({}),
            retry_count: 0,
            attempt_count: 0,
            max_retries: 3,
            scheduled_at: None,
            expires_at: None,
            created_at: now,
            started_at: None,
            completed_at: None,
            crawl_id: None,
            updated_at: now,
            lock_token: None,
            lock_expires_at: None,
        };

        let active = TaskMapper::to_active_model(&domain);
        // id 必须是 Unchanged(作为 WHERE 条件)
        assert!(matches!(active.id, ActiveValue::Unchanged(_)));
        assert_eq!(active.id.as_ref(), &id.to_uuid_v8());
    }

    #[test]
    fn test_to_active_model_created_at_is_unchanged() {
        let now = Utc::now();
        let domain = Task {
            id: crate::domain::id::Id::generate(),
            task_type: TaskType::Scrape,
            status: TaskStatus::Queued,
            priority: 1,
            team_id: crate::domain::id::Id::generate(),
            api_key_id: crate::domain::id::Id::generate(),
            url: "https://example.com".to_string(),
            payload: serde_json::json!({}),
            retry_count: 0,
            attempt_count: 0,
            max_retries: 3,
            scheduled_at: None,
            expires_at: None,
            created_at: now,
            started_at: None,
            completed_at: None,
            crawl_id: None,
            updated_at: now,
            lock_token: None,
            lock_expires_at: None,
        };

        let active = TaskMapper::to_active_model(&domain);
        // created_at 必须是 Unchanged(不应更新)
        assert!(matches!(active.created_at, ActiveValue::Unchanged(_)));
    }

    #[test]
    fn test_to_active_model_other_fields_are_set() {
        let now = Utc::now();
        let domain = Task {
            id: crate::domain::id::Id::generate(),
            task_type: TaskType::Crawl,
            status: TaskStatus::Active,
            priority: 9,
            team_id: crate::domain::id::Id::generate(),
            api_key_id: crate::domain::id::Id::generate(),
            url: "https://example.com".to_string(),
            payload: serde_json::json!({"k": "v"}),
            retry_count: 1,
            attempt_count: 2,
            max_retries: 4,
            scheduled_at: None,
            expires_at: None,
            created_at: now,
            started_at: None,
            completed_at: None,
            crawl_id: None,
            updated_at: now,
            lock_token: None,
            lock_expires_at: None,
        };

        let active = TaskMapper::to_active_model(&domain);
        // 除 id 和 created_at 外,其他字段必须是 Set
        assert!(matches!(active.task_type, ActiveValue::Set(_)));
        assert!(matches!(active.team_id, ActiveValue::Set(_)));
        assert!(matches!(active.api_key_id, ActiveValue::Set(_)));
        assert!(matches!(active.crawl_id, ActiveValue::Set(_)));
        assert!(matches!(active.url, ActiveValue::Set(_)));
        assert!(matches!(active.status, ActiveValue::Set(_)));
        assert!(matches!(active.priority, ActiveValue::Set(_)));
        assert!(matches!(active.payload, ActiveValue::Set(_)));
        assert!(matches!(active.retry_count, ActiveValue::Set(_)));
        assert!(matches!(active.max_retries, ActiveValue::Set(_)));
        assert!(matches!(active.scheduled_at, ActiveValue::Set(_)));
        assert!(matches!(active.expires_at, ActiveValue::Set(_)));
        assert!(matches!(active.completed_at, ActiveValue::Set(_)));
        assert!(matches!(active.lock_token, ActiveValue::Set(_)));
        assert!(matches!(active.lock_expires_at, ActiveValue::Set(_)));
        assert!(matches!(active.started_at, ActiveValue::Set(_)));
        assert!(matches!(active.attempt_count, ActiveValue::Set(_)));
        assert!(matches!(active.updated_at, ActiveValue::Set(_)));

        // 值也应正确映射
        assert_eq!(active.task_type.as_ref(), "crawl");
        assert_eq!(active.status.as_ref(), "active");
        assert_eq!(active.priority.as_ref(), &9);
        assert_eq!(active.retry_count.as_ref(), &1);
        assert_eq!(active.attempt_count.as_ref(), &2);
        assert_eq!(active.max_retries.as_ref(), &4);
    }

    // null/optional 字段

    #[test]
    fn test_to_domain_all_optional_fields_none() {
        let entity = make_entity(); // 默认所有 Option 字段为 None
        let domain = TaskMapper::to_domain(entity);
        assert!(domain.scheduled_at.is_none());
        assert!(domain.expires_at.is_none());
        assert!(domain.started_at.is_none());
        assert!(domain.completed_at.is_none());
        assert!(domain.crawl_id.is_none());
        assert!(domain.lock_token.is_none());
        assert!(domain.lock_expires_at.is_none());
    }

    #[test]
    fn test_to_domain_all_optional_fields_some() {
        let now = Utc::now().fixed_offset();
        let crawl_id = crate::domain::id::Id::generate();
        let lock_token = crate::domain::id::Id::generate();
        let mut entity = make_entity();
        entity.scheduled_at = Some(now);
        entity.expires_at = Some(now);
        entity.started_at = Some(now);
        entity.completed_at = Some(now);
        entity.crawl_id = Some(crawl_id.into());
        entity.lock_token = Some(lock_token.into());
        entity.lock_expires_at = Some(now);

        let domain = TaskMapper::to_domain(entity);
        assert!(domain.scheduled_at.is_some());
        assert!(domain.expires_at.is_some());
        assert!(domain.started_at.is_some());
        assert!(domain.completed_at.is_some());
        assert_eq!(domain.crawl_id, Some(crawl_id));
        assert_eq!(domain.lock_token, Some(lock_token));
        assert!(domain.lock_expires_at.is_some());
    }

    // datetime 转换

    #[test]
    fn test_to_entity_with_scheduled_at_preserves_timestamp() {
        let scheduled = Utc::now() + chrono::Duration::seconds(3600);
        let now = Utc::now();
        let domain = Task {
            id: crate::domain::id::Id::generate(),
            task_type: TaskType::Scrape,
            status: TaskStatus::Queued,
            priority: 1,
            team_id: crate::domain::id::Id::generate(),
            api_key_id: crate::domain::id::Id::generate(),
            url: "https://example.com".to_string(),
            payload: serde_json::json!({}),
            retry_count: 0,
            attempt_count: 0,
            max_retries: 3,
            scheduled_at: Some(scheduled),
            expires_at: Some(scheduled),
            created_at: now,
            started_at: Some(scheduled),
            completed_at: Some(scheduled),
            crawl_id: None,
            updated_at: now,
            lock_token: None,
            lock_expires_at: Some(scheduled),
        };

        let entity = TaskMapper::to_entity(&domain);
        assert!(entity.scheduled_at.is_some());
        assert_eq!(
            entity.scheduled_at.unwrap().timestamp(),
            scheduled.timestamp()
        );
        assert_eq!(
            entity.expires_at.unwrap().timestamp(),
            scheduled.timestamp()
        );
        assert_eq!(
            entity.started_at.unwrap().timestamp(),
            scheduled.timestamp()
        );
        assert_eq!(
            entity.completed_at.unwrap().timestamp(),
            scheduled.timestamp()
        );
        assert_eq!(
            entity.lock_expires_at.unwrap().timestamp(),
            scheduled.timestamp()
        );
    }

    #[test]
    fn test_roundtrip_preserves_all_optional_datetimes() {
        let ts = Utc::now();
        let domain = Task {
            id: crate::domain::id::Id::generate(),
            task_type: TaskType::Extract,
            status: TaskStatus::Failed,
            priority: 3,
            team_id: crate::domain::id::Id::generate(),
            api_key_id: crate::domain::id::Id::generate(),
            url: "https://example.com".to_string(),
            payload: serde_json::json!({"a": 1}),
            retry_count: 2,
            attempt_count: 3,
            max_retries: 5,
            scheduled_at: Some(ts),
            expires_at: Some(ts),
            created_at: ts,
            started_at: Some(ts),
            completed_at: Some(ts),
            crawl_id: Some(crate::domain::id::Id::generate()),
            updated_at: ts,
            lock_token: Some(crate::domain::id::Id::generate()),
            lock_expires_at: Some(ts),
        };

        let entity = TaskMapper::to_entity(&domain);
        let back = TaskMapper::to_domain(entity);

        assert_eq!(
            domain.scheduled_at.map(|t| t.timestamp()),
            back.scheduled_at.map(|t| t.timestamp())
        );
        assert_eq!(
            domain.expires_at.map(|t| t.timestamp()),
            back.expires_at.map(|t| t.timestamp())
        );
        assert_eq!(
            domain.started_at.map(|t| t.timestamp()),
            back.started_at.map(|t| t.timestamp())
        );
        assert_eq!(
            domain.completed_at.map(|t| t.timestamp()),
            back.completed_at.map(|t| t.timestamp())
        );
        assert_eq!(
            domain.lock_expires_at.map(|t| t.timestamp()),
            back.lock_expires_at.map(|t| t.timestamp())
        );
        assert_eq!(domain.crawl_id, back.crawl_id);
        assert_eq!(domain.lock_token, back.lock_token);
    }
}