summaryrefslogtreecommitdiff
path: root/web/test/protocol.test.ts
blob: e12df4e6a2654cbb96f773fb365eb6cfb171db56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { describe, expect, it } from 'vitest';
import {
	claimMessage,
	commandMessage,
	helloMessage,
	pingMessage
} from '$lib/protocol/types';

describe('wire protocol builders', () => {
	it('builds the hello handshake message', () => {
		expect(helloMessage()).toEqual({ t: 'hello', v: 1 });
	});

	it('builds a command message with default empty args', () => {
		expect(commandMessage('draw')).toEqual({
			t: 'cmd',
			name: 'draw',
			args: {}
		});
	});

	it('builds a command message with args', () => {
		expect(
			commandMessage('addCharacter', { id: 'Berserker', edition: 'x' })
		).toEqual({
			t: 'cmd',
			name: 'addCharacter',
			args: { id: 'Berserker', edition: 'x' }
		});
	});

	it('builds claim, ping messages', () => {
		expect(claimMessage('Berserker')).toEqual({
			t: 'claim',
			characterId: 'Berserker'
		});
		expect(pingMessage()).toEqual({ t: 'ping' });
	});
});