size-limit-policy: add test.

This commit is contained in:
Brian Lee 2024-01-09 08:32:45 -08:00
parent 94a3c8455d
commit c303045e33

View File

@ -11,10 +11,12 @@ Deno.test('Size limit policy test', async () => {
// Create a message over 12KB // Create a message over 12KB
const largeContent = 'Hello'.repeat(2500); // Over 12KB const largeContent = 'Hello'.repeat(2500); // Over 12KB
const largeMessage = buildInputMessage({ event: buildEvent({ content: largeContent }) }); const largeMessage = buildInputMessage({ event: buildEvent({ content: largeContent }) });
const largeReplaceable = buildInputMessage({ event: buildEvent({ content: largeContent, kind: 30078 }) });
// Test that a small message is accepted // Test that a small message is accepted
assertEquals((await sizeLimitPolicy(smallMessage)).action, 'accept', 'Small message should be accepted'); assertEquals((await sizeLimitPolicy(smallMessage)).action, 'accept', 'Small message should be accepted');
// Test that a large message is rejected // Test that a large message is rejected
assertEquals((await sizeLimitPolicy(largeMessage)).action, 'reject', 'Large message should be rejected'); assertEquals((await sizeLimitPolicy(largeMessage)).action, 'reject', 'Large message should be rejected');
assertEquals((await sizeLimitPolicy(largeReplaceable)).action, 'accept', 'Large replaceable event should be accepted');
}); });