summaryrefslogtreecommitdiff
path: root/web/test/protocol.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/test/protocol.test.ts')
-rw-r--r--web/test/protocol.test.ts37
1 files changed, 34 insertions, 3 deletions
diff --git a/web/test/protocol.test.ts b/web/test/protocol.test.ts
index c804d8b..e12df4e 100644
--- a/web/test/protocol.test.ts
+++ b/web/test/protocol.test.ts
@@ -1,8 +1,39 @@
import { describe, expect, it } from 'vitest';
-import { buildHello } from '$lib/protocol/connection';
+import {
+ claimMessage,
+ commandMessage,
+ helloMessage,
+ pingMessage
+} from '$lib/protocol/types';
-describe('wire protocol', () => {
+describe('wire protocol builders', () => {
it('builds the hello handshake message', () => {
- expect(buildHello()).toEqual({ t: 'hello', v: 1 });
+ 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' });
});
});