mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-04 11:52:25 +00:00
test(HashtagPreferences): mock signer in beforeEach to fix auto-save errors (agent)
- Update `tests/hashtag-preferences.test.mjs` to set a default mock signer in `beforeEach`. - Mock `nostrClient.pool.publish` and `nostrClient.writeRelays` to support auto-save operations during tests. - Revert inline mocks in individual tests to rely on the suite-wide setup. - Ensure all tests have a valid active pubkey loaded to pass publish validation. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
acb794abc1
commit
5a640dd3d8
1 file changed
+27
-2
@@ -34,11 +34,36 @@ function restoreNostrClient() {
|
||||
: originalWriteRelays;
|
||||
}
|
||||
|
||||
test.beforeEach(() => {
|
||||
test.beforeEach(async () => {
|
||||
hashtagPreferences.reset();
|
||||
restoreNostrClient();
|
||||
window.nostr = originalWindowNostr;
|
||||
clearActiveSigner();
|
||||
|
||||
// Setup default mock signer to prevent auto-save errors
|
||||
setActiveSigner({
|
||||
signEvent: async (e) => ({ ...e, id: "fake" }),
|
||||
nip44Encrypt: async () => "encrypted",
|
||||
nip04Encrypt: async () => "encrypted",
|
||||
});
|
||||
|
||||
// Setup default pool mock for publish and list
|
||||
nostrClient.pool = {
|
||||
list: async () => [],
|
||||
publish: (urls, event) => ({
|
||||
on: (eventName, handler) => {
|
||||
if (eventName === "ok") {
|
||||
setTimeout(() => handler(), 0);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
// Ensure writeRelays are set
|
||||
nostrClient.writeRelays = ["wss://mock.relay"];
|
||||
|
||||
// Ensure active pubkey is set for publish operations
|
||||
await hashtagPreferences.load("0".repeat(64));
|
||||
});
|
||||
|
||||
test.after(() => {
|
||||
|
||||
Reference in new issue
Block a user