Skip to content

Commit c6f1058

Browse files
committed
Carried approvals after #279: one 'approved' rule for merged and carried approvals; the test helpers keep main's jest and missing-file builds beside start/finish
1 parent 50eb373 commit c6f1058

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

‎app/tests/baselines.rs‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,56 @@ impl World {
310310
created.json()["id"].as_str().unwrap().to_string()
311311
}
312312

313+
/// A jest suite's build as DocSpring's CI sends it: text snapshots split out of Jest `.snap` files
314+
/// (`visualci upload --from jest`), into a subset build named "jest". For a pull request into `base`.
315+
async fn jest(
316+
&self,
317+
app: &Application,
318+
commit: &str,
319+
branch: &str,
320+
base: Option<&str>,
321+
parents: &[&str],
322+
files: &[(&str, &str)],
323+
) -> Build {
324+
let auth = format!("Bearer {}", self.token);
325+
let mut body =
326+
json!({ "commit": commit, "branch": branch, "parent_commits": parents, "subset": true, "name": "jest" });
327+
if let Some(base) = base {
328+
body["base_branch"] = json!(base);
329+
body["pr_number"] = json!(7);
330+
}
331+
let created = app.post("/api/v1/builds").header("authorization", &auth).json(body).await;
332+
created.assert_ok();
333+
let id = created.json()["id"].as_str().unwrap().to_string();
334+
let mut list = Vec::new();
335+
let mut bodies = Vec::new();
336+
for (name, text) in files {
337+
// The test's own bytes, as with images ([`png`]).
338+
let bytes = format!("{text}\n// {}\n", self.nonce).into_bytes();
339+
let sha = visualci_core::sha256_hex(&bytes);
340+
list.push(json!({
341+
"name": name, "platform": "", "kind": "text", "sha256": sha, "fingerprint": sha, "size": bytes.len(),
342+
"content_type": "text/plain",
343+
}));
344+
bodies.push(bytes);
345+
}
346+
let registered = app
347+
.post(format!("/api/v1/builds/{id}/snapshots"))
348+
.header("authorization", &auth)
349+
.json(json!({ "snapshots": list }))
350+
.await;
351+
registered.assert_ok();
352+
for (s, bytes) in registered.json()["snapshots"].as_array().unwrap().iter().zip(bodies) {
353+
if let Some(url) = s["upload_url"].as_str() {
354+
upload(url, bytes).await;
355+
}
356+
}
357+
let done = app.post(format!("/api/v1/builds/{id}/finalize")).header("authorization", &auth).await;
358+
assert_eq!(done.json()["state"], "completed", "{}", done.text());
359+
let pid: laravel::str::Uuid = id.parse().unwrap();
360+
Build::query().filter(Build::pid.eq(pid)).first().await.unwrap().unwrap()
361+
}
362+
313363
/// Register these images with a receiving build and upload them, all but the `missing` ones.
314364
async fn upload_all(&self, app: &Application, id: &str, files: &[(&str, [u8; 3])], missing: &[&str]) {
315365
if files.is_empty() {

0 commit comments

Comments
 (0)