fabro/lib/foundation/fabro-api/tests/automation_round_trip.rs
2026-08-26 17:35:36 -04:00

101 lines
3.3 KiB
Rust

use fabro_api::types::{
Automation as ApiAutomation, AutomationTrigger as ApiAutomationTrigger,
CreateAutomationRequest as ApiCreateAutomationRequest,
ReplaceAutomationRequest as ApiReplaceAutomationRequest,
};
use fabro_automation::{Automation, AutomationDraft, AutomationReplace, AutomationTrigger};
use serde_json::json;
// Compile-time witnesses that the generated API types resolve to the same
// types as the `fabro-automation` domain types via `with_replacement(...)`.
// If progenitor stops reusing the domain type, these functions stop type-
// checking and the build fails.
const _: fn(ApiAutomation) -> Automation = |value| value;
const _: fn(ApiAutomationTrigger) -> AutomationTrigger = |value| value;
const _: fn(ApiCreateAutomationRequest) -> AutomationDraft = |value| value;
const _: fn(ApiReplaceAutomationRequest) -> AutomationReplace = |value| value;
#[test]
fn automation_response_round_trips_public_json_shape() {
let value = json!({
"id": "nightly-deps",
"revision": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"name": "Nightly dependency update",
"description": null,
"target": {
"kind": "git",
"repo": "fabro-sh/fabro",
"branch": "main",
"tag": "v1.2.3",
"sha": "0123456789abcdef0123456789abcdef01234567"
},
"workflow": "dependency-update",
"triggers": [
{
"id": "manual",
"type": "api",
"enabled": true
},
{
"id": "nightly",
"type": "schedule",
"enabled": true,
"expression": "0 3 * * *"
}
]
});
let api: ApiAutomation = serde_json::from_value(value.clone()).unwrap();
assert_eq!(serde_json::to_value(api).unwrap(), value);
}
#[test]
fn create_automation_request_round_trips_public_json_shape() {
let value = json!({
"id": "nightly-deps",
"name": "Nightly dependency update",
"description": "Keep dependencies fresh",
"target": {
"kind": "git",
"repo": "fabro-sh/fabro",
"branch": "main"
},
"workflow": "dependency-update",
"triggers": [
{
"id": "manual",
"type": "api",
"enabled": false
}
]
});
let api: ApiCreateAutomationRequest = serde_json::from_value(value.clone()).unwrap();
assert_eq!(serde_json::to_value(api).unwrap(), value);
}
#[test]
fn replace_automation_request_round_trips_public_json_shape() {
let value = json!({
"name": "Nightly dependency update",
"description": "Keep dependencies fresh",
"target": {
"kind": "git",
"repo": "fabro-sh/fabro",
"branch": "release",
"tag": "v2"
},
"workflow": "dependency-update",
"triggers": [
{
"id": "nightly",
"type": "schedule",
"enabled": true,
"expression": "0 3 * * *"
}
]
});
let api: ApiReplaceAutomationRequest = serde_json::from_value(value.clone()).unwrap();
assert_eq!(serde_json::to_value(api).unwrap(), value);
}