Skip to content

Commit

Permalink
added onMintPaid test
Browse files Browse the repository at this point in the history
  • Loading branch information
Egge21M committed Jul 17, 2024
1 parent 39f8453 commit 83f322f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/WSConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@ describe('testing WSConnection', () => {
);
});
expect(payload).toMatchObject({ quote: '123', request: '456', paid: true, expiry: 123 });
server.stop();
});
});
39 changes: 39 additions & 0 deletions test/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { MeltQuoteResponse, ReceiveResponse } from '../src/model/types/index.js'
import { getDecodedToken } from '../src/utils.js';
import { AmountPreference } from '../src/model/types/index';
import { Proof } from '@cashu/crypto/modules/common';
import { injectWebSocketImpl } from '../src/WSConnection.js';
import { Server, WebSocket } from 'mock-socket';

injectWebSocketImpl(WebSocket);

const dummyKeysResp = {
keysets: [
Expand Down Expand Up @@ -619,3 +623,38 @@ describe('deterministic', () => {
);
});
});

describe('WebSocket Updates', () => {
test('mint update', async () => {
const fakeUrl = 'ws://localhost:3338/v1/ws';
const server = new Server(fakeUrl, { mock: false });
server.on('connection', (socket) => {
socket.on('message', (m) => {
console.log(m);
try {
const parsed = JSON.parse(m.toString());
if (parsed.method === 'subscribe') {
const message = `{"jsonrpc": "2.0", "result": {"status": "OK", "subId": "${parsed.params.subId}"}, "id": ${parsed.id}}`;
socket.send(message);
setTimeout(() => {
const message = `{"jsonrpc": "2.0", "method": "subscribe", "params": {"subId": "${parsed.params.subId}", "payload": {"quote": "123", "request": "456", "paid": true, "expiry": 123}}}`;
socket.send(message);
}, 500);
}
} catch {
console.log('Server parsing failed...');
}
});
});
const wallet = new CashuWallet(mint);
await new Promise((res) => {
const callback = (p: any) => {
console.log(p);
res(p);
};
const test = wallet.onQuotePaid('123', callback, () => {
console.log('error');
});
});
});
});

0 comments on commit 83f322f

Please sign in to comment.