Skip to content

Commit

Permalink
refactor(tests): add GameMessagePayload copy test
Browse files Browse the repository at this point in the history
  • Loading branch information
drazisil committed Oct 11, 2024
1 parent 2b04e31 commit 12e9715
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/shared-packets/test/GameMessagePayload.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { describe, it, expect } from "vitest";
import { GameMessagePayload } from "../src/GameMessagePayload.js";

describe("GameMessagePayload", () => {
it("should create a copy of the payload", () => {
const originalPayload = new GameMessagePayload();
originalPayload.deserialize(Buffer.from("test data"));

const copiedPayload = GameMessagePayload.copy(originalPayload);

expect(copiedPayload).not.toBe(originalPayload);
expect(copiedPayload.serialize()).toEqual(originalPayload.serialize());
});

it("should return the correct byte size", () => {
const payload = new GameMessagePayload();
payload.deserialize(Buffer.from("test data"));

expect(payload.getByteSize()).toBe(9);
});

it("should serialize the payload correctly", () => {
const payload = new GameMessagePayload();
const buffer = Buffer.from("test data");
payload.deserialize(buffer);

expect(payload.serialize()).toEqual(buffer);
});

it("should deserialize the payload correctly", () => {
const payload = new GameMessagePayload();
const buffer = Buffer.from("test data");
payload.deserialize(buffer);

expect(payload.serialize()).toEqual(buffer);
});

it("should correctly indicate if the payload is encrypted", () => {
const payload = new GameMessagePayload();

expect(payload.isPayloadEncrypted()).toBe(false);

payload.setPayloadEncryption(true);
expect(payload.isPayloadEncrypted()).toBe(true);
});

it("should set the payload encryption correctly", () => {
const payload = new GameMessagePayload();

payload.setPayloadEncryption(true);
expect(payload.isPayloadEncrypted()).toBe(true);

payload.setPayloadEncryption(false);
expect(payload.isPayloadEncrypted()).toBe(false);
});
});

0 comments on commit 12e9715

Please sign in to comment.