Skip to content

Commit 5fb387d

Browse files
committed
fix: more test comment cleanup
1 parent eca76a2 commit 5fb387d

File tree

4 files changed

+63
-50
lines changed

4 files changed

+63
-50
lines changed

packages/auth-server/components/session/row/Expiry.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const props = defineProps<{
3838
status: SessionStatus;
3939
isExpired: boolean;
4040
now: number;
41-
createdAt: number;
4241
expiresAt: number;
42+
maxExpiresAt: number;
4343
}>();
4444
4545
const expiresIn = useTimeAgo(props.expiresAt, { showSecond: true, updateInterval: 1000 });
@@ -54,7 +54,10 @@ const sessionExpiry = computed(() => {
5454
});
5555
});
5656
const timeLeft = computed<number>(() => Math.max(0, props.expiresAt - props.now));
57-
const timeTotal = computed<number>(() => Math.max(0, props.expiresAt - props.createdAt));
58-
const timeLeftPercentage = computed<number>(() => Math.min(100, (timeLeft.value / timeTotal.value) * 100));
57+
const maxTimeLeft = computed<number>(() => Math.max(0, props.maxExpiresAt - props.now));
58+
const timeLeftPercentage = computed<number>(() => {
59+
if (maxTimeLeft.value === 0) return 0;
60+
return Math.min(100, (timeLeft.value / maxTimeLeft.value) * 100);
61+
});
5962
const isRevoked = computed(() => props.status === SessionStatus.Closed);
6063
</script>

packages/auth-server/components/session/row/Row.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@
1616
</div>
1717
</div>
1818
<div class="session-expiry-container">
19-
<!-- TODO: created-at is hardcoded to 0 because the current session data
20-
does not include a creation timestamp. Update this when a real
21-
created-at value is available or when SessionRowExpiry is changed
22-
to not rely on created-at for active sessions. -->
2319
<SessionRowExpiry
2420
v-if="sessionState"
2521
:status="sessionState.status"
2622
:is-expired="isExpired"
27-
:created-at="0"
2823
:expires-at="expiresAt"
2924
:now="now"
25+
:max-expires-at="maxExpiresAt"
3026
/>
3127
</div>
3228
<div class="session-spend-limit-container">
@@ -67,6 +63,7 @@ import { type SessionConfig, type SessionState, SessionStatus } from "zksync-sso
6763
const props = defineProps<{
6864
sessionHash: Hex;
6965
sessionSpec: SessionConfig;
66+
maxExpiresAt: number;
7067
}>();
7168
7269
const _now = useNow({ interval: 1000 });

packages/auth-server/pages/dashboard/sessions.vue

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
:key="item.sessionHash"
4646
:session-hash="item.sessionHash"
4747
:session-spec="item.sessionSpec"
48+
:max-expires-at="maxExpiresAt"
4849
/>
4950
</template>
5051
</div>
@@ -55,7 +56,7 @@
5556
import { InformationCircleIcon } from "@heroicons/vue/20/solid";
5657
import type { Address, Hex } from "viem";
5758
import { listActiveSessions } from "zksync-sso-4337";
58-
import { type ConstraintCondition, LimitType, type SessionSpec } from "zksync-sso-4337/client";
59+
import { ConstraintCondition, LimitType, type SessionSpec } from "zksync-sso-4337/client";
5960
6061
const { defaultChain } = useClientStore();
6162
const { address } = storeToRefs(useAccountStore());
@@ -158,12 +159,37 @@ const convertSessionSpec = (wasmSpec: WasmSessionSpec): SessionSpec => {
158159
selector: policy.selector,
159160
maxValuePerUse: safeBigInt(policy.maxValuePerUse, "maxValuePerUse"),
160161
valueLimit: convertLimit(policy.valueLimit),
161-
constraints: (policy.constraints || []).map((constraint: WasmConstraint) => ({
162-
condition: constraint.condition as unknown as ConstraintCondition,
163-
index: safeBigInt(constraint.index, "constraint.index"),
164-
refValue: constraint.refValue,
165-
limit: convertLimit(constraint.limit),
166-
})),
162+
constraints: (policy.constraints || []).map((constraint: WasmConstraint) => {
163+
// Validate and convert constraint condition
164+
let condition: ConstraintCondition;
165+
const validConditions: Record<string, ConstraintCondition> = {
166+
Unconstrained: ConstraintCondition.Unconstrained,
167+
Equal: ConstraintCondition.Equal,
168+
Greater: ConstraintCondition.Greater,
169+
Less: ConstraintCondition.Less,
170+
GreaterEqual: ConstraintCondition.GreaterEqual,
171+
LessEqual: ConstraintCondition.LessEqual,
172+
NotEqual: ConstraintCondition.NotEqual,
173+
};
174+
175+
if (constraint.condition in validConditions) {
176+
condition = validConditions[constraint.condition];
177+
} else {
178+
const error = new Error(
179+
`Unexpected constraint condition value received from WASM: ${constraint.condition}`,
180+
);
181+
// eslint-disable-next-line no-console
182+
console.error(error);
183+
throw error;
184+
}
185+
186+
return {
187+
condition,
188+
index: safeBigInt(constraint.index, "constraint.index"),
189+
refValue: constraint.refValue,
190+
limit: convertLimit(constraint.limit),
191+
};
192+
}),
167193
})),
168194
transferPolicies: (wasmSpec.transferPolicies || []).map((policy: WasmTransferPolicy) => ({
169195
target: policy.target,
@@ -204,7 +230,7 @@ const {
204230
accountFactory: contracts.factory,
205231
webauthnValidator: contracts.webauthnValidator,
206232
eoaValidator: contracts.eoaValidator,
207-
guardianExecutor: contracts.guardianExecutor,
233+
guardianExecutor: contracts.guardianExecutor as Address,
208234
},
209235
});
210236
@@ -227,5 +253,11 @@ const {
227253
return filtered;
228254
});
229255
256+
// Calculate the maximum expiration time across all sessions for progress bar scaling
257+
const maxExpiresAt = computed(() => {
258+
if (!sessions.value || sessions.value.length === 0) return 0;
259+
return Math.max(...sessions.value.map((s) => Number(s.sessionSpec.expiresAt)));
260+
});
261+
230262
sessionsFetch();
231263
</script>

packages/auth-server/tests/sessions.spec.ts

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -99,52 +99,33 @@ test("Session list: verify sessions page loads and displays correctly", async ({
9999

100100
console.log("Page loaded, checking content...");
101101

102-
// Log any errors that occurred
103-
if (pageErrors.length > 0) {
104-
console.log(`⚠️ Page errors detected: ${pageErrors.join(", ")}`);
105-
}
106-
107-
// Check what's actually on the page
108-
const bodyText = await page.locator("body").textContent();
109-
console.log(`Page content (first 500 chars): ${bodyText?.substring(0, 500)}`);
102+
// Assert no page errors occurred
103+
expect(pageErrors, "No page errors should occur during load").toHaveLength(0);
110104

111105
// Step 3: Verify sessions page UI
112106
console.log("\nStep 3: Verifying sessions page UI...");
113107

114-
// Check for main content
115-
const mainVisible = await page.locator("main").isVisible({ timeout: 5000 }).catch(() => false);
116-
console.log(`Main content visible: ${mainVisible}`);
108+
// Assert main content is visible
109+
const main = page.locator("main");
110+
await expect(main).toBeVisible({ timeout: 5000 });
117111

118-
// Look for sessions heading (in header)
112+
// Assert sessions heading is present
119113
const header = page.locator("header").getByText("Sessions");
120-
const headerVisible = await header.isVisible({ timeout: 5000 }).catch(() => false);
121-
console.log(`Sessions header visible: ${headerVisible}`);
122-
123-
if (headerVisible) {
124-
console.log("✓ Sessions header found");
125-
} else {
126-
console.log("❌ Sessions header NOT found");
127-
// Check what's in the header
128-
const headerText = await page.locator("header").textContent().catch(() => "");
129-
console.log(`Header content: ${headerText}`);
130-
}
114+
await expect(header).toBeVisible({ timeout: 5000 });
131115

132-
// Look for empty state or error message
116+
// Assert empty state is visible (since we haven't created any sessions yet)
133117
const emptyStateText = page.getByText(/no active sessions/i);
134-
const emptyVisible = await emptyStateText.isVisible({ timeout: 3000 }).catch(() => false);
135-
console.log(`Empty state visible: ${emptyVisible}`);
118+
await expect(emptyStateText).toBeVisible({ timeout: 3000 });
136119

120+
// Assert no error alerts are shown
137121
const errorAlert = page.locator("[role='alert']");
138-
const errorVisible = await errorAlert.isVisible({ timeout: 1000 }).catch(() => false);
139-
if (errorVisible) {
140-
const errorText = await errorAlert.textContent();
141-
console.log(`⚠️ Error alert: ${errorText}`);
142-
}
122+
await expect(errorAlert).not.toBeVisible({ timeout: 1000 });
143123

144-
// Check for session rows
145-
const sessionRows = page.locator("[data-testid*='session-row'], .session-item");
124+
// Assert no session rows are displayed (empty state)
125+
const sessionRows = page.locator(".session-row");
146126
const count = await sessionRows.count();
147-
console.log(`Session rows found: ${count}`);
127+
expect(count, "No sessions should be displayed in empty state").toBe(0);
148128

129+
console.log("✓ All assertions passed");
149130
console.log("\n=== Session List UI Test Complete ===\n");
150131
});

0 commit comments

Comments
 (0)