<repo_name>featr/socketIO-chat-app<file_sep>/server/utils/validation.test.js
const expect = require('expect');
const { isRealString } = require('./validation');

describe('isRealString', () => {
	it('should reject non-string values', () => {
		const res = isRealString(1234);
		expect(res).toBeFalsy();
	});
	it('should reject string with only spaces', () => {
		const res = isRealString('    ');
		expect(res).toBeFalsy();
	});
	it('should allow string with non space values', () => {
		const res = isRealString('Artifact   ');
		expect(res).toBeTruthy();
	});
});
<file_sep>/server/utils/message.test.js
const expect = require('expect');
const { generateMessage, generateLocationMessage } = require('./message');

describe('generateMessage', () => {
	it('should generate the correct message object', () => {
		const res = generateMessage('Admin', 'About...');
		expect(res.from).toBe('Admin');
		expect(res.text).toBe('About...');
		expect(res.createdAt).toEqual(expect.any(Number));
	});
});

describe('generateLocationMessage', () => {
	it('should generate correct location object', () => {
		const res = generateLocationMessage('Admin', '1324', '1324');
		expect(res.from).toBe('Admin');
		expect(res.url).toBe('https://www.google.com/maps?q=1324,1324');
		expect(res.createdAt).toEqual(expect.any(Number));
	});
});
<file_sep>/server/utils/users.test.js
const expect = require('expect');

const { Users } = require('./users');

describe('Users', () => {
	let users;
	beforeEach(() => {
		users = new Users();
		users.users = [
			{ id: '1', name: 'jen', room: 'office' },
			{ id: '2', name: 'mike', room: 'office' },
			{ id: '3', name: 'john', room: 'react' },
		];
	});

	it('should add new user', () => {
		const users = new Users();
		const user = {
			id: 'xczc',
			name: 'ev',
			room: 'office',
		};
		const resUser = users.addUser(user.id, user.name, user.room);
		expect(users.users).toEqual([user]);
	});

	it('should remove a user', () => {
		const resUser = users.removeUser('1');
		expect(resUser.id).toBe('1');
		expect(users.users.length).toBe(2);
	});

	it('should not remove user', () => {
		const resUser = users.removeUser('4');
		expect(users.users.length).toBe(3);
	});

	it('should find user', () => {
		const resUser = users.getUser('1');
		expect(resUser).toEqual(users.users[0]);
	});

	it('should not find user', () => {
		const resUser = users.getUser('6');
		expect(resUser).toBeFalsy();
	});

	it('should return names for office room', () => {
		const userList = users.getUserList('office');
		expect(userList).toEqual(['jen', 'mike']);
	});

	it('should return names for react room', () => {
		const userList = users.getUserList('react');
		expect(userList).toEqual(['john']);
	});

	it('should return active rooms', () => {
		const rooms = users.getActiveRooms();
		expect(rooms).toEqual(['office', 'react']);
	});
});
<file_sep>/public/scripts/index.js
const socket = io();

const activeRooms = document.getElementById('activeRooms');

socket.on('getActiveRooms', rooms => {
	const defaultOption = document.createElement('option');
	defaultOption.text = 'See active rooms';
	activeRooms.innerHTML = '';
	console.log(rooms);
	if (rooms) {
		activeRooms.add(defaultOption);
		rooms.forEach(room => {
			let option = document.createElement('option');
			option.text = room;
			// option.disabled = 'disabled';
			activeRooms.add(option);
		});
	}
});

activeRooms.onchange = function(e) {
	if (activeRooms.options[activeRooms.selectedIndex.value] !== activeRooms[0]) {
		console.log('yea');
		document.getElementById('room-name').value =
			activeRooms.options[activeRooms.selectedIndex].value;
	}
};
