Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc committed Nov 29, 2023
1 parent 791059e commit c6f46be
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/rooms/gateways/rooms.gateway.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Test, TestingModule } from '@nestjs/testing';
import { RoomsGateway } from './rooms.gateway';
import { Socket } from 'socket.io';

describe('RoomsGateway', () => {
let gateway: RoomsGateway;
let socket: jest.Mocked<Socket>;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand All @@ -12,7 +14,33 @@ describe('RoomsGateway', () => {
gateway = module.get<RoomsGateway>(RoomsGateway);
});

beforeEach(() => {
socket = {
rooms: new Set(),
join: jest.fn().mockImplementation((room) => socket.rooms.add(room)),
leave: jest.fn().mockImplementation((room) => socket.rooms.delete(room)),
} as unknown as jest.Mocked<Socket>;
});

it('should be defined', () => {
expect(gateway).toBeDefined();
});

describe('#join()', () => {
it('should join', () => {
const ret = gateway.join(socket, 'FAKE_ROOM');
expect(ret).toEqual(['FAKE_ROOM']);
});
});

describe('#leave()', () => {
beforeEach(() => {
socket.rooms.add('FAKE_ROOM');
});

it('should leave', () => {
const ret = gateway.leave(socket, 'FAKE_ROOM');
expect(ret).toEqual([]);
});
});
});

0 comments on commit c6f46be

Please sign in to comment.