52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
RECONNECT = ROOT / "frontend" / "reconnect-outboxes.js"
|
|
|
|
|
|
def run_node(script: str) -> dict:
|
|
result = subprocess.run(
|
|
["node", "-e", script], cwd=ROOT, text=True, capture_output=True, check=True
|
|
)
|
|
return json.loads(result.stdout)
|
|
|
|
|
|
def test_successful_reconnect_restores_identity_and_flushes_unchanged_outboxes():
|
|
result = run_node(
|
|
f"""
|
|
const createReconnectOutboxes = require({json.dumps(str(RECONNECT))});
|
|
const calls = [];
|
|
const reconnect = createReconnectOutboxes({{
|
|
refresh: async () => ({{context:{{user:{{login:'timmy'}}}}}}),
|
|
restoreIdentity: login => calls.push(['identity', login]),
|
|
flushIssue: () => calls.push(['issue']),
|
|
flushAuthored: () => calls.push(['authored']),
|
|
flushNotificationReads: () => calls.push(['notification-read']),
|
|
}});
|
|
reconnect().then(result => process.stdout.write(JSON.stringify({{result, calls}})));
|
|
"""
|
|
)
|
|
|
|
assert result == {
|
|
"result": True,
|
|
"calls": [
|
|
["identity", "timmy"],
|
|
["issue"],
|
|
["authored"],
|
|
["notification-read"],
|
|
],
|
|
}
|
|
|
|
|
|
def test_dashboard_uses_reconnect_flush_after_live_identity_refresh():
|
|
index = (ROOT / "frontend" / "index.html").read_text()
|
|
dashboard = (ROOT / "frontend" / "dashboard.js").read_text()
|
|
|
|
assert '<script src="static/reconnect-outboxes.js"></script>' in index
|
|
assert "const reconnectOutboxes = createReconnectOutboxes({" in dashboard
|
|
assert "restoreIdentity: login => { activeFlushLogin = login; confirmedOwnerLogin = login; }" in dashboard
|
|
assert "window.addEventListener('online', reconnectOutboxes);" in dashboard
|