Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .github/workflows/contract-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: Contract CI

on:
push:
branches: [ main, develop ]
branches: [main, develop]
paths:
- 'apps/onchain/**'
- '.github/workflows/contract-ci.yml'
- "apps/onchain/**"
- ".github/workflows/contract-ci.yml"
pull_request:
branches: [ main, develop ]
branches: [main, develop]
paths:
- 'apps/onchain/**'
- '.github/workflows/contract-ci.yml'
- "apps/onchain/**"
- ".github/workflows/contract-ci.yml"

jobs:
test:
Expand All @@ -28,8 +28,12 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt, clippy
targets: wasm32-unknown-unknown

- name: Add wasm target
run: rustup target add wasm32-unknown-unknown

- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { AllowedAsset } from './modules/assets/entities/allowed-asset.entity';
import { IpfsModule } from './modules/ipfs/ipfs.module';
import { HealthModule } from './modules/health/health.module';
import { AppVersionModule } from './app-version/app-version.module';
import { EventsModule } from './gateways/events.module';
import stellarConfig from './config/stellar.config';
import ipfsConfig from './config/ipfs.config';

Expand Down Expand Up @@ -79,6 +80,7 @@ import ipfsConfig from './config/ipfs.config';
AuthModule,
UserModule,
EscrowModule,
EventsModule,
StellarModule,
forwardRef(() => AdminModule),
WebhookModule,
Expand Down
54 changes: 54 additions & 0 deletions apps/backend/src/gateways/escrow.gateway.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { EventsGateway } from './escrow.gateway';

describe('EventsGateway', () => {
let gateway: EventsGateway;
let jwtService: { verify: jest.Mock };

beforeEach(() => {
jwtService = {
verify: jest.fn().mockReturnValue({ sub: 'user-1' }),
};
gateway = new EventsGateway(jwtService as any);
});

it('authenticates a socket and emits a connected event', async () => {
const client = {
id: 'socket-1',
handshake: { auth: { token: 'valid-token' }, headers: {} },
emit: jest.fn(),
disconnect: jest.fn(),
join: jest.fn(),
leave: jest.fn(),
};

await gateway.handleConnection(client as any);

expect(jwtService.verify).toHaveBeenCalledWith('valid-token');
expect(client.emit).toHaveBeenCalledWith(
'connected',
expect.objectContaining({ userId: 'user-1', socketId: 'socket-1' }),
);
});

it('broadcasts escrow and notification events to the correct rooms', () => {
const emit = jest.fn();
gateway.server = {
to: jest.fn().mockReturnValue({ emit }),
} as any;

gateway['userSocketMap'].set('user-1', new Set(['socket-1']));

gateway.broadcastEscrowStatusChanged('esc-1', { status: 'active' });
gateway.broadcastNotification('user-1', { message: 'new message' });

expect(gateway.server.to).toHaveBeenCalledWith('escrow:esc-1');
expect(emit).toHaveBeenCalledWith(
'escrow.status_changed',
expect.objectContaining({ escrowId: 'esc-1' }),
);
expect(emit).toHaveBeenCalledWith(
'notification.new',
expect.objectContaining({ message: 'new message' }),
);
});
});
Loading