返回 CodeWhale
profile_constitution.rs
根目录 / crates / app-server / src / runtime_api / tests / profile_constitution.rs
1 use super::*;
2
3 #[tokio::test]
4 async fn profile_constitution_preview_is_authenticated_and_uses_the_engine_renderer() -> Result<()>
5 {
6 let temp = tempfile::tempdir()?;
7 let root = temp.path().join("constitution-route");
8 let Some((addr, _, handle)) = spawn_test_server_with_root_token_mobile_workspace(
9 root.clone(),
10 root.join("sessions"),
11 Some("constitution-fixture-token".into()),
12 false,
13 root.join("workspace"),
14 )
15 .await?
16 else {
17 bail!("loopback server unavailable");
18 };
19 let client = codewhale_release::tls::reqwest_client();
20 let url = format!("http://{addr}/v1/constitution/preview");
21 let document = codewhale_config::user_constitution::ProfileConstitution {
22 notes: "Show the recommendation first. 🐋".into(),
23 ..Default::default()
24 };
25 assert_eq!(
26 client.post(&url).json(&document).send().await?.status(),
27 401
28 );
29 let response: Value = client
30 .post(&url)
31 .bearer_auth("constitution-fixture-token")
32 .json(&document)
33 .send()
34 .await?
35 .error_for_status()?
36 .json()
37 .await?;
38 assert_eq!(response["saved"], false);
39 assert_eq!(
40 response["modelGuidance"],
41 document.as_user_constitution()?.render_body()
42 );
43 let mut invalid = serde_json::to_value(&document)?;
44 invalid["permissions"] = "all".into();
45 assert_eq!(
46 client
47 .post(&url)
48 .bearer_auth("constitution-fixture-token")
49 .json(&invalid)
50 .send()
51 .await?
52 .status(),
53 422
54 );
55 handle.abort();
56 Ok(())
57 }
58
58 lines RUST