Skip to content

Commit af83826

Browse files
author
am
committed
test: tighten hosted community quota boundary coverage
Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz>
1 parent 4ba0633 commit af83826

5 files changed

Lines changed: 81 additions & 36 deletions

File tree

‎crates/buzz-db/src/store/community.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,10 @@ mod postgres_tests {
14671467
.list_communities_owned_by(&owner)
14681468
.await
14691469
.expect("owner quota at fifty");
1470-
assert_eq!(page.quota_used, 50);
1470+
assert_eq!(
1471+
page.quota_used,
1472+
crate::relay_members::MAX_COMMUNITIES_PER_OWNER
1473+
);
14711474
assert!(!page.can_create);
14721475

14731476
let host = format!("limit-test-overflow-{}.example", Uuid::new_v4().simple());
@@ -1694,7 +1697,11 @@ mod postgres_tests {
16941697
.await
16951698
.expect("owner list at lifetime cap");
16961699
assert_eq!(page.quota_used, 0, "completed deletions free active slots");
1697-
assert_eq!(page.quota_limit, 50, "active limit is shown separately");
1700+
assert_eq!(
1701+
page.quota_limit,
1702+
crate::relay_members::max_communities_per_owner(),
1703+
"active limit is shown separately"
1704+
);
16981705
assert!(!page.can_create, "the lifetime cap still blocks creation");
16991706

17001707
let host = format!("lifetime-overflow-{}.example", Uuid::new_v4().simple());

‎crates/buzz-db/src/store/relay_members.rs‎

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,8 @@ mod postgres_tests {
13071307
fn owner_limit_defaults_when_unset_or_invalid() {
13081308
assert_eq!(
13091309
super::effective_owner_limit(None),
1310-
super::MAX_COMMUNITIES_PER_OWNER
1310+
50,
1311+
"stock deployment permits 50 active communities"
13111312
);
13121313
assert_eq!(
13131314
super::effective_owner_limit(Some("not-a-number")),
@@ -1329,9 +1330,6 @@ mod postgres_tests {
13291330
let limit = super::max_communities_per_owner();
13301331
let lifetime = super::MAX_LIFETIME_COMMUNITIES_PER_OWNER;
13311332
assert!(quota(0, 0).admits());
1332-
assert_eq!(limit, 50, "stock deployment permits 50 active owners");
1333-
assert!(quota(49, 49).admits(), "49 to 50 is allowed");
1334-
assert!(!quota(50, 50).admits(), "50 to 51 is rejected");
13351333
assert!(quota(limit - 1, lifetime - 1).admits());
13361334
assert!(!quota(limit, limit).admits(), "active cap");
13371335
assert!(
@@ -1763,30 +1761,57 @@ mod postgres_tests {
17631761
.expect("bootstrap transferee community");
17641762
}
17651763

1766-
for (expected, label) in [(true, "fiftieth transfer"), (false, "fifty-first transfer")] {
1767-
let community = make_test_community(&pool).await;
1768-
bootstrap_owner(&pool, community, &owner)
1764+
let fiftieth = make_test_community(&pool).await;
1765+
bootstrap_owner(&pool, fiftieth, &owner)
1766+
.await
1767+
.expect("bootstrap owner");
1768+
assert!(matches!(
1769+
transfer_ownership(&pool, fiftieth, &transferee, &owner)
17691770
.await
1770-
.expect("bootstrap owner");
1771-
let result = transfer_ownership(&pool, community, &transferee, &owner)
1771+
.expect("fiftieth transfer"),
1772+
TransferResult::Transferred { .. }
1773+
));
1774+
assert_eq!(
1775+
get_relay_member(&pool, fiftieth, &transferee)
17721776
.await
1773-
.expect(label);
1774-
assert_eq!(
1775-
matches!(result, TransferResult::Transferred { .. }),
1776-
expected,
1777-
"{label}"
1778-
);
1779-
if !expected {
1780-
assert_eq!(result, TransferResult::LimitReached);
1781-
assert_eq!(
1782-
get_relay_member(&pool, community, &owner)
1783-
.await
1784-
.expect("get owner")
1785-
.expect("exists")
1786-
.role,
1787-
"owner"
1788-
);
1789-
}
1790-
}
1777+
.expect("get transferee")
1778+
.expect("exists")
1779+
.role,
1780+
"owner"
1781+
);
1782+
assert_eq!(
1783+
get_relay_member(&pool, fiftieth, &owner)
1784+
.await
1785+
.expect("get previous owner")
1786+
.expect("exists")
1787+
.role,
1788+
"member"
1789+
);
1790+
1791+
let fifty_first = make_test_community(&pool).await;
1792+
bootstrap_owner(&pool, fifty_first, &owner)
1793+
.await
1794+
.expect("bootstrap owner");
1795+
assert_eq!(
1796+
transfer_ownership(&pool, fifty_first, &transferee, &owner)
1797+
.await
1798+
.expect("fifty-first transfer"),
1799+
TransferResult::LimitReached
1800+
);
1801+
assert_eq!(
1802+
get_relay_member(&pool, fifty_first, &owner)
1803+
.await
1804+
.expect("get owner")
1805+
.expect("exists")
1806+
.role,
1807+
"owner"
1808+
);
1809+
assert!(
1810+
get_relay_member(&pool, fifty_first, &transferee)
1811+
.await
1812+
.expect("get transferee")
1813+
.is_none(),
1814+
"rejected transfer must not add transferee"
1815+
);
17911816
}
17921817
}

‎desktop/src/features/communities/hostedCommunityApi.test.mjs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { npubEncode } from "nostr-tools/nip19";
1616
import {
1717
hostedCommunityErrorMessage,
1818
hostedCommunityQuotaLimit,
19+
hostedCommunityQuotaUsed,
1920
normalizedBoundKeyHex,
2021
usableBoundIdentityNpub,
2122
} from "./hostedCommunityApi.ts";
@@ -99,6 +100,15 @@ test("the string normalizer rejects the same non-key values directly", () => {
99100
assert.equal(normalizedBoundKeyHex(" "), null);
100101
});
101102

103+
test("quota used accepts zero but rejects missing and invalid projections", () => {
104+
assert.equal(hostedCommunityQuotaUsed(undefined), null);
105+
assert.equal(hostedCommunityQuotaUsed(-1), null);
106+
assert.equal(hostedCommunityQuotaUsed(0), 0);
107+
assert.equal(hostedCommunityQuotaUsed(49), 49);
108+
assert.equal(hostedCommunityQuotaUsed(1.5), null);
109+
assert.equal(hostedCommunityQuotaUsed(Number.MAX_SAFE_INTEGER + 1), null);
110+
});
111+
102112
test("quota projection never invents a fixed client limit", () => {
103113
assert.equal(hostedCommunityQuotaLimit(undefined), null);
104114
assert.equal(hostedCommunityQuotaLimit(0), null);

‎desktop/src/features/communities/hostedCommunityApi.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ export function hostedCommunityQuotaLimit(
7474
: null;
7575
}
7676

77+
export function hostedCommunityQuotaUsed(
78+
value: number | undefined,
79+
): number | null {
80+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0
81+
? value
82+
: null;
83+
}
84+
7785
export function hostedCommunityErrorMessage(
7886
error: HostedCommunityApiError | undefined,
7987
correlationId: string | undefined,

‎desktop/src/features/settings/ui/HostedCommunitiesSettingsCard.tsx‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
HOSTED_COMMUNITY_SUFFIX as HOST_SUFFIX,
1919
hostedCommunityErrorMessage as errorMessage,
2020
hostedCommunityQuotaLimit,
21+
hostedCommunityQuotaUsed,
2122
hostedCommunityRelayUrl as relayUrl,
2223
normalizedBoundKeyHex,
2324
usableBoundIdentityNpub,
@@ -116,13 +117,7 @@ export function HostedCommunitiesSettingsCard() {
116117
}
117118
setIdentity(identityResponse.identity ?? null);
118119
setCommunities(communitiesResponse.communities ?? []);
119-
setQuotaUsed(
120-
typeof communitiesResponse.quota_used === "number" &&
121-
Number.isSafeInteger(communitiesResponse.quota_used) &&
122-
communitiesResponse.quota_used >= 0
123-
? communitiesResponse.quota_used
124-
: null,
125-
);
120+
setQuotaUsed(hostedCommunityQuotaUsed(communitiesResponse.quota_used));
126121
setQuotaLimit(hostedCommunityQuotaLimit(communitiesResponse.quota_limit));
127122
setCanCreate(communitiesResponse.can_create !== false);
128123
}, []);

0 commit comments

Comments
 (0)