/* Assertions for reddit-challenge.js. Run by the harness only after the
 * microtask queue has drained, so the challenge's async handler has settled. */

/* The obfuscated computation is `await (async e => e + e)(seed)` -- the token
 * is just the seed concatenated with itself. Verified against the live site:
 * requesting /r/<sub>/?solution=<this>&js_challenge=1&token=... returns the
 * real page instead of the interstitial. */
var EXPECTED = "7b8c3762b16953087b8c3762b1695308";

var fail = 0;

function check(what, got, want)
{
	var ok = got === want;
	if (!ok)
		fail++;
	print((ok ? "  ok   " : "  FAIL ") + what +
	      ": got " + got + (ok ? "" : ", want " + want));
}

print("reddit challenge:");
check("solution token", submitted, EXPECTED);
check("query params carried into form", form.extra.length, 1);
if (form.extra.length === 1) {
	check("carried param name", form.extra[0].name, "foo");
	check("carried param value", form.extra[0].value, "bar");
	check("carried param type", form.extra[0].type, "hidden");
}

print(fail === 0 ? "PASS" : "FAIL (" + fail + ")");
